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
|
//! The `assets` crate stores all audio and image assets that need to be
//! loaded during runtime
use raylib::{RaylibHandle, RaylibThread, audio::RaylibAudio, texture::Texture2D};
#[expect(dead_code)]
type Sound = raylib::audio::Sound<'static>;
/// The `AudioData` container initalizes the audio subsystem
/// for raylib, leaks it (to gurentee audio is statically loaded),
/// then loads all needed audio samples
#[derive(Debug)]
pub struct AudioData {}
impl AudioData {
pub(crate) fn load() -> crate::Result<Self> {
// Phantom handle to the raylib audio subsystem
// Raylib doesnt use a handle, but the rust bindings
// have one to ensure memory safety.
//
// We must leak this handle after allocating it,
// if we dont then all audio will be unloaded :(
//
// NOTE: would this cause issues if `AudioData::load` was
// called multiple times?
let _handle = Box::leak(Box::new(RaylibAudio::init_audio_device()?));
// TODO: load audio samples
//let example = handle.new_sound("example.ogg")?;
Ok(Self {})
}
}
/// The baseline size of all ingame sprites and tile textures
pub(crate) const BASE_TILE_SIZE: i32 = 32;
/// The height of the wall (offset between tile layers)
pub(crate) const WALL_HEIGHT: i32 = 13;
/// Texture indexes into the atlas
#[derive(Clone, Copy, Debug)]
pub(crate) enum AtlasTexture {
Wall,
FloorFull,
FloorEmpty,
WallBase,
WallEdgeNorth,
WallEdgeEast,
WallEdgeSouth,
WallEdgeWest,
Player,
Error,
}
impl AtlasTexture {
/// Returns the x,y position of the sprite on the atlas.bmp texture
#[must_use]
pub(crate) const fn xy(&self) -> (i32, i32) {
match self {
Self::Wall => (0, 0),
Self::FloorFull => (1, 0),
Self::FloorEmpty => (2, 0),
Self::WallBase => (3, 0),
Self::WallEdgeNorth => (0, 1),
Self::WallEdgeEast => (1, 1),
Self::WallEdgeSouth => (2, 1),
Self::WallEdgeWest => (3, 1),
Self::Player => (0, 2),
Self::Error => (3, 3),
}
}
/// Returns the x position of the sprite on the atlas.bmp texture
#[must_use]
pub(crate) const fn x(&self) -> i32 {
self.xy().0
}
/// Returns the y position of the sprite on the atlas.bmp texture
#[must_use]
pub(crate) const fn y(&self) -> i32 {
self.xy().1
}
}
/// The `ImageData` container loads all game sprites, and other images into memory.
#[derive(Debug)]
pub(crate) struct ImageData {
pub(crate) atlas: Texture2D,
}
impl ImageData {
pub(crate) fn load(
handle: &mut RaylibHandle,
thread: &RaylibThread,
) -> crate::Result<Self> {
let atlas = handle.load_texture(thread, "assets/atlas.bmp")?;
Ok(Self { atlas })
}
}
|