make projectiles arrive at their destination regardless of tick time

This commit is contained in:
Fraser Graham 2013-10-18 20:39:53 -07:00
parent f4e2e84676
commit e02c5f89fb
1 changed files with 12 additions and 4 deletions

16
game.go
View File

@ -193,7 +193,14 @@ func (g *game) nudgeProjectiles() (rprojectiles []Projectile) {
}
}
if v.Distance(p.Position, p.MoveTo) < 5 || hit_player {
// 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}}
travel := newPos.Sub(p.Position)
arrived, _, _ := v.RectIntersection(r_dest, p.Position, travel)
if arrived || hit_player {
delete(g.projectiles, p)
// Spawn a splosion
@ -219,10 +226,11 @@ func (g *game) nudgeProjectiles() (rprojectiles []Projectile) {
}
}
}
} else {
p.Position.X = newPos.X
p.Position.Y = newPos.Y
rprojectiles = append(rprojectiles, *p)
}
p.Position.X = newPos.X
p.Position.Y = newPos.Y
rprojectiles = append(rprojectiles, *p)
}
return
}