remove collectible if bumped into it
This commit is contained in:
parent
a86f6c816f
commit
d17594dc38
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user