3 Commits

Author SHA1 Message Date
d23861a427 started with animation interface 2024-04-15 14:42:52 +02:00
8c14f36463 more new tiles 2024-04-15 13:36:40 +02:00
d22042cc72 enhanced 2024-04-12 19:01:17 +02:00
8 changed files with 133 additions and 45 deletions

View File

@@ -0,0 +1,45 @@
JASC-PAL
0100
42
0 0 0
0 0 0
14 14 14
29 29 29
51 51 51
80 80 80
99 99 99
122 122 122
167 167 167
192 192 192
228 228 228
251 245 239
242 211 171
255 227 160
255 216 117
255 202 60
255 168 36
255 141 0
73 77 126
63 69 136
54 61 145
44 52 155
35 44 164
26 36 173
39 39 68
31 31 76
27 27 80
22 22 85
17 17 90
14 14 93
139 109 156
142 98 167
145 86 179
150 68 197
154 52 213
158 36 229
198 159 165
204 153 161
212 145 155
221 136 149
230 127 143
241 116 135

Binary file not shown.

Binary file not shown.

BIN
assets/space/obstacle.ase Normal file

Binary file not shown.

BIN
assets/space/player.ase Normal file

Binary file not shown.

BIN
assets/space/sprites.ase Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -12,10 +12,21 @@ const (
Destruction = iota Destruction = iota
Idle Idle
Collision Collision
Moving
) )
// virtual location, aka tile address type AnimationTrigger int
type Animation struct {
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
}
}