added Timer, Particle Render Delay (via Particle.Show) +new sprites

This commit is contained in:
2024-02-12 17:27:52 +01:00
parent 65ddec3fa4
commit 5a288035b3
14 changed files with 80 additions and 20 deletions

View File

@@ -5,6 +5,7 @@ import (
"openquell/assets"
"openquell/components"
. "openquell/components"
"openquell/config"
"openquell/observers"
"github.com/hajimehoshi/ebiten/v2"
@@ -31,6 +32,7 @@ func (system *CollectibleSystem) Update() {
posID := ecs.ComponentID[components.Position](system.World)
veloID := ecs.ComponentID[components.Velocity](system.World)
particlepositions := []*components.Position{}
EntitiesToRemove := []ecs.Entity{}
@@ -93,13 +95,14 @@ func (system *CollectibleSystem) Draw(screen *ebiten.Image) {
func (system *CollectibleSystem) AddParticle(position *components.Position) {
particleobserver := observers.GetParticleObserver(system.World)
ptmapper := generic.NewMap2[
ptmapper := generic.NewMap3[
components.Position,
components.Particle,
components.Timer,
](system.World)
entity := ptmapper.New()
pos, particle := ptmapper.Get(entity)
pos, particle, timer := ptmapper.Get(entity)
particleobserver.AddEntity(entity)
particle.Index = assets.Tiles['*'].Particle
@@ -110,4 +113,6 @@ func (system *CollectibleSystem) AddParticle(position *components.Position) {
position.Y-(16),
64,
)
timer.Start(config.PARTICLE_LOOPWAIT)
}

View File

@@ -2,6 +2,7 @@ package systems
import (
. "openquell/components"
"openquell/config"
"github.com/hajimehoshi/ebiten/v2"
"github.com/mlange-42/arche/ecs"
@@ -10,13 +11,13 @@ import (
type ParticleSystem struct {
World *ecs.World
Selector *generic.Filter2[Position, Particle]
Selector *generic.Filter3[Position, Particle, Timer]
Cellsize int
}
func NewParticleSystem(world *ecs.World, cellsize int) *ParticleSystem {
system := &ParticleSystem{
Selector: generic.NewFilter2[Position, Particle](),
Selector: generic.NewFilter3[Position, Particle, Timer](),
World: world,
Cellsize: cellsize,
}
@@ -32,16 +33,24 @@ func (system *ParticleSystem) Update() {
for query.Next() {
// we loop, but it's only one anyway
_, particle := query.Get()
_, particle, timer := query.Get()
switch {
// particle shows from earlier tick, animate
case particle.Index > -1 && particle.Index < len(particle.Particles)-1:
particle.Index++
default:
// last sprite reached, remove it
EntitiesToRemove = append(EntitiesToRemove, query.Entity())
particle.Show = true
if timer.IsReady() {
switch {
// particle shows from earlier tick, animate
case particle.Index > -1 && particle.Index < len(particle.Particles)-1:
particle.Index++
timer.Start(config.PARTICLE_LOOPWAIT)
default:
// last sprite reached, remove it
EntitiesToRemove = append(EntitiesToRemove, query.Entity())
}
} else {
timer.Update()
}
}
for _, entity := range EntitiesToRemove {
@@ -55,10 +64,12 @@ func (system *ParticleSystem) Draw(screen *ebiten.Image) {
query := system.Selector.Query(system.World)
for query.Next() {
pos, particle := query.Get()
pos, particle, _ := query.Get()
op.GeoM.Reset()
op.GeoM.Translate(float64(pos.X), float64(pos.Y))
screen.DrawImage(particle.Particles[particle.Index], op)
if particle.Show {
op.GeoM.Reset()
op.GeoM.Translate(float64(pos.X), float64(pos.Y))
screen.DrawImage(particle.Particles[particle.Index], op)
}
}
}