From 1220b0db23376cb71fbb92a27533089ee698aa63 Mon Sep 17 00:00:00 2001 From: Luke Meyers Date: Wed, 5 Feb 2020 20:41:23 -0800 Subject: [PATCH] refactor, add second obstacle --- game/game.go | 5 +++++ game/physics.go | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/game/game.go b/game/game.go index f7ca2ff..5f2753b 100644 --- a/game/game.go +++ b/game/game.go @@ -35,6 +35,10 @@ func NewState() State { Lane: 0, Pos: Steps / 3, }, + { + Lane: 1, + Pos: Steps * 2 / 3, + }, }, } } @@ -66,6 +70,7 @@ func UpdateState(sOld State) State { s := sOld for i, t := range s.Teams { + accelerate(t.Baton.Holder) moveBot(t.Baton.Holder, sOld) maybePassBaton(&s.Teams[i]) } diff --git a/game/physics.go b/game/physics.go index 80aaa09..b2480a6 100644 --- a/game/physics.go +++ b/game/physics.go @@ -2,7 +2,7 @@ package game import "math/rand" -func moveBot(b *Bot, s State) { +func accelerate(b *Bot) { if b.a == 0 { b.a = 1 } @@ -21,7 +21,9 @@ func moveBot(b *Bot, s State) { if b.v < -maxV { b.v = -maxV } +} +func moveBot(b *Bot, s State) { for i := 0; i < b.v; i++ { if !collide(b.id, b.Pos+1, b.Lane, s) { b.Pos++