throw batons with animation

This commit is contained in:
Luke Meyers 2020-02-07 16:24:23 -08:00
parent 73bceedf56
commit 9c5fc0b08f
4 changed files with 18 additions and 13 deletions

View File

@ -13,7 +13,7 @@ func doCommand(cmd command, s State, teamID int) State {
da := 1
//da += rand.Intn(3) - 1
b := activeBot(s.Teams[teamID])
b := ActiveBot(s.Teams[teamID])
if b == nil {
return s
}

View File

@ -5,14 +5,14 @@ import "log"
func UpdateState(s State, sOld State) State {
for i := range s.Teams {
s = doCommand(chooseCommand(s, i), s, i)
if b := activeBot(s.Teams[i]); b != nil {
if b := ActiveBot(s.Teams[i]); b != nil {
s = moveBot(s, i, *b)
}
s = maybePassBaton(s, i)
}
for _, t := range s.Teams {
if b := activeBot(t); b != nil && won(*b, s) {
if b := ActiveBot(t); b != nil && won(*b, s) {
log.Printf("team %d won", t.id)
s.GameOver = true
}
@ -23,7 +23,7 @@ func UpdateState(s State, sOld State) State {
func maybePassBaton(s State, teamID int) State {
t := s.Teams[teamID]
h := activeBot(t)
h := ActiveBot(t)
if h == nil {
return s
}
@ -47,7 +47,7 @@ func maybePassBaton(s State, teamID int) State {
return s
}
func activeBot(t Team) *Bot {
func ActiveBot(t Team) *Bot {
for _, b := range t.Bots {
if b.ID == t.Baton.HolderID {
return &b

View File

@ -52,6 +52,6 @@ func collide(pos, lane int, s State) interface{} {
}
const (
passDistance = 1
passDistance = 3
baseAccel = 1
)

View File

@ -17,7 +17,7 @@ type RenderState struct {
}
func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window) RenderState {
w.Clear(colornames.Peru)
w.Clear(colornames.Olivedrab)
tween := float64(rs.Frame) / float64(rs.Frames)
@ -51,15 +51,20 @@ func renderBots(sOld, sNew game.State, tween float64, w *pixelgl.Window, colors
}
im.Push(pos)
im.Clear()
im.Circle(botWidth, 0)
im.Draw(w)
if t.Bots[j].ID == t.Baton.HolderID {
renderBaton(pos, w)
}
}
oldHolder, newHolder := game.ActiveBot(sOld.Teams[i]), game.ActiveBot(sNew.Teams[i])
oldPos := lanePos(oldHolder.Pos, oldHolder.Lane, botWidth, bounds)
newPos := lanePos(newHolder.Pos, newHolder.Lane, botWidth, bounds)
pos := pixel.Vec{
X: oldPos.X + tween*(newPos.X-oldPos.X),
Y: oldPos.Y + tween*(newPos.Y-oldPos.Y),
}
renderBaton(pos, w)
}
}
@ -110,7 +115,7 @@ func teamColors(ts []game.Team) map[*game.Team]pixel.RGBA {
case 2:
c = colornames.Lavender
case 3:
c = colornames.Maroon
c = colornames.Rosybrown
}
m[&ts[i]] = pixel.ToRGBA(c)
}