objects have HP now, only direct hits hurt them
This commit is contained in:
parent
ae9d09596c
commit
4c4c0d4e67
@ -8,6 +8,7 @@ import (
|
||||
|
||||
type Obstacle struct {
|
||||
Bounds v.Rect2d `json:"bounds"`
|
||||
Hp int `json:"-"`
|
||||
}
|
||||
|
||||
func (o Obstacle) distance_from_point(p v.Point2d) float32 {
|
||||
@ -48,6 +49,7 @@ func GenerateObstacles(count int, width, height float32) []Obstacle {
|
||||
A: v.Point2d{X: x, Y: y},
|
||||
B: v.Point2d{X: 20 + x + w, Y: 20 + y + h},
|
||||
},
|
||||
Hp: 10000,
|
||||
})
|
||||
}
|
||||
return out
|
||||
|
@ -51,11 +51,15 @@ func (p *Projectile) Tick(g *game) {
|
||||
arrived, _, pos := v.RectIntersection(r_dest, p.Position, travel)
|
||||
|
||||
if !arrived {
|
||||
for _, obj := range g.obstacles {
|
||||
for i, obj := range g.obstacles {
|
||||
collision, _, pos := v.RectIntersection(obj.Bounds, p.Position, travel)
|
||||
if collision {
|
||||
arrived = true
|
||||
p.Position = pos
|
||||
obj.Hp -= p.Damage
|
||||
if obj.Hp < 0 {
|
||||
delete(g.obstacles, i)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user