refactoring to systems complete. also added observers for collision checks

This commit is contained in:
2024-02-11 13:00:56 +01:00
parent ac643f49d3
commit 72f0aa7691
10 changed files with 187 additions and 82 deletions

View File

@@ -6,6 +6,7 @@ import (
"log"
"openquell/assets"
"openquell/components"
"openquell/observers"
"github.com/mlange-42/arche/ecs"
"github.com/mlange-42/arche/generic"
@@ -45,14 +46,11 @@ func NewGrid(world *ecs.World,
components.Renderable,
components.Collectible](world)
ptmapper := generic.NewMap2[
components.Position,
components.Particle,
](world)
var pos *components.Position
var render *components.Renderable
playerobserver := observers.GetPlayerObserver(world)
for point, tile := range mapslice {
switch tile.Renderable {
case true:
@@ -63,6 +61,8 @@ func NewGrid(world *ecs.World,
case tile.Player:
entity := playermapper.New()
pos, _, render, _ = playermapper.Get(entity)
playerobserver.AddEntity(entity)
fmt.Printf("player start pos: %d,%d\n", point.X*tilesize, point.Y*tilesize)
case tile.Collectible:
entity := colmapper.New()
@@ -85,12 +85,6 @@ func NewGrid(world *ecs.World,
pos.Update(point.X*tilesize, point.Y*tilesize, tilesize)
}
// not part of the grid, but add them as well
entity := ptmapper.New()
_, particle := ptmapper.Get(entity)
particle.Index = assets.Tiles['*'].Particle
particle.Particles = assets.Tiles['*'].Particles
return &Grid{
Size: len(mapslice),
Tilesize: tilesize,