diff --git a/game/game.go b/game/game.go index 99f791f..c94bc0b 100644 --- a/game/game.go +++ b/game/game.go @@ -1,5 +1,7 @@ package game +import "log" + func UpdateState(s State, sOld State) State { for i := range s.Teams { s = doCommand(chooseCommand(s, i), s, i) @@ -11,6 +13,7 @@ func UpdateState(s State, sOld State) State { for _, t := range s.Teams { if b := activeBot(t); b != nil && won(*b, s) { + log.Printf("team %d won", t.id) s.GameOver = true } } @@ -182,10 +185,10 @@ func NewState() State { } const ( - Steps = 50 + Steps = 60 numBots = 5 NumTeams = 4 NumLanes = 6 - maxA = 3 - maxV = 10 + maxA = 2 + maxV = 8 ) diff --git a/main.go b/main.go index b3ffdd6..5b1c53c 100644 --- a/main.go +++ b/main.go @@ -30,29 +30,34 @@ func run() { start := time.Now() w.Clear(colornames.Peachpuff) + + rs := gfx.RenderState{ + Animating: false, + Frames: 20, + } + + sOld := s + for !w.Closed() && !s.GameOver { - sOld := s - - rs := gfx.RenderState{ - Animating: false, - Frames: 20, - } - switch { case w.Pressed(pixelgl.KeyQ): return - case w.JustPressed(pixelgl.KeySpace) || true: + case rs.Animating: + rs = gfx.Render(rs, sOld, s, w, time.Since(start)) + if !rs.Animating { + sOld = s + } + default: rs.Animating = true + rs.Frame = 0 s = game.UpdateState(s, sOld) if s.GameOver { s = game.NewState() sOld = s } } - for rs.Animating { - rs = gfx.Render(rs, sOld, s, w, time.Since(start)) - w.Update() - } + + w.Update() } }