completed animation setup and code based solely on LDTK settings

This commit is contained in:
2024-04-03 19:39:08 +02:00
parent 001b67f97a
commit f844058bf9
13 changed files with 262 additions and 172 deletions

View File

@@ -1,11 +0,0 @@
package components
import "github.com/hajimehoshi/ebiten/v2"
type Animation struct {
Show bool
Index int
Loop bool
Tiles []*ebiten.Image
Width, Height int // single sprite measurements
}

View File

@@ -1,19 +1,5 @@
package components
import (
"github.com/hajimehoshi/ebiten/v2"
)
// virtual location, aka tile address
type Renderable struct {
Pos *Position // just for debugging, will not used as positiion!
Image *ebiten.Image
DamageImage *ebiten.Image
Damaged int
Shader *ebiten.Shader
}
// only tile entities will have those
type Tilish struct{}
type Solid struct{}

43
components/renderable.go Normal file
View File

@@ -0,0 +1,43 @@
package components
import (
"openquell/config"
"github.com/hajimehoshi/ebiten/v2"
)
// 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
Tiles []*ebiten.Image
Width, Height int // single sprite measurements
Timer Timer
Trigger string
}
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
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":
fallthrough
case "OnDestruct":
render.Animate.Loop = false
case "OnIdle":
render.Animate.Loop = true
}
}