Added splosion visualization

This commit is contained in:
Stephen McQuay 2014-05-12 22:11:44 -07:00
parent 14297191ed
commit bb072255cd

View File

@ -2,6 +2,7 @@ package client
import (
"log"
"math"
"github.com/nsf/termbox-go"
@ -130,15 +131,28 @@ 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))
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,
'O',
termbox.ColorRed|termbox.AttrBold, termbox.ColorBlack,
',
termbox.ColorYellow|termbox.AttrBold, termbox.ColorRed,
)
}
}
}
}
err := termbox.Flush()
if err != nil {