switched to go coded animation system, LDTK is not used for this anymore
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
package systems
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"openquell/components"
|
||||
. "openquell/components"
|
||||
"openquell/config"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/mlange-42/arche/ecs"
|
||||
@@ -32,28 +33,35 @@ func (system *AnimationSystem) Update() error {
|
||||
|
||||
for query.Next() {
|
||||
_, render := query.Get()
|
||||
if render.Animate.Active {
|
||||
if render.Animate.Timer.IsReady() {
|
||||
switch {
|
||||
// animation shows from earlier tick, animate
|
||||
case render.Animate.Index > -1 && render.Animate.Index < len(render.Animate.Sprites)-1:
|
||||
render.Animate.Index += 1
|
||||
render.Animate.Timer.Start(config.ANIMATION_LOOPWAIT)
|
||||
default:
|
||||
// last sprite reached
|
||||
if render.Animate.Loop {
|
||||
render.Animate.Index = 0
|
||||
} else {
|
||||
EntitiesToRemove = append(EntitiesToRemove, query.Entity())
|
||||
|
||||
for animationtype, animate := range render.Animations() {
|
||||
if animate.Active {
|
||||
if animate.Timer.IsReady() {
|
||||
switch {
|
||||
// animation shows from earlier tick, animate
|
||||
case animate.Index > -1 && animate.Index < len(animate.Sprites)-1:
|
||||
animate.Index += 1
|
||||
animate.Timer.Start(animate.GetDuration())
|
||||
default:
|
||||
// last sprite reached
|
||||
if animate.Loop {
|
||||
animate.Index = 0
|
||||
animate.Timer.Start(animate.GetDuration())
|
||||
}
|
||||
|
||||
if animationtype == components.Destruction {
|
||||
EntitiesToRemove = append(EntitiesToRemove, query.Entity())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
animate.Timer.Update()
|
||||
}
|
||||
} else {
|
||||
render.Animate.Timer.Update()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, entity := range EntitiesToRemove {
|
||||
slog.Debug("remove collectible")
|
||||
system.World.RemoveEntity(entity)
|
||||
}
|
||||
|
||||
@@ -68,10 +76,13 @@ func (system *AnimationSystem) Draw(screen *ebiten.Image) {
|
||||
for query.Next() {
|
||||
pos, render := query.Get()
|
||||
|
||||
if render.Animate.Active {
|
||||
op.GeoM.Reset()
|
||||
op.GeoM.Translate(float64(pos.X), float64(pos.Y))
|
||||
screen.DrawImage(render.Animate.GetSprite(), op)
|
||||
for _, animate := range render.Animations() {
|
||||
if animate.Active {
|
||||
op.GeoM.Reset()
|
||||
op.GeoM.Translate(float64(pos.X), float64(pos.Y))
|
||||
sprite := animate.GetSprite()
|
||||
screen.DrawImage(sprite, op)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"log/slog"
|
||||
"openquell/components"
|
||||
. "openquell/components"
|
||||
|
||||
. "openquell/config"
|
||||
"openquell/observers"
|
||||
|
||||
@@ -38,12 +39,18 @@ func (system *CollectibleSystem) Update() error {
|
||||
numcollectibles := query.Count()
|
||||
|
||||
if numcollectibles == 0 || observer.Lost {
|
||||
slog.Debug("WON")
|
||||
timer := observers.GetGameObserver(system.World).StopTimer
|
||||
if !timer.Running {
|
||||
timer.Start(LEVEL_END_WAIT)
|
||||
|
||||
}
|
||||
query.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
for query.Next() {
|
||||
colposition, _, render := query.Get()
|
||||
colposition, collectible, render := query.Get()
|
||||
|
||||
for _, player := range observer.GetPlayers() {
|
||||
if !system.World.Alive(player) {
|
||||
@@ -54,10 +61,10 @@ func (system *CollectibleSystem) Update() error {
|
||||
playervelocity := (*Velocity)(system.World.Get(player, veloID))
|
||||
|
||||
ok, _ := colposition.Intersects(playerposition, playervelocity)
|
||||
if ok && !render.Hidden {
|
||||
if ok && !collectible.Hit {
|
||||
slog.Debug("bumped into collectible", "colpos", colposition)
|
||||
|
||||
render.StartAnimation()
|
||||
render.StartAnimation(components.Destruction)
|
||||
|
||||
// position the animation relative to the middle of the current entity
|
||||
colposition.Update(
|
||||
@@ -65,19 +72,13 @@ func (system *CollectibleSystem) Update() error {
|
||||
colposition.Y-(system.Cellsize/2),
|
||||
64,
|
||||
)
|
||||
|
||||
collectible.Hit = true
|
||||
numcollectibles--
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if numcollectibles == 0 {
|
||||
// winner, winner, chicken dinner!
|
||||
timer := observers.GetGameObserver(system.World).StopTimer
|
||||
if !timer.Running {
|
||||
timer.Start(LEVEL_END_WAIT)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user