Added splosion visualization
This commit is contained in:
parent
14297191ed
commit
bb072255cd
30
spectator.go
30
spectator.go
@ -2,6 +2,7 @@ package client
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math"
|
||||
|
||||
"github.com/nsf/termbox-go"
|
||||
|
||||
@ -130,14 +131,27 @@ func (s *SimpleSpectator) Run() {
|
||||
}
|
||||
|
||||
for _, splosion := range u.Splosions {
|
||||
x := int((splosion.Position.X / s.width) * float64(s.viewX))
|
||||
y := int((splosion.Position.Y / s.height) * float64(s.viewY))
|
||||
termbox.SetCell(
|
||||
x,
|
||||
s.viewY-y,
|
||||
'O',
|
||||
termbox.ColorRed|termbox.AttrBold, termbox.ColorBlack,
|
||||
)
|
||||
startX := int(((splosion.Position.X - float64(splosion.Radius)) / s.width) * float64(s.viewX))
|
||||
startY := int(((splosion.Position.Y - float64(splosion.Radius)) / s.height) * float64(s.viewY))
|
||||
stopX := int(((splosion.Position.X+float64(splosion.Radius))/s.width)*float64(s.viewX)) + 1
|
||||
stopY := int(((splosion.Position.Y+float64(splosion.Radius))/s.height)*float64(s.viewY)) + 1
|
||||
for x := startX; x < stopX; x++ {
|
||||
for y := startY; y < stopY; y++ {
|
||||
realX := float64(x) * s.width / float64(s.viewX)
|
||||
realY := float64(y) * s.height / float64(s.viewY)
|
||||
dX := realX - splosion.Position.X
|
||||
dY := realY - splosion.Position.Y
|
||||
curRad := math.Sqrt(dX*dX + dY*dY)
|
||||
if curRad < float64(splosion.Radius) {
|
||||
termbox.SetCell(
|
||||
x,
|
||||
s.viewY-y,
|
||||
'·',
|
||||
termbox.ColorYellow|termbox.AttrBold, termbox.ColorRed,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err := termbox.Flush()
|
||||
|
Loading…
Reference in New Issue
Block a user