From 81e0dbe8d7fb4009df1759b9fe6da703ee490f19 Mon Sep 17 00:00:00 2001 From: Luke Meyers Date: Wed, 5 Feb 2020 20:57:46 -0800 Subject: [PATCH] simple lane changes with weird effects --- game/game.go | 7 +++++++ game/physics.go | 4 ++-- gfx/gfx.go | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/game/game.go b/game/game.go index 0018096..ec92c6d 100644 --- a/game/game.go +++ b/game/game.go @@ -73,6 +73,8 @@ func UpdateState(sOld State) State { switch chooseCommand(t, sOld) { case speedUp: accelerate(t.Baton.Holder) + case left: + t.Baton.Holder.Lane++ } moveBot(t.Baton.Holder, sOld) @@ -89,6 +91,10 @@ func UpdateState(sOld State) State { } func chooseCommand(t Team, s State) command { + h := t.Baton.Holder + if collide(h.Pos+1, h.Lane, s) { + return left + } return speedUp } @@ -96,6 +102,7 @@ type command int const ( speedUp command = iota + left ) func maybePassBaton(t *Team) { diff --git a/game/physics.go b/game/physics.go index a99aeed..868f314 100644 --- a/game/physics.go +++ b/game/physics.go @@ -25,13 +25,13 @@ func accelerate(b *Bot) { func moveBot(b *Bot, s State) { for i := 0; i < b.v; i++ { - if !collide(b.id, b.Pos+1, b.Lane, s) { + if !collide(b.Pos+1, b.Lane, s) { b.Pos++ } } } -func collide(id, pos, lane int, s State) bool { +func collide(pos, lane int, s State) bool { for _, o := range s.Obstacles { if o.Pos == pos && o.Lane == lane { return true diff --git a/gfx/gfx.go b/gfx/gfx.go index 347a724..726e384 100644 --- a/gfx/gfx.go +++ b/gfx/gfx.go @@ -29,7 +29,7 @@ func renderBots(s game.State, w *pixelgl.Window, d time.Duration, colors map[*ga im.Color = colors[&s.Teams[i]] } - pos := lanePos(bot.Pos, i, botWidth, b) + pos := lanePos(bot.Pos, bot.Lane, botWidth, b) im.Push(pos)