proper player collision and direct hit capability
This commit is contained in:
+16
-8
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user