Compare commits
3 Commits
dd25d217dc
...
animationi
| Author | SHA1 | Date | |
|---|---|---|---|
| d23861a427 | |||
| 8c14f36463 | |||
| d22042cc72 |
45
assets/space/enhanced-space.pal
Normal file
45
assets/space/enhanced-space.pal
Normal 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
|
||||
BIN
assets/space/enhancedpalette.ase
Normal file
BIN
assets/space/enhancedpalette.ase
Normal file
Binary file not shown.
BIN
assets/space/obstacle-alldirections.ase
Normal file
BIN
assets/space/obstacle-alldirections.ase
Normal file
Binary file not shown.
BIN
assets/space/obstacle.ase
Normal file
BIN
assets/space/obstacle.ase
Normal file
Binary file not shown.
BIN
assets/space/player.ase
Normal file
BIN
assets/space/player.ase
Normal file
Binary file not shown.
BIN
assets/space/sprites.ase
Normal file
BIN
assets/space/sprites.ase
Normal file
Binary file not shown.
Binary file not shown.
@@ -12,10 +12,21 @@ const (
|
||||
Destruction = iota
|
||||
Idle
|
||||
Collision
|
||||
Moving
|
||||
)
|
||||
|
||||
// virtual location, aka tile address
|
||||
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
|
||||
Loop bool // remove the entity if false, loop endless otherwise
|
||||
Index int // where we are currently
|
||||
@@ -24,6 +35,59 @@ type Animation struct {
|
||||
Timer Timer
|
||||
Trigger string
|
||||
Data assets.TileAnimation
|
||||
Render *Renderable
|
||||
Which AnimationTrigger
|
||||
}
|
||||
|
||||
func (animation *StandardAnimation) StartAnimation() {
|
||||
animation.Active = true
|
||||
animation.Timer.Start(0)
|
||||
}
|
||||
|
||||
func (animation *StandardAnimation) StopAnimation() {
|
||||
animation.Active = false
|
||||
}
|
||||
|
||||
func (animation *StandardAnimation) GetSprite() *ebiten.Image {
|
||||
return animation.Sprites[animation.Index].Sprite
|
||||
}
|
||||
|
||||
func (animation *StandardAnimation) GetDuration() time.Duration {
|
||||
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 {
|
||||
@@ -32,49 +96,28 @@ type Renderable struct {
|
||||
DamageImage *ebiten.Image // FIXME: put into its own struct
|
||||
Damaged int
|
||||
Shader *ebiten.Shader
|
||||
DestructionAnimate Animation
|
||||
IdleAnimate Animation
|
||||
CollisionAnimate Animation
|
||||
Animations map[AnimationTrigger]Animation
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
func (render *Renderable) StartAnimation(which int) {
|
||||
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 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)
|
||||
idle := &IdleAnimation{
|
||||
StandardAnimation: StandardAnimation{
|
||||
Which: Idle,
|
||||
Render: render,
|
||||
},
|
||||
}
|
||||
render.Animations[Idle] = idle
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user