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 {
|
type Obstacle struct {
|
||||||
Bounds v.Rect2d `json:"bounds"`
|
Bounds v.Rect2d `json:"bounds"`
|
||||||
|
Hp int `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Obstacle) distance_from_point(p v.Point2d) float32 {
|
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},
|
A: v.Point2d{X: x, Y: y},
|
||||||
B: v.Point2d{X: 20 + x + w, Y: 20 + y + h},
|
B: v.Point2d{X: 20 + x + w, Y: 20 + y + h},
|
||||||
},
|
},
|
||||||
|
Hp: 10000,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
|
|
|
@ -51,11 +51,15 @@ func (p *Projectile) Tick(g *game) {
|
||||||
arrived, _, pos := v.RectIntersection(r_dest, p.Position, travel)
|
arrived, _, pos := v.RectIntersection(r_dest, p.Position, travel)
|
||||||
|
|
||||||
if !arrived {
|
if !arrived {
|
||||||
for _, obj := range g.obstacles {
|
for i, obj := range g.obstacles {
|
||||||
collision, _, pos := v.RectIntersection(obj.Bounds, p.Position, travel)
|
collision, _, pos := v.RectIntersection(obj.Bounds, p.Position, travel)
|
||||||
if collision {
|
if collision {
|
||||||
arrived = true
|
arrived = true
|
||||||
p.Position = pos
|
p.Position = pos
|
||||||
|
obj.Hp -= p.Damage
|
||||||
|
if obj.Hp < 0 {
|
||||||
|
delete(g.obstacles, i)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue