changes to collision response and player to player collision
This commit is contained in:
parent
34b8ec045f
commit
f6c8399699
38
robot.go
38
robot.go
@ -167,9 +167,11 @@ type Instruction struct {
|
|||||||
func (r *Robot) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point2d, *Robot) {
|
func (r *Robot) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point2d, *Robot) {
|
||||||
collision := false
|
collision := false
|
||||||
intersection_point := v.Point2d{X: 0, Y: 0}
|
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
|
// 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)
|
collision, _, pos := v.RectIntersection(r_walls, r.Position, move_vector)
|
||||||
if collision {
|
if collision {
|
||||||
return collision, pos, nil
|
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 {
|
if bot.Id == r.Id {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
player_rect := v.RectFromPoint(bot.Position, 5)
|
player_rect := v.OrientedSquare(bot.Position, bot.Heading, bot_size)
|
||||||
collision, _, pos := v.RectIntersection(player_rect, r.Position, move_vector)
|
collision, move_collision, translation := v.PolyPolyIntersection(
|
||||||
if collision {
|
bot_polygon, move_vector, player_rect)
|
||||||
return collision, pos, bot
|
if collision || move_collision {
|
||||||
|
return true, r.Position.Add(move_vector).Add(translation.Scale(1.2)), bot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Obstacles
|
// Check Obstacles
|
||||||
for _, obj := range g.obstacles {
|
for _, obj := range g.obstacles {
|
||||||
bot_polygon := v.OrientedSquare(r.Position, r.Heading, 5)
|
collision, move_collision, translation := v.PolyPolyIntersection(
|
||||||
collision, move_collition, translation := v.PolyPolyIntersection(
|
|
||||||
bot_polygon, move_vector, obj.Bounds.ToPolygon())
|
bot_polygon, move_vector, obj.Bounds.ToPolygon())
|
||||||
|
|
||||||
if collision || move_collition {
|
if collision || move_collision {
|
||||||
log.Printf(" COLLISION: %v %v %v\n", collision, move_collition, translation)
|
// log.Printf(" COLLISION: %v %v %v\n", collision, move_collition, translation)
|
||||||
log.Printf(" DETAILS: %v %v\n", r.Position, move_vector)
|
// log.Printf(" DETAILS: %v %v\n", r.Position, move_vector)
|
||||||
log.Printf(" INPUT: %v %v %v\n", bot_polygon, obj.Bounds.ToPolygon(), obj.Bounds)
|
// 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
|
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 {
|
if r.Speed > r.TargetSpeed {
|
||||||
r.Speed = r.TargetSpeed
|
r.Speed = r.TargetSpeed
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if float32(math.Abs(float64(r.Speed-r.TargetSpeed))) > v.Epsilon {
|
} else if float32(math.Abs(float64(r.Speed-r.TargetSpeed))) > v.Epsilon {
|
||||||
r.Speed -= (r.Stats.Acceleration * delta)
|
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 {
|
} else {
|
||||||
r.Speed = r.TargetSpeed
|
r.Speed = r.TargetSpeed
|
||||||
}
|
}
|
||||||
@ -267,19 +272,18 @@ func (r *Robot) Tick(g *game) {
|
|||||||
if hit_robot != nil {
|
if hit_robot != nil {
|
||||||
hit_robot.Health -= int(r.Speed / 10.0)
|
hit_robot.Health -= int(r.Speed / 10.0)
|
||||||
hit_robot.Speed = (hit_robot.Speed * 0.1)
|
hit_robot.Speed = (hit_robot.Speed * 0.1)
|
||||||
hit_robot.Heading = r.Heading
|
// hit_robot.Heading = r.Heading
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Position != intersection_point {
|
if r.Position != intersection_point {
|
||||||
move_by := intersection_point.Sub(r.Position)
|
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.Position = r.Position.Add(move_by)
|
||||||
}
|
}
|
||||||
|
|
||||||
r.Health -= int(r.Speed / 10.0)
|
r.Health -= int(r.Speed / 10.0)
|
||||||
r.MoveTo = &r.Position
|
r.MoveTo = &r.Position
|
||||||
r.Speed = (r.Speed * 0.1)
|
r.Speed = (r.Speed * -0.5)
|
||||||
r.Heading = r.Heading.Scale(-1.0)
|
// r.Heading = r.Heading.Scale(-1.0)
|
||||||
} else {
|
} else {
|
||||||
r.Position = r.Position.Add(move_vector)
|
r.Position = r.Position.Add(move_vector)
|
||||||
if new_heading.Mag() > 0 {
|
if new_heading.Mag() > 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user