55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package components
|
|
|
|
import (
|
|
"openquell/assets"
|
|
"openquell/config"
|
|
"time"
|
|
|
|
"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
|
|
Sprites []assets.AnimationSprite
|
|
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
|
|
IdleAnimate 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
|
|
}
|
|
}
|
|
|
|
func (animation *Animation) GetSprite() *ebiten.Image {
|
|
return animation.Sprites[animation.Index].Sprite
|
|
}
|
|
|
|
func (animation *Animation) GetDuration() time.Duration {
|
|
return animation.Sprites[animation.Index].Duration * time.Millisecond
|
|
}
|