changes to collision response and player to player collision

This commit is contained in:
Fraser Graham 2013-11-26 22:35:09 -08:00
parent 34b8ec045f
commit f6c8399699

View File

@ -167,9 +167,11 @@ type Instruction struct {
func (r *Robot) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point2d, *Robot) {
collision := false
intersection_point := v.Point2d{X: 0, Y: 0}
bot_size := float32(5.0)
bot_polygon := v.OrientedSquare(r.Position, r.Heading, bot_size)
// Check Walls
r_walls := v.AABB2d{A: v.Point2d{X: 0, Y: 0}, B: v.Point2d{X: g.width, Y: g.height}}
r_walls := v.AABB2d{A: v.Point2d{X: bot_size, Y: bot_size}, B: v.Point2d{X: g.width - bot_size, Y: g.height - bot_size}}
collision, _, pos := v.RectIntersection(r_walls, r.Position, move_vector)
if collision {
return collision, pos, nil
@ -181,25 +183,25 @@ func (r *Robot) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point2
if bot.Id == r.Id {
continue
}
player_rect := v.RectFromPoint(bot.Position, 5)
collision, _, pos := v.RectIntersection(player_rect, r.Position, move_vector)
if collision {
return collision, pos, bot
player_rect := v.OrientedSquare(bot.Position, bot.Heading, bot_size)
collision, move_collision, translation := v.PolyPolyIntersection(
bot_polygon, move_vector, player_rect)
if collision || move_collision {
return true, r.Position.Add(move_vector).Add(translation.Scale(1.2)), bot
}
}
}
// Check Obstacles
for _, obj := range g.obstacles {
bot_polygon := v.OrientedSquare(r.Position, r.Heading, 5)
collision, move_collition, translation := v.PolyPolyIntersection(
collision, move_collision, 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
if collision || move_collision {
// 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 true, r.Position.Add(move_vector).Add(translation.Scale(1.1)), nil
}
}
@ -217,9 +219,12 @@ func (r *Robot) Tick(g *game) {
if r.Speed > r.TargetSpeed {
r.Speed = r.TargetSpeed
}
} else if float32(math.Abs(float64(r.Speed-r.TargetSpeed))) > v.Epsilon {
r.Speed -= (r.Stats.Acceleration * delta)
// Cap reverse to 1/2 speed
if r.Speed < (-0.5 * r.TargetSpeed) {
r.Speed = (-0.5 * r.TargetSpeed)
}
} else {
r.Speed = r.TargetSpeed
}
@ -267,19 +272,18 @@ func (r *Robot) Tick(g *game) {
if hit_robot != nil {
hit_robot.Health -= int(r.Speed / 10.0)
hit_robot.Speed = (hit_robot.Speed * 0.1)
hit_robot.Heading = r.Heading
// hit_robot.Heading = r.Heading
}
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)
r.Heading = r.Heading.Scale(-1.0)
r.Speed = (r.Speed * -0.5)
// r.Heading = r.Heading.Scale(-1.0)
} else {
r.Position = r.Position.Add(move_vector)
if new_heading.Mag() > 0 {