diff --git a/game/levels.go b/game/levels.go index 487330d..b205dc5 100644 --- a/game/levels.go +++ b/game/levels.go @@ -65,6 +65,8 @@ func NewLevel(game *Game, cellsize int, plan *assets.RawLevel) *Level { func (level *Level) Update() { query := level.World.Query(level.Selector["player"]) + toRemove := []ecs.Entity{} + for query.Next() { playerposition := (*components.Position)(query.Get(level.Component["position"])) velocity := (*components.Velocity)(query.Get(level.Component["velocity"])) @@ -111,12 +113,19 @@ func (level *Level) Update() { ok, _ := playerposition.Intersects(colposition, velocity) if ok { fmt.Printf("bumped into collectible %v\n", collectible) + toRemove = append(toRemove, colquery.Entity()) } } } playerposition.Move(velocity) } + + for _, entity := range toRemove { + // FIXME: or keep them and prepare an animated death + level.World.RemoveEntity(entity) + } + } func (level *Level) Position2Point(position *components.Position) image.Point {