started with animation interface
This commit is contained in:
parent
8c14f36463
commit
d23861a427
@ -15,7 +15,18 @@ const (
|
|||||||
Moving
|
Moving
|
||||||
)
|
)
|
||||||
|
|
||||||
type Animation struct {
|
type AnimationTrigger int
|
||||||
|
|
||||||
|
type Animation interface {
|
||||||
|
GetType() AnimationTrigger
|
||||||
|
StartAnimation()
|
||||||
|
StopAnimation()
|
||||||
|
GetSprite() *ebiten.Image
|
||||||
|
GetDuration() time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
// implements the AnimationInterface
|
||||||
|
type StandardAnimation struct {
|
||||||
Active bool // animation is running
|
Active bool // animation is running
|
||||||
Loop bool // remove the entity if false, loop endless otherwise
|
Loop bool // remove the entity if false, loop endless otherwise
|
||||||
Index int // where we are currently
|
Index int // where we are currently
|
||||||
@ -24,57 +35,89 @@ type Animation struct {
|
|||||||
Timer Timer
|
Timer Timer
|
||||||
Trigger string
|
Trigger string
|
||||||
Data assets.TileAnimation
|
Data assets.TileAnimation
|
||||||
|
Render *Renderable
|
||||||
|
Which AnimationTrigger
|
||||||
}
|
}
|
||||||
|
|
||||||
type Renderable struct {
|
func (animation *StandardAnimation) StartAnimation() {
|
||||||
Pos *Position // just for debugging, will not used as positiion!
|
animation.Active = true
|
||||||
Image *ebiten.Image
|
animation.Timer.Start(0)
|
||||||
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(which int) {
|
func (animation *StandardAnimation) StopAnimation() {
|
||||||
switch which {
|
animation.Active = false
|
||||||
case Collision:
|
|
||||||
fallthrough
|
|
||||||
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) {
|
func (animation *StandardAnimation) GetSprite() *ebiten.Image {
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (animation *Animation) GetSprite() *ebiten.Image {
|
|
||||||
return animation.Sprites[animation.Index].Sprite
|
return animation.Sprites[animation.Index].Sprite
|
||||||
}
|
}
|
||||||
|
|
||||||
func (animation *Animation) GetDuration() time.Duration {
|
func (animation *StandardAnimation) GetDuration() time.Duration {
|
||||||
return animation.Sprites[animation.Index].Duration * time.Millisecond
|
return animation.Sprites[animation.Index].Duration * time.Millisecond
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (animation *StandardAnimation) GetType() AnimationTrigger {
|
||||||
|
return animation.Which
|
||||||
|
}
|
||||||
|
|
||||||
|
type CollisionAnimation struct {
|
||||||
|
StandardAnimation
|
||||||
|
}
|
||||||
|
|
||||||
|
type IdleAnimation struct {
|
||||||
|
StandardAnimation
|
||||||
|
}
|
||||||
|
|
||||||
|
type DestructionAnimation struct {
|
||||||
|
StandardAnimation
|
||||||
|
}
|
||||||
|
|
||||||
|
type MovingAnimation struct {
|
||||||
|
StandardAnimation
|
||||||
|
}
|
||||||
|
|
||||||
|
func (animation *DestructionAnimation) StartAnimation() {
|
||||||
|
animation.Render.StopAnimations()
|
||||||
|
animation.Render.Hidden = true
|
||||||
|
animation.Active = true
|
||||||
|
animation.Timer.Start(config.ANIMATION_STARTWAIT)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (animation *IdleAnimation) StartAnimation() {
|
||||||
|
animation.Render.StopAnimations()
|
||||||
|
animation.Active = true
|
||||||
|
animation.Loop = true
|
||||||
|
animation.Timer.Start(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
Animations map[AnimationTrigger]Animation
|
||||||
|
Hidden bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (render *Renderable) StopAnimations() {
|
||||||
|
for _, animation := range render.Animations {
|
||||||
|
animation.StopAnimation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (render *Renderable) AddAnimation(which AnimationTrigger) {
|
||||||
|
render.Animations = make(map[AnimationTrigger]Animation)
|
||||||
|
|
||||||
|
switch which {
|
||||||
|
case Idle:
|
||||||
|
idle := &IdleAnimation{
|
||||||
|
StandardAnimation: StandardAnimation{
|
||||||
|
Which: Idle,
|
||||||
|
Render: render,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
render.Animations[Idle] = idle
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user