Bullet support

This commit is contained in:
2023-12-28 14:42:20 +01:00
parent b6776fa9f3
commit d336fa4d15
9 changed files with 196 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ type ObjectType int
const (
Hero ObjectType = 1 << iota
Zombie
Bullet
)
type Collidable interface {

View File

@@ -18,7 +18,10 @@ func (w *World) RemoveEntity(e Collidable) {
func (w *World) NotifyAboutCollisions() {
for i, entity := range w.Entities {
for _, other := range w.Entities[i+1:] {
for j, other := range w.Entities {
if i == j {
continue
}
if entity.CollisionShape().Overlaps(other.CollisionShape()) {
entity.HandleCollisionEvent(other)
other.HandleCollisionEvent(entity)