diff --git a/src/gamecore.rs b/src/gamecore.rs index 19b9592..fcbe880 100644 --- a/src/gamecore.rs +++ b/src/gamecore.rs @@ -25,6 +25,7 @@ pub enum GameState { GameQuit, InGame, GameEnd, + InShop } impl fmt::Display for GameState { diff --git a/src/logic/mod.rs b/src/logic/mod.rs index 362eee2..19c7044 100644 --- a/src/logic/mod.rs +++ b/src/logic/mod.rs @@ -3,4 +3,5 @@ pub mod loadingscreen; pub mod mainmenu; pub mod pausemenu; pub mod ingame; -pub mod gameend; \ No newline at end of file +pub mod gameend; +pub mod shopscreen; \ No newline at end of file diff --git a/src/logic/shopscreen.rs b/src/logic/shopscreen.rs new file mode 100644 index 0000000..3c1db0a --- /dev/null +++ b/src/logic/shopscreen.rs @@ -0,0 +1,130 @@ +use raylib::prelude::*; + +use crate::{ + gamecore::{GameCore, GameState}, + lib::wrappers::audio::player::AudioPlayer, +}; + +use super::screen::Screen; + +const SCREEN_PANEL_SIZE: Vector2 = Vector2 { x: 300.0, y: 380.0 }; + +pub struct ShopScreen {} + +impl ShopScreen { + pub fn new() -> Self { + Self {} + } +} + +impl Screen for ShopScreen { + fn render( + &mut self, + draw_handle: &mut RaylibDrawHandle, + _thread: &RaylibThread, + audio_system: &mut AudioPlayer, + game_core: &mut GameCore, + ) -> Option { + let mouse_position = draw_handle.get_mouse_position(); + draw_handle.clear_background(Color::GRAY); + // TODO: Maybe we can stick some art here? + + // If escape is pressed again, return to the previous render state + if draw_handle.is_key_pressed(KeyboardKey::KEY_ESCAPE) { + return Some(game_core.last_state); + } + + // Window dimensions + let win_height = draw_handle.get_screen_height(); + let win_width = draw_handle.get_screen_width(); + + // Render the backing to the menu itself + draw_handle.draw_rectangle( + (win_width / 2) - ((SCREEN_PANEL_SIZE.x as i32 + 6) / 2), + (win_height / 2) - ((SCREEN_PANEL_SIZE.y as i32 + 6) / 2), + SCREEN_PANEL_SIZE.x as i32 + 6, + SCREEN_PANEL_SIZE.y as i32 + 6, + Color::BLACK, + ); + draw_handle.draw_rectangle( + (win_width / 2) - (SCREEN_PANEL_SIZE.x as i32 / 2), + (win_height / 2) - (SCREEN_PANEL_SIZE.y as i32 / 2), + SCREEN_PANEL_SIZE.x as i32, + SCREEN_PANEL_SIZE.y as i32, + Color::WHITE, + ); + + // Render heading text + draw_handle.draw_text( + "SHOP", + (win_width / 2) - 80, + (win_height / 2) - (SCREEN_PANEL_SIZE.y as i32 / 2) + 10, + 40, + Color::BLACK, + ); + + + // Close and quit buttons + let bottom_left_button_dimensions = Rectangle { + x: (win_width as f32 / 2.0) - (SCREEN_PANEL_SIZE.x / 2.0) + 5.0, + y: (win_height as f32 / 2.0) + (SCREEN_PANEL_SIZE.y / 2.0) - 50.0, + width: (SCREEN_PANEL_SIZE.x / 2.0) - 15.0, + height: 40.0, + }; + let bottom_right_button_dimensions = Rectangle { + x: (win_width as f32 / 2.0) + 5.0, + y: bottom_left_button_dimensions.y, + width: bottom_left_button_dimensions.width, + height: bottom_left_button_dimensions.height, + }; + + // Check if the mouse is over either button + let mouse_over_bottom_left_button = + bottom_left_button_dimensions.check_collision_point_rec(mouse_position); + let mouse_over_bottom_right_button = + bottom_right_button_dimensions.check_collision_point_rec(mouse_position); + + // Render buttons + draw_handle.draw_rectangle_lines_ex( + bottom_left_button_dimensions, + 3, + match mouse_over_bottom_left_button { + true => Color::GRAY, + false => Color::BLACK, + }, + ); + draw_handle.draw_text( + "Quit", + bottom_left_button_dimensions.x as i32 + 15, + bottom_left_button_dimensions.y as i32 + 5, + 30, + Color::BLACK, + ); + draw_handle.draw_rectangle_lines_ex( + bottom_right_button_dimensions, + 3, + match mouse_over_bottom_right_button { + true => Color::GRAY, + false => Color::BLACK, + }, + ); + draw_handle.draw_text( + "Close", + bottom_right_button_dimensions.x as i32 + 15, + bottom_right_button_dimensions.y as i32 + 5, + 30, + Color::BLACK, + ); + + // Handle click actions on the buttons + if draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) { + if mouse_over_bottom_left_button { + return Some(GameState::GameQuit); + } else if mouse_over_bottom_right_button { + return Some(game_core.last_state); + } + } + + return None; + } +} diff --git a/src/main.rs b/src/main.rs index aa48d4a..a98eed6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ mod items; use gamecore::{GameCore, GameProgress, GameState}; use lib::{utils::profiler::GameProfiler, wrappers::audio::player::AudioPlayer}; use log::info; -use logic::{gameend::GameEndScreen, ingame::InGameScreen, loadingscreen::LoadingScreen, mainmenu::MainMenuScreen, pausemenu::PauseMenuScreen, screen::Screen}; +use logic::{gameend::GameEndScreen, ingame::InGameScreen, loadingscreen::LoadingScreen, mainmenu::MainMenuScreen, pausemenu::PauseMenuScreen, screen::Screen, shopscreen::ShopScreen}; use raylib::prelude::*; use world::{World, load_world_colliders}; @@ -63,6 +63,7 @@ fn main() { let mut pause_menu_screen = PauseMenuScreen::new(); let mut ingame_screen = InGameScreen::new(); let mut game_end_screen = GameEndScreen::new(); + let mut shop_screen = ShopScreen::new(); // Main rendering loop while !raylib.window_should_close() { @@ -101,6 +102,12 @@ fn main() { &mut audio_system, &mut game_core, ), + GameState::InShop => shop_screen.render( + &mut draw_handle, + &raylib_thread, + &mut audio_system, + &mut game_core, + ), }; // If needed, update the global state