-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation.odin
68 lines (54 loc) · 1.6 KB
/
animation.odin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package odinTd
import sa "core:container/small_array"
import rl "vendor:raylib"
EphemeralAnimation :: struct {
duration, timer, scale, rotation: f32,
spritemapDirection: SpritemapDirectionKind,
position, worldDimensions: rl.Vector2,
texture: ^rl.Texture,
tint: rl.Color,
origin: rl.Vector2,
using a: Animation,
flip: bool,
}
Animation :: struct {
frameDuration: f32,
numFrames: int,
st: Subtexture,
}
create_ephemeral_animation :: proc(using gs: ^GameState, e: EphemeralAnimation) {
// fmt.println(e)
sa.append(&ephemeralAnimations, e)
}
draw_ephemeral_animation :: proc(using ea: ^EphemeralAnimation) {
// from 0 to 1, e.g 0.8
animationProgress := timer / duration
// fmt.println(timer, duration, animationProgress)
// 6 * 0.8 = 4.8. Then round. 4.8 -> 5
currentFrame := int(f32(numFrames) * animationProgress)
// if spritemapDirection == .Right do fmt.println(currentFrame)
source := st
assert(spritemapDirection != .Unknown)
switch spritemapDirection {
case .Unknown:
case .Right:
source.x += st.width * f32(currentFrame)
case .Down:
source.y += st.height * f32(currentFrame)
}
// rl.DrawRectanglePro(
// {position.x, position.y, st.width * scale, st.height * scale},
// {0, st.height / 2},
// rotation,
// rl.RED,
// )
if flip do source.width = -source.width
rl.DrawTexturePro(
texture^,
source,
{position.x, position.y, worldDimensions.x * scale, st.height * scale},
origin,
rotation,
tint,
)
}