diff --git a/obstacle.go b/obstacle.go index 88b8c29..287fc23 100644 --- a/obstacle.go +++ b/obstacle.go @@ -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 diff --git a/projectile.go b/projectile.go index 1f65cb6..bda363f 100644 --- a/projectile.go +++ b/projectile.go @@ -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 {