collision work
This commit is contained in:
parent
200afffa7f
commit
c910902d38
28
player.go
28
player.go
@ -59,7 +59,7 @@ func (p *player) recv() {
|
||||
p.ws.Close()
|
||||
}
|
||||
|
||||
func (p *player) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point2d) {
|
||||
func (p *player) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point2d, *player) {
|
||||
collision := false
|
||||
intersection_point := v.Point2d{X: 0, Y: 0}
|
||||
|
||||
@ -67,15 +67,24 @@ func (p *player) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point
|
||||
r_walls := v.Rect2d{A: v.Point2d{X: 0, Y: 0}, B: v.Point2d{X: g.width, Y: g.height}}
|
||||
collision, _, pos := v.RectIntersection(r_walls, p.Robot.Position, move_vector)
|
||||
if collision {
|
||||
return collision, pos
|
||||
return collision, pos, nil
|
||||
}
|
||||
|
||||
// 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
|
||||
// }
|
||||
// }
|
||||
|
||||
// Check Terrain
|
||||
// TBD
|
||||
|
||||
return collision, intersection_point
|
||||
return collision, intersection_point, nil
|
||||
}
|
||||
|
||||
func (p *player) Tick(g *game) {
|
||||
@ -119,13 +128,18 @@ func (p *player) Tick(g *game) {
|
||||
}
|
||||
|
||||
move_vector := new_heading.Scale(p.Robot.Speed * delta)
|
||||
collision, _ := p.checkCollisions(g, move_vector)
|
||||
collision, _, hit_player := p.checkCollisions(g, move_vector)
|
||||
if collision {
|
||||
// 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}
|
||||
}
|
||||
} else {
|
||||
p.Robot.Position = p.Robot.Position.Add(move_vector)
|
||||
if new_heading.Mag() > 0 {
|
||||
|
@ -31,9 +31,7 @@ func (p *Projectile) Tick(g *game) {
|
||||
}
|
||||
|
||||
// Are we going to intersect the destination zone in this tick?
|
||||
r_dest := v.Rect2d{
|
||||
A: v.Point2d{X: p.MoveTo.X - 3, Y: p.MoveTo.Y - 3},
|
||||
B: v.Point2d{X: p.MoveTo.X + 3, Y: p.MoveTo.Y + 3}}
|
||||
r_dest := v.RectFromPoint(p.MoveTo, 3.0)
|
||||
|
||||
travel := newPos.Sub(p.Position)
|
||||
arrived, _, _ := v.RectIntersection(r_dest, p.Position, travel)
|
||||
|
Loading…
Reference in New Issue
Block a user