Fixing the robot through building bug

This commit is contained in:
Fraser Graham 2014-04-26 13:26:16 -06:00
parent 6da0bfac7a
commit ab3586e5aa
2 changed files with 13 additions and 13 deletions

View File

@ -30,7 +30,7 @@ const (
TIMESCALE = 1.0 // this tweaks the temporal duration of a TICK TIMESCALE = 1.0 // this tweaks the temporal duration of a TICK
WIDTH = 800 WIDTH = 800
HEIGHT = 550 HEIGHT = 550
OBSTACLES = 5 OBSTACLES = 10
MAX_POINTS = 500 // allowing for 50 pts in every category MAX_POINTS = 500 // allowing for 50 pts in every category
DEFAULT_MODE = "deathmatch" DEFAULT_MODE = "deathmatch"
) )

View File

@ -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 // Check Other Bots
for player := range g.players { for player := range g.players {
for _, bot := range player.Robots { 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 // Check Obstacles
for _, obj := range g.obstacles { for _, obj := range g.obstacles {
// collision due to motion: // 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()) botPolygon, probe, obj.Bounds.ToPolygon())
if collision || move_collision { if collision || move_collision {
finalCollision = collision finalCollision = collision || move_collision
p := r.Position.Add(probe).Add(translation.Scale(1.1)) p := r.Position.Add(probe).Add(translation)
if dist := r.Position.Sub(p).Mag(); dist < closest { if dist := r.Position.Sub(p).Mag(); dist < closest {
intersection = &p intersection = &p
closest = dist 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 return finalCollision, intersection, finalRobot