From ab3586e5aa7e60ad2d6fac77a4c6ea6e8018221a Mon Sep 17 00:00:00 2001 From: Fraser Graham Date: Sat, 26 Apr 2014 13:26:16 -0600 Subject: [PATCH] Fixing the robot through building bug --- config.go | 2 +- robot.go | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/config.go b/config.go index 8d91a2f..574a29b 100644 --- a/config.go +++ b/config.go @@ -30,7 +30,7 @@ const ( TIMESCALE = 1.0 // this tweaks the temporal duration of a TICK WIDTH = 800 HEIGHT = 550 - OBSTACLES = 5 + OBSTACLES = 10 MAX_POINTS = 500 // allowing for 50 pts in every category DEFAULT_MODE = "deathmatch" ) diff --git a/robot.go b/robot.go index 41fd378..a41cc8a 100644 --- a/robot.go +++ b/robot.go @@ -206,6 +206,10 @@ func (r *Robot) checkCollisions(g *Game, probe v.Vector2d) (bool, *v.Point2d, *R } } + if (finalCollision){ + return finalCollision, intersection, nil + } + // Check Other Bots for player := range g.players { for _, bot := range player.Robots { @@ -226,6 +230,12 @@ 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: @@ -233,23 +243,13 @@ func (r *Robot) checkCollisions(g *Game, probe v.Vector2d) (bool, *v.Point2d, *R botPolygon, probe, obj.Bounds.ToPolygon()) if collision || move_collision { - finalCollision = collision - p := r.Position.Add(probe).Add(translation.Scale(1.1)) + finalCollision = collision || move_collision + p := r.Position.Add(probe).Add(translation) if dist := r.Position.Sub(p).Mag(); dist < closest { intersection = &p closest = dist } } - - // collision due to probe - collision, _, wallIntersect := v.RectIntersection(obj.Bounds, r.Position, probe) - if collision && wallIntersect != nil { - finalCollision = collision - if dist := r.Position.Sub(*wallIntersect).Mag(); dist < closest { - intersection = wallIntersect - closest = dist - } - } } return finalCollision, intersection, finalRobot