bah humbug
This commit is contained in:
parent
39b8a9e5d7
commit
ba700ba633
47
robot.go
47
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}}
|
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)
|
collision, _, wallIntersect := v.RectIntersection(r_walls, r.Position, probe)
|
||||||
if collision && wallIntersect != nil {
|
if collision && wallIntersect != nil {
|
||||||
finalCollision = collision
|
finalCollision = true
|
||||||
if dist := r.Position.Sub(*wallIntersect).Mag(); dist < closest {
|
if dist := r.Position.Sub(*wallIntersect).Mag(); dist < closest {
|
||||||
intersection = wallIntersect
|
intersection = wallIntersect
|
||||||
closest = dist
|
closest = dist
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finalCollision){
|
// Check Obstacles
|
||||||
return finalCollision, intersection, nil
|
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
|
// 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
|
return finalCollision, intersection, finalRobot
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,6 +253,14 @@ func (r *Robot) Tick(g *Game) {
|
|||||||
r.scan(g)
|
r.scan(g)
|
||||||
|
|
||||||
// Adjust Speed
|
// 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 {
|
if r.Speed < r.TargetSpeed {
|
||||||
r.Speed += (r.Stats.Acceleration * r.Delta)
|
r.Speed += (r.Stats.Acceleration * r.Delta)
|
||||||
if r.Speed > r.TargetSpeed {
|
if r.Speed > r.TargetSpeed {
|
||||||
|
Loading…
Reference in New Issue
Block a user