proper player collision and direct hit capability
This commit is contained in:
parent
545b68d1d7
commit
dfb3dba4f4
@ -78,7 +78,7 @@ func (p *player) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point
|
|||||||
player_rect := v.RectFromPoint(player.Robot.Position, 3)
|
player_rect := v.RectFromPoint(player.Robot.Position, 3)
|
||||||
collision, _, pos := v.RectIntersection(player_rect, p.Robot.Position, move_vector)
|
collision, _, pos := v.RectIntersection(player_rect, p.Robot.Position, move_vector)
|
||||||
if collision {
|
if collision {
|
||||||
log.Printf("Player Collision %v hit %v, rect:%v", p.Robot.Position, move_vector, player_rect)
|
// log.Printf("Player Collision %v hit %v, rect:%v", p.Robot.Position, move_vector, player_rect)
|
||||||
return collision, pos, player
|
return collision, pos, player
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ func (p *player) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point
|
|||||||
for _, obj := range g.obstacles {
|
for _, obj := range g.obstacles {
|
||||||
collision, _, pos := v.RectIntersection(obj.Bounds, p.Robot.Position, move_vector)
|
collision, _, pos := v.RectIntersection(obj.Bounds, p.Robot.Position, move_vector)
|
||||||
if collision {
|
if collision {
|
||||||
log.Printf("Object Collision %v hit %v, rect:%v", p.Robot.Position, move_vector, obj.Bounds)
|
// log.Printf("Object Collision %v hit %v, rect:%v", p.Robot.Position, move_vector, obj.Bounds)
|
||||||
return collision, pos, nil
|
return collision, pos, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
v "bitbucket.org/hackerbots/vector"
|
v "bitbucket.org/hackerbots/vector"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Projectile struct {
|
type Projectile struct {
|
||||||
@ -25,9 +26,18 @@ func (p *Projectile) Tick(g *game) {
|
|||||||
if player == p.Owner {
|
if player == p.Owner {
|
||||||
continue
|
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
|
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
|
// Spawn a splosion
|
||||||
splo := &Splosion{
|
splo := &Splosion{
|
||||||
Id: p.Id,
|
Id: p.Id,
|
||||||
Position: p.Position,
|
Position: p.Position,
|
||||||
Radius: p.Radius,
|
Radius: p.Radius,
|
||||||
MaxDamage: 10,
|
Lifespan: 8,
|
||||||
MinDamage: 5,
|
|
||||||
Lifespan: 8,
|
|
||||||
}
|
}
|
||||||
g.splosions[splo] = true
|
g.splosions[splo] = true
|
||||||
|
|
||||||
|
@ -8,8 +8,6 @@ type Splosion struct {
|
|||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Position v.Point2d `json:"position"`
|
Position v.Point2d `json:"position"`
|
||||||
Radius int `json:"radius"`
|
Radius int `json:"radius"`
|
||||||
MaxDamage int `json:"-"`
|
|
||||||
MinDamage int `json:"-"`
|
|
||||||
Lifespan int `json:"-"`
|
Lifespan int `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user