use dungeon::Dungeon; use raylib::{ color::Color, prelude::{RaylibDraw, RaylibDrawHandle}, }; #[cfg(debug_assertions)] use raylib::RaylibHandle; /// Debug information used each frame #[cfg(debug_assertions)] pub struct DebugInfo { pub fps: u32, } #[cfg(debug_assertions)] impl DebugInfo { pub fn new(handle: &RaylibHandle) -> Self { let fps = handle.get_fps(); Self { fps } } } /// A `Renderer` is a renderer for a single /// frame of the game. It is created per frame. pub struct Renderer<'a> { handle: RaylibDrawHandle<'a>, #[cfg(debug_assertions)] debug: DebugInfo, } impl<'a> Renderer<'a> { /// Creates the renderer for the current frame #[cfg(debug_assertions)] pub(crate) fn new(handle: RaylibDrawHandle<'a>, debug: DebugInfo) -> Self { Self { handle, debug } } /// Creates the renderer for the current frame #[cfg(not(debug_assertions))] pub(crate) fn new(handle: RaylibDrawHandle<'a>) -> Self { Self { handle } } /// Returns the current render width pub fn render_width(&mut self) -> i32 { self.handle.get_render_width() } /// Returns the current render height pub fn render_height(&mut self) -> i32 { self.handle.get_render_height() } /// Clear the screen pub fn clear(&mut self) { self.handle.clear_background(Color::BLACK); } /// Draws an entire frame pub fn draw_frame(&mut self, dungeon: &Dungeon) { // Clear the background to black self.clear(); // Draw the dungeon self.draw_tiles(dungeon); self.draw_player(dungeon); // Draw fps (debug mode only) #[cfg(debug_assertions)] self.draw_fps(self.debug.fps); } /// Draw game over screen pub fn draw_game_over(&mut self) { // TODO: } /// Draw the player sprite pub fn draw_player(&mut self, _dungeon: &Dungeon) { // TODO: } /// Draw dungeon tiles pub fn draw_tiles(&mut self, _dungeon: &Dungeon) { // TODO: } /// Draw FPS counter pub fn draw_fps(&mut self, fps: u32) { let fps_str = format!("{fps}"); self.handle.draw_text(&fps_str, 10, 10, 30, Color::YELLOW); } }