diff options
Diffstat (limited to 'graphics/src/assets.rs')
| -rw-r--r-- | graphics/src/assets.rs | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/graphics/src/assets.rs b/graphics/src/assets.rs index edac69b..f7ce68a 100644 --- a/graphics/src/assets.rs +++ b/graphics/src/assets.rs @@ -1,7 +1,7 @@ //! The `assets` crate stores all audio and image assets that need to be //! loaded during runtime -use raylib::{RaylibHandle, RaylibThread, audio::RaylibAudio}; +use raylib::{RaylibHandle, RaylibThread, audio::RaylibAudio, texture::Texture2D}; #[expect(dead_code)] type Sound = raylib::audio::Sound<'static>; @@ -32,18 +32,63 @@ impl AudioData { } } +/// 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 { + pub(crate) 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), + } + } + + pub(crate) fn x(&self) -> i32 { + self.xy().0 + } + + pub(crate) 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) struct ImageData { + pub(crate) atlas: Texture2D, +} impl ImageData { pub(crate) fn load( - _handle: &mut RaylibHandle, - _thread: &RaylibThread, + handle: &mut RaylibHandle, + thread: &RaylibThread, ) -> crate::Result<Self> { - // TODO: load image data - - //let example = handle.load_texture(&thread, "example.png"); + let atlas = handle.load_texture(thread, "assets/atlas.bmp")?; - Ok(Self {}) + Ok(Self { atlas }) } } |