61 lines
2.0 KiB
Odin
61 lines
2.0 KiB
Odin
// -----------------------------------------------------------------------------
|
|
// Asset Manager
|
|
//
|
|
// Responsible for loading, owning, and unloading all game assets.
|
|
// Assets are loaded once, shared throughout the game, and released on close
|
|
// -----------------------------------------------------------------------------
|
|
package game
|
|
|
|
import rl "vendor:raylib"
|
|
|
|
Player_Assets :: struct {
|
|
clips: [Player_State]AnimationClip,
|
|
}
|
|
|
|
Enemy_Assets :: struct {
|
|
clips: [Enemy_State]AnimationClip,
|
|
}
|
|
|
|
Asset_Manager :: struct {
|
|
player: Player_Assets,
|
|
enemy: Enemy_Assets,
|
|
}
|
|
|
|
asset_manager_init :: proc() -> Asset_Manager {
|
|
assets := Asset_Manager{}
|
|
init_player_assets(&assets.player.clips)
|
|
init_enemy_assets(&assets.enemy.clips)
|
|
|
|
return assets
|
|
}
|
|
|
|
init_player_assets :: proc(clip_array: ^[Player_State]AnimationClip) {
|
|
idle_tex := rl.LoadTexture("assets/textures/player/player_idle.png")
|
|
walk_tex := rl.LoadTexture("assets/textures/player/player_walk.png")
|
|
|
|
clip_array[.IDLE] = AnimationClip {
|
|
texture = idle_tex, frame_count = 6, frame_width = 32, frame_height = 32, frame_time = 0.14, looping = true,
|
|
}
|
|
clip_array[.WALK] = AnimationClip {
|
|
texture = walk_tex, frame_count = 8, frame_width = 32, frame_height = 32, frame_time = 0.14, looping = true,
|
|
}
|
|
}
|
|
|
|
init_enemy_assets :: proc(clip_array: ^[Enemy_State]AnimationClip) {
|
|
idle_tex := rl.LoadTexture("assets/textures/enemy/player_idle.png")
|
|
walk_tex := rl.LoadTexture("assets/textures/enemy/player_walk.png")
|
|
|
|
clip_array[.IDLE] = AnimationClip {
|
|
texture = idle_tex, frame_count = 6, frame_width = 32, frame_height = 32, frame_time = 0.14, looping = true,
|
|
}
|
|
clip_array[.WALK] = AnimationClip {
|
|
texture = walk_tex, frame_count = 8, frame_width = 32, frame_height = 32, frame_time = 0.14, looping = true,
|
|
}
|
|
}
|
|
|
|
asset_manager_destroy :: proc(assets: ^Asset_Manager) {
|
|
for clip in assets.player.clips {
|
|
rl.UnloadTexture(clip.texture)
|
|
}
|
|
}
|