proper player collision and direct hit capability

This commit is contained in:
Fraser Graham
2013-11-06 20:47:40 -08:00
parent 545b68d1d7
commit dfb3dba4f4
3 changed files with 18 additions and 12 deletions
+16 -8
View File
@@ -2,6 +2,7 @@ package main
import (
v "bitbucket.org/hackerbots/vector"
"log"
)
type Projectile struct {
@@ -25,9 +26,18 @@ func (p *Projectile) Tick(g *game) {
if player == p.Owner {
continue
}
dist := v.Distance(player.Robot.Position, p.Position)
if dist < 5.0 {
player_rect := v.RectFromPoint(player.Robot.Position, 3)
collision, _, _ := v.RectIntersection(player_rect, p.Position, v_scaled)
if collision {
hit_player = true
if player.Robot.Health > 0 {
// Direct hit causes more damage
log.Printf("Direct Hit %v, Dmg:%v", player.Robot.Id, p.Damage)
player.Robot.Health -= p.Damage
}
}
}
@@ -54,12 +64,10 @@ func (p *Projectile) Tick(g *game) {
// Spawn a splosion
splo := &Splosion{
Id: p.Id,
Position: p.Position,
Radius: p.Radius,
MaxDamage: 10,
MinDamage: 5,
Lifespan: 8,
Id: p.Id,
Position: p.Position,
Radius: p.Radius,
Lifespan: 8,
}
g.splosions[splo] = true