diff --git a/player.go b/player.go index 1287902..1d79968 100644 --- a/player.go +++ b/player.go @@ -72,17 +72,17 @@ func (p *player) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point // Check Other Bots // TODO - FIX THIS - // for player := range g.players { - // if player.Robot.Id == p.Robot.Id { - // continue - // } - // player_rect := v.RectFromPoint(player.Robot.Position, 0.5) - // collision, _, pos := v.RectIntersection(player_rect, p.Robot.Position, move_vector) - // if collision { - // log.Printf("Player Collision %v hit %v, rect:%v", p.Robot.Position, move_vector, player_rect) - // return collision, pos, player - // } - // } + for player := range g.players { + if player.Robot.Id == p.Robot.Id { + continue + } + player_rect := v.RectFromPoint(player.Robot.Position, 3) + collision, _, pos := v.RectIntersection(player_rect, p.Robot.Position, move_vector) + if collision { + log.Printf("Player Collision %v hit %v, rect:%v", p.Robot.Position, move_vector, player_rect) + return collision, pos, player + } + } return collision, intersection_point, nil } @@ -130,16 +130,16 @@ func (p *player) Tick(g *game) { move_vector := new_heading.Scale(p.Robot.Speed * delta) collision, _, hit_player := p.checkCollisions(g, move_vector) if collision { + if hit_player != nil { + hit_player.Robot.Health -= int(p.Robot.Speed / 10.0) + hit_player.Robot.Speed = (hit_player.Robot.Speed * 0.5) + hit_player.Robot.Heading = p.Robot.Heading + } // p.Robot.Position = intersection_point p.Robot.Health -= int(p.Robot.Speed / 10.0) p.Robot.MoveTo = &p.Robot.Position - p.Robot.Speed = 0 - p.Robot.Heading = v.Vector2d{X: 0, Y: 0} - if hit_player != nil { - hit_player.Robot.Health -= int(p.Robot.Speed / 10.0) - hit_player.Robot.Speed = 0 - hit_player.Robot.Heading = v.Vector2d{X: 0, Y: 0} - } + p.Robot.Speed = (p.Robot.Speed * 0.5) + p.Robot.Heading = p.Robot.Heading.Scale(-1.0) } else { p.Robot.Position = p.Robot.Position.Add(move_vector) if new_heading.Mag() > 0 {