From ba700ba6331c4db878f321875c9de0a98c99e506 Mon Sep 17 00:00:00 2001 From: Fraser Graham Date: Sat, 26 Apr 2014 16:10:21 -0600 Subject: [PATCH] bah humbug --- robot.go | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/robot.go b/robot.go index a41cc8a..18f9c35 100644 --- a/robot.go +++ b/robot.go @@ -199,15 +199,27 @@ func (r *Robot) checkCollisions(g *Game, probe v.Vector2d) (bool, *v.Point2d, *R r_walls := v.AABB2d{A: v.Point2d{X: botSize, Y: botSize}, B: v.Point2d{X: g.width - botSize, Y: g.height - botSize}} collision, _, wallIntersect := v.RectIntersection(r_walls, r.Position, probe) if collision && wallIntersect != nil { - finalCollision = collision + finalCollision = true if dist := r.Position.Sub(*wallIntersect).Mag(); dist < closest { intersection = wallIntersect closest = dist } } - if (finalCollision){ - return finalCollision, intersection, nil + // Check Obstacles + for _, obj := range g.obstacles { + // collision due to motion: + collision, move_collision, translation := v.PolyPolyIntersection( + botPolygon, probe, obj.Bounds.ToPolygon()) + + if collision || move_collision { + finalCollision = true + p := r.Position.Add(probe).Add(translation) + if dist := r.Position.Sub(p).Mag(); dist < closest { + intersection = &p + closest = dist + } + } } // Check Other Bots @@ -231,27 +243,6 @@ func (r *Robot) checkCollisions(g *Game, probe v.Vector2d) (bool, *v.Point2d, *R } } - if (finalCollision){ - return finalCollision, intersection, finalRobot - } - - - // Check Obstacles - for _, obj := range g.obstacles { - // collision due to motion: - collision, move_collision, translation := v.PolyPolyIntersection( - botPolygon, probe, obj.Bounds.ToPolygon()) - - if collision || move_collision { - finalCollision = collision || move_collision - p := r.Position.Add(probe).Add(translation) - if dist := r.Position.Sub(p).Mag(); dist < closest { - intersection = &p - closest = dist - } - } - } - return finalCollision, intersection, finalRobot } @@ -262,6 +253,14 @@ func (r *Robot) Tick(g *Game) { r.scan(g) // Adjust Speed + if r.TargetSpeed > r.Stats.Speed { + r.TargetSpeed = r.Stats.Speed + } + + if r.TargetSpeed < -1.0 * r.Stats.Speed { + r.TargetSpeed = -1.0 * r.Stats.Speed + } + if r.Speed < r.TargetSpeed { r.Speed += (r.Stats.Acceleration * r.Delta) if r.Speed > r.TargetSpeed {