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 ( import (
"log" "log"
"math"
"github.com/nsf/termbox-go" "github.com/nsf/termbox-go"
@ -130,14 +131,27 @@ func (s *SimpleSpectator) Run() {
} }
for _, splosion := range u.Splosions { for _, splosion := range u.Splosions {
x := int((splosion.Position.X / s.width) * float64(s.viewX)) startX := int(((splosion.Position.X - float64(splosion.Radius)) / s.width) * float64(s.viewX))
y := int((splosion.Position.Y / s.height) * float64(s.viewY)) startY := int(((splosion.Position.Y - float64(splosion.Radius)) / s.height) * float64(s.viewY))
termbox.SetCell( stopX := int(((splosion.Position.X+float64(splosion.Radius))/s.width)*float64(s.viewX)) + 1
x, stopY := int(((splosion.Position.Y+float64(splosion.Radius))/s.height)*float64(s.viewY)) + 1
s.viewY-y, for x := startX; x < stopX; x++ {
'O', for y := startY; y < stopY; y++ {
termbox.ColorRed|termbox.AttrBold, termbox.ColorBlack, 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() err := termbox.Flush()