fixed observers, added GameObserver

This commit is contained in:
2024-02-11 14:24:30 +01:00
parent 72f0aa7691
commit 65ddec3fa4
18 changed files with 122 additions and 53 deletions

View File

@@ -35,6 +35,12 @@ func (system *CollectibleSystem) Update() {
EntitiesToRemove := []ecs.Entity{}
query := system.Selector.Query(system.World)
numcollectibles := query.Count()
if numcollectibles == 0 {
query.Close()
return
}
for query.Next() {
colposition, collectible, _ := query.Get()
@@ -58,6 +64,14 @@ func (system *CollectibleSystem) Update() {
for _, entity := range EntitiesToRemove {
system.World.RemoveEntity(entity)
numcollectibles--
}
if numcollectibles == 0 {
// winner, winner, chicken dinner!
game := observers.GetGameObserver(system.World)
game.Score++
game.CurrentLevel++
}
}

View File

@@ -9,7 +9,6 @@ import (
. "openquell/config"
"openquell/grid"
"github.com/alecthomas/repr"
"github.com/hajimehoshi/ebiten/v2"
"github.com/mlange-42/arche/ecs"
"github.com/mlange-42/arche/generic"
@@ -119,7 +118,6 @@ func (system *GridSystem) GetSolidNeighborPosition(
}
newpos := components.NewPosition(neighborpos, system.Tilesize)
repr.Println(newpos)
if !edge && system.Grid.Map[neighborpos].Solid {
return true, newpos

View File

@@ -12,7 +12,7 @@ import (
type PlayerSystem struct {
World *ecs.World
Selector *generic.Filter4[Position, Velocity, Player, Renderable]
Selector *generic.Filter5[Position, Velocity, Player, Renderable, Speed]
Particle *ParticleSystem
Collectible *CollectibleSystem
Grid *GridSystem
@@ -20,7 +20,7 @@ type PlayerSystem struct {
func NewPlayerSystem(world *ecs.World, grid *GridSystem) *PlayerSystem {
system := &PlayerSystem{
Selector: generic.NewFilter4[Position, Velocity, Player, Renderable](),
Selector: generic.NewFilter5[Position, Velocity, Player, Renderable, Speed](),
Particle: NewParticleSystem(world, grid.Tilesize),
Collectible: NewCollectibleSystem(world),
Grid: grid,
@@ -34,7 +34,7 @@ func (system PlayerSystem) Update() error {
query := system.Selector.Query(system.World)
for query.Next() {
playerposition, velocity, _, _ := query.Get()
playerposition, velocity, _, _, speed := query.Get()
if !velocity.Moving() {
switch {
@@ -72,7 +72,7 @@ func (system PlayerSystem) Update() error {
}
}
playerposition.Move(velocity)
playerposition.Move(velocity, speed)
}
system.Particle.Update()
@@ -87,7 +87,7 @@ func (system *PlayerSystem) Draw(screen *ebiten.Image) {
query := system.Selector.Query(system.World)
for query.Next() {
pos, _, _, sprite := query.Get()
pos, _, _, sprite, _ := query.Get()
op.GeoM.Reset()
op.GeoM.Translate(float64(pos.X), float64(pos.Y))