-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.odin
More file actions
116 lines (91 loc) · 2.59 KB
/
main.odin
File metadata and controls
116 lines (91 loc) · 2.59 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package cat_fighter_fsm
import "../../anima"
import "../../anima/anima_fsm"
import "../../anima/anima_raylib"
import "core:fmt"
import "core:mem"
import rl "vendor:raylib"
CatAnim :: enum u8 {
PunchRight,
PunchLeft,
KickRight,
KickLeft,
}
anim_speed :: 0.1
main :: proc() {
when ODIN_DEBUG {
track: mem.Tracking_Allocator
mem.tracking_allocator_init(&track, context.allocator)
context.allocator = mem.tracking_allocator(&track)
defer {
if len(track.allocation_map) > 0 {
fmt.eprintf("=== %v allocations not freed: ===\n", len(track.allocation_map))
for _, entry in track.allocation_map {
fmt.eprintf("- %v bytes @ %v\n", entry.size, entry.location)
}
}
if len(track.bad_free_array) > 0 {
fmt.eprintf("=== %v incorrect frees: ===\n", len(track.bad_free_array))
for entry in track.bad_free_array {
fmt.eprintf("- %p @ %v\n", entry.memory, entry.location)
}
}
mem.tracking_allocator_destroy(&track)
}
}
rl.InitWindow(800, 600, "anima - example - cat fighter fsm")
defer rl.CloseWindow()
rl.SetTargetFPS(60)
image := rl.LoadImage("assets/cat_fighter.png")
texture := rl.LoadTextureFromImage(image)
defer rl.UnloadTexture(texture)
rl.UnloadImage(image)
camera := rl.Camera2D{0, 0, 0.0, 2.0}
g := anima.new_grid(50, 50, uint(texture.width), uint(texture.height))
cat := anima_fsm.create(CatAnim)
defer anima_fsm.destroy(cat)
anima_fsm.add(
cat,
CatAnim.PunchRight,
anima.new_animation(anima.grid_frames(&g, "6-9", 3), anim_speed),
)
anima_fsm.add(
cat,
CatAnim.PunchLeft,
anima.new_animation(anima.grid_frames(&g, "6-9", 3), anim_speed, flip_v = true),
)
anima_fsm.add(
cat,
CatAnim.KickLeft,
anima.new_animation(anima.grid_frames(&g, "0-9", 4, "8-1", 4), anim_speed),
)
anima_fsm.add(
cat,
CatAnim.KickRight,
anima.new_animation(anima.grid_frames(&g, "0-9", 4, "8-1", 4), anim_speed, flip_v = true),
)
anima_fsm.play(cat, CatAnim.PunchRight)
for !rl.WindowShouldClose() {
dt := rl.GetFrameTime()
if rl.IsKeyPressed(rl.KeyboardKey.Q) {
anima_fsm.play(cat, CatAnim.PunchLeft)
}
if rl.IsKeyPressed(rl.KeyboardKey.W) {
anima_fsm.play(cat, CatAnim.PunchRight)
}
if rl.IsKeyPressed(rl.KeyboardKey.A) {
anima_fsm.play(cat, CatAnim.KickRight)
}
if rl.IsKeyPressed(rl.KeyboardKey.S) {
anima_fsm.play(cat, CatAnim.KickLeft)
}
anima_fsm.update(cat, dt)
rl.BeginDrawing()
rl.ClearBackground(rl.BLACK)
rl.BeginMode2D(camera)
anima_raylib.fsm_draw(cat, texture, 100, 100)
rl.DrawText("Q/W to punch left/right, A/S to kick left/right", 10, 10, 10, rl.GREEN)
rl.EndMode2D()
rl.EndDrawing()
}
}