start using new poly intersection against buildings
This commit is contained in:
parent
b702afeb3a
commit
34b8ec045f
21
robot.go
21
robot.go
@ -191,9 +191,15 @@ func (r *Robot) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point2
|
||||
|
||||
// Check Obstacles
|
||||
for _, obj := range g.obstacles {
|
||||
collision, _, pos := v.RectIntersection(obj.Bounds, r.Position, move_vector)
|
||||
if collision {
|
||||
return collision, pos, nil
|
||||
bot_polygon := v.OrientedSquare(r.Position, r.Heading, 5)
|
||||
collision, move_collition, translation := v.PolyPolyIntersection(
|
||||
bot_polygon, move_vector, obj.Bounds.ToPolygon())
|
||||
|
||||
if collision || move_collition {
|
||||
log.Printf(" COLLISION: %v %v %v\n", collision, move_collition, translation)
|
||||
log.Printf(" DETAILS: %v %v\n", r.Position, move_vector)
|
||||
log.Printf(" INPUT: %v %v %v\n", bot_polygon, obj.Bounds.ToPolygon(), obj.Bounds)
|
||||
return (collision || move_collition), r.Position.Add(move_vector).Add(translation.Scale(1.2)), nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,10 +269,13 @@ func (r *Robot) Tick(g *game) {
|
||||
hit_robot.Speed = (hit_robot.Speed * 0.1)
|
||||
hit_robot.Heading = r.Heading
|
||||
}
|
||||
move_by := intersection_point.Sub(r.Position)
|
||||
move_dist := move_by.Scale(float32(math.Floor(float64(move_by.Mag()-3.0))) / move_by.Mag())
|
||||
|
||||
r.Position = r.Position.Add(move_dist)
|
||||
if r.Position != intersection_point {
|
||||
move_by := intersection_point.Sub(r.Position)
|
||||
// move_dist := move_by.Scale(float32(math.Floor(float64(move_by.Mag()-3.0))) / move_by.Mag())
|
||||
r.Position = r.Position.Add(move_by)
|
||||
}
|
||||
|
||||
r.Health -= int(r.Speed / 10.0)
|
||||
r.MoveTo = &r.Position
|
||||
r.Speed = (r.Speed * 0.1)
|
||||
|
Loading…
Reference in New Issue
Block a user