diff --git a/src/gamecore.rs b/src/gamecore.rs index 7253a38..07755ae 100644 --- a/src/gamecore.rs +++ b/src/gamecore.rs @@ -2,15 +2,20 @@ use std::fmt; -use raylib::{RaylibHandle, RaylibThread}; +use raylib::{ + camera::Camera2D, math::Vector2, prelude::RaylibDrawHandle, RaylibHandle, RaylibThread, +}; use crate::resources::GlobalResources; +use log::debug; + /// Overall states for the game -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Copy, Clone)] pub enum GameState { Loading, MainMenu, + PauseMenu, } impl fmt::Display for GameState { @@ -23,20 +28,47 @@ impl fmt::Display for GameState { pub struct GameCore { /// The game's overall state pub state: GameState, + pub last_state: GameState, pub last_state_change_time: f64, pub has_rendered_first_frame: bool, /// Resources pub resources: GlobalResources, + + /// Camera (more than one maybe?) + pub master_camera: Camera2D, + + /// Debug features + pub show_simple_debug_info: bool } impl GameCore { pub fn new(raylib: &mut RaylibHandle, thread: &RaylibThread) -> Self { Self { state: GameState::Loading, + last_state: GameState::Loading, last_state_change_time: 0.0, has_rendered_first_frame: false, - resources: GlobalResources::load_all(raylib, thread).expect("Failed to load game assets. Can not launch!"), + resources: GlobalResources::load_all(raylib, thread) + .expect("Failed to load game assets. Can not launch!"), + master_camera: Camera2D { + offset: Vector2::zero(), + target: Vector2::zero(), + rotation: 0.0, + zoom: 1.0, + }, + show_simple_debug_info: false + } + } + + pub fn switch_state(&mut self, new_state: GameState, draw_handle: Option<&RaylibDrawHandle>) { + debug!("Switching global state to: {}", new_state); + + self.last_state = self.state; + self.state = new_state; + + if draw_handle.is_some() { + self.last_state_change_time = draw_handle.as_ref().unwrap().get_time(); } } } diff --git a/src/logic/mainmenu.rs b/src/logic/mainmenu.rs index 459f49a..d453c91 100644 --- a/src/logic/mainmenu.rs +++ b/src/logic/mainmenu.rs @@ -23,8 +23,11 @@ impl Screen for MainMenuScreen { audio_system: &mut AudioPlayer, game_core: &mut GameCore, ) -> Option { + // Clear frame - draw_handle.clear_background(Color::RED); + draw_handle.clear_background(Color::WHITE); + + return None; } diff --git a/src/logic/mod.rs b/src/logic/mod.rs index 8ea3fe4..6d476b4 100644 --- a/src/logic/mod.rs +++ b/src/logic/mod.rs @@ -1,4 +1,5 @@ pub mod screen; pub mod loadingscreen; pub mod mainmenu; - +pub mod pausemenu; +pub mod ingame; \ No newline at end of file diff --git a/src/logic/pausemenu.rs b/src/logic/pausemenu.rs new file mode 100644 index 0000000..a44378d --- /dev/null +++ b/src/logic/pausemenu.rs @@ -0,0 +1,34 @@ +use raylib::prelude::*; + +use crate::{ + gamecore::{GameCore, GameState}, + lib::wrappers::audio::player::AudioPlayer, +}; + +use super::screen::Screen; + +pub struct PauseMenuScreen {} + +impl PauseMenuScreen { + pub fn new() -> Self { + Self {} + } +} + +impl Screen for PauseMenuScreen { + fn render( + &mut self, + draw_handle: &mut RaylibDrawHandle, + thread: &RaylibThread, + audio_system: &mut AudioPlayer, + game_core: &mut GameCore, + ) -> Option { + + // Clear frame + draw_handle.clear_background(Color::WHITE); + + + + return None; + } +} diff --git a/src/main.rs b/src/main.rs index 8038e24..9850889 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,10 @@ mod resources; use gamecore::{GameCore, GameState}; use lib::{utils::profiler::GameProfiler, wrappers::audio::player::AudioPlayer}; -use log::{debug, info}; -use logic::{loadingscreen::LoadingScreen, mainmenu::MainMenuScreen, screen::Screen}; +use logic::{ + loadingscreen::LoadingScreen, mainmenu::MainMenuScreen, pausemenu::PauseMenuScreen, + screen::Screen, +}; use raylib::prelude::*; // Game Launch Configuration @@ -47,6 +49,7 @@ fn main() { // Create all the game screens let mut loading_screen = LoadingScreen::new(); let mut main_menu_screen = MainMenuScreen::new(); + let mut pause_menu_screen = PauseMenuScreen::new(); // Main rendering loop while !raylib.window_should_close() { @@ -66,12 +69,17 @@ fn main() { &mut audio_system, &mut game_core, ), + GameState::PauseMenu => pause_menu_screen.render( + &mut draw_handle, + &raylib_thread, + &mut audio_system, + &mut game_core, + ), }; + // If needed, update the global state if new_state.is_some() { - game_core.state = new_state.unwrap(); - game_core.last_state_change_time = draw_handle.get_time(); - debug!("Switching global state to: {}", game_core.state); + game_core.switch_state(new_state.unwrap(), Some(&draw_handle)); } // Feed the profiler @@ -90,6 +98,24 @@ fn main() { profiler.update(); } + // Debug key + if draw_handle.is_key_pressed(KeyboardKey::KEY_F3) { + game_core.show_simple_debug_info = !game_core.show_simple_debug_info; + } + + // Handle showing some simple debug info if needed + if game_core.show_simple_debug_info { + draw_handle.draw_text( + &format!("FPS: {}", draw_handle.get_fps()), + 0, + 0, + 20, + Color::RED, + ); + #[cfg(debug_assertions)] + draw_handle.draw_text("DEBUG BUILD", 0, 20, 20, Color::RED); + } + // Set the first frame flag game_core.has_rendered_first_frame = true; }