Files
old-9heroja/collision/world.go

36 lines
668 B
Go
Raw Normal View History

2023-11-30 21:01:49 +01:00
package collision
type World struct {
Entities []Collidable
}
func (w *World) AddEntity(e Collidable) {
w.Entities = append(w.Entities, e)
}
func (w *World) RemoveEntity(e Collidable) {
for i, entity := range w.Entities {
if entity == e {
w.Entities = append(w.Entities[:i], w.Entities[i+1:]...)
}
}
}
func (w *World) NotifyAboutCollisions() {
for i, entity := range w.Entities {
2023-12-28 14:42:20 +01:00
for j, other := range w.Entities {
if i == j {
continue
}
2023-11-30 21:01:49 +01:00
if entity.CollisionShape().Overlaps(other.CollisionShape()) {
entity.HandleCollisionEvent(other)
other.HandleCollisionEvent(entity)
}
}
}
}
func NewWorld() *World {
return &World{}
}