switched to go coded animation system, LDTK is not used for this anymore

This commit is contained in:
2024-04-08 18:51:25 +02:00
parent 2793710819
commit f23bdaf121
15 changed files with 233 additions and 240 deletions

View File

@@ -4,7 +4,9 @@ package components
type Tilish struct{}
type Solid struct{}
type Floor struct{}
type Collectible struct{}
type Collectible struct {
Hit bool
}
type Obstacle struct {
Direction int

View File

@@ -8,40 +8,66 @@ import (
"github.com/hajimehoshi/ebiten/v2"
)
const (
Destruction = iota
Idle
Collision
)
// virtual location, aka tile address
type Animation struct {
Active bool // animation is running
Loop bool // remove the entity if false, loop endless otherwise
Index int // where we are currently
Sprites []assets.AnimationSprite
Width, Height int // single sprite measurements
Active bool // animation is running
Loop bool // remove the entity if false, loop endless otherwise
Index int // where we are currently
Sprites []assets.AnimationSprite // each element contains the sprite and duration
Width, Height int // single sprite measurements
Timer Timer
Trigger string
Data assets.TileAnimation
}
type Renderable struct {
Pos *Position // just for debugging, will not used as positiion!
Image *ebiten.Image
DamageImage *ebiten.Image // FIXME: put into its own struct
Damaged int
Shader *ebiten.Shader
Animate Animation
IdleAnimate Animation
Hidden bool
Pos *Position // just for debugging, will not used as positiion!
Image *ebiten.Image
DamageImage *ebiten.Image // FIXME: put into its own struct
Damaged int
Shader *ebiten.Shader
DestructionAnimate Animation
IdleAnimate Animation
CollisionAnimate Animation
Hidden bool
}
func (render *Renderable) StartAnimation() {
render.Hidden = true
render.Animate.Active = true
render.Animate.Timer.Start(config.ANIMATION_STARTWAIT)
switch render.Animate.Trigger {
case "OnCollision":
func (render *Renderable) StartAnimation(which int) {
switch which {
case Collision:
fallthrough
case "OnDestruct":
render.Animate.Loop = false
case "OnIdle":
render.Animate.Loop = true
case Destruction:
render.Hidden = true
render.DestructionAnimate.Active = true
render.DestructionAnimate.Timer.Start(config.ANIMATION_STARTWAIT)
render.IdleAnimate.Active = false
case Idle:
render.IdleAnimate.Active = true
render.IdleAnimate.Loop = true
render.IdleAnimate.Timer.Start(0)
}
}
func (render *Renderable) StopAnimation(which int) {
switch which {
case Collision:
render.CollisionAnimate.Active = false
case Idle:
render.IdleAnimate.Active = false
}
}
func (render *Renderable) Animations() map[int]*Animation {
return map[int]*Animation{
Collision: &render.CollisionAnimate,
Destruction: &render.DestructionAnimate,
Idle: &render.IdleAnimate,
}
}