diff --git a/game/ai.go b/game/ai.go index 6f7a045..77070f6 100644 --- a/game/ai.go +++ b/game/ai.go @@ -3,7 +3,7 @@ package game func chooseCommand(s State, teamID int) command { t := s.Teams[teamID] h := t.BatonHolder() - if collide(h.Pos+1, h.Lane, s) { + if collide(h.Pos+1, h.Lane, s) != nil { if h.Lane <= t.Lane && h.Lane < NumLanes-1 { return left } diff --git a/game/physics.go b/game/physics.go index f95a752..b775a9c 100644 --- a/game/physics.go +++ b/game/physics.go @@ -1,5 +1,7 @@ package game +import "log" + func accelerate(b Bot) Bot { if b.a < -maxA { b.a = -maxA @@ -21,7 +23,9 @@ func accelerate(b Bot) Bot { func moveBot(s State, teamID int, b Bot) State { for i := 0; i < b.v; i++ { - if !collide(b.Pos+1, b.Lane, s) { + if o := collide(b.Pos+1, b.Lane, s); o != nil { + log.Printf("bot %d crashed into %#v!", b.ID, o) + } else { b.Pos++ } } @@ -30,20 +34,20 @@ func moveBot(s State, teamID int, b Bot) State { return s } -func collide(pos, lane int, s State) bool { +func collide(pos, lane int, s State) interface{} { for _, o := range s.Obstacles { if o.Pos == pos && o.Lane == lane { - return true + return o } } for _, t := range s.Teams { for _, b := range t.Bots { if b.Pos == pos && b.Lane == lane { - return true + return b } } } - return false + return nil } const ( diff --git a/gfx/gfx.go b/gfx/gfx.go index ee60c96..c9b537a 100644 --- a/gfx/gfx.go +++ b/gfx/gfx.go @@ -3,7 +3,6 @@ package gfx import ( "image/color" "relay/game" - "time" "github.com/faiface/pixel" "github.com/faiface/pixel/imdraw" @@ -17,13 +16,13 @@ type RenderState struct { Frame int } -func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window, d time.Duration) RenderState { +func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window) RenderState { w.Clear(colornames.Peru) tween := float64(rs.Frame) / float64(rs.Frames) colors := teamColors(sNew.Teams) - renderBots(sOld, sNew, tween, w, d, colors) + renderBots(sOld, sNew, tween, w, colors) renderObstacles(sNew, w) rs.Frame++ @@ -33,7 +32,7 @@ func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window, d time.Dur return rs } -func renderBots(sOld, sNew game.State, tween float64, w *pixelgl.Window, _ time.Duration, colors map[*game.Team]pixel.RGBA) { +func renderBots(sOld, sNew game.State, tween float64, w *pixelgl.Window, colors map[*game.Team]pixel.RGBA) { bounds := w.Bounds() im := imdraw.New(nil) diff --git a/main.go b/main.go index e31f5d2..4e54c37 100644 --- a/main.go +++ b/main.go @@ -27,8 +27,6 @@ func run() { s := game.NewState() - start := time.Now() - w.Clear(colornames.Peachpuff) rs := gfx.RenderState{ @@ -42,7 +40,7 @@ func run() { case w.Pressed(pixelgl.KeyQ): return case rs.Animating: - rs = gfx.Render(rs, sOld, s, w, time.Since(start)) + rs = gfx.Render(rs, sOld, s, w) if !rs.Animating { sOld = s }