bah humbug

This commit is contained in:
Fraser Graham 2014-04-26 16:10:21 -06:00
parent 39b8a9e5d7
commit ba700ba633

View File

@ -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 {