diff --git a/src/gamecore.rs b/src/gamecore.rs index 0954c0f..1f56a4f 100644 --- a/src/gamecore.rs +++ b/src/gamecore.rs @@ -25,7 +25,8 @@ pub enum GameState { GameQuit, InGame, GameEnd, - InShop + InShop, + WinGame } impl fmt::Display for GameState { diff --git a/src/logic/gameend.rs b/src/logic/gameend.rs index eeb7136..c20064e 100644 --- a/src/logic/gameend.rs +++ b/src/logic/gameend.rs @@ -25,9 +25,8 @@ impl Screen for GameEndScreen { 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? + draw_handle.clear_background(Color::GRAY); + // TODO: Maybe we can stick some art here? // Render the background draw_handle.draw_texture(&game_core.resources.shop_background, 0, 0, Color::WHITE); @@ -71,7 +70,7 @@ impl Screen for GameEndScreen { Color::BLACK, ); - // Render button + // Creates let go_to_menu_button = OnScreenButton::new( String::from("Return to shop"), Rectangle { @@ -88,8 +87,10 @@ impl Screen for GameEndScreen { true, ); + // render button go_to_menu_button.render(draw_handle); + // If the player clicks on the button send them to shop if go_to_menu_button.is_hovered(draw_handle) && draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON){ game_core.switch_state(GameState::InShop, Some(draw_handle)); diff --git a/src/logic/ingame/mod.rs b/src/logic/ingame/mod.rs index cb64580..85da3a0 100644 --- a/src/logic/ingame/mod.rs +++ b/src/logic/ingame/mod.rs @@ -222,6 +222,10 @@ impl Screen for InGameScreen { return Some(GameState::GameEnd); } + if game_core.world.end_position.distance_to(game_core.player.position) <= 70.0{ + return Some(GameState::WinGame); + } + return None; } } diff --git a/src/logic/mod.rs b/src/logic/mod.rs index 7b1e5eb..9942ba6 100644 --- a/src/logic/mod.rs +++ b/src/logic/mod.rs @@ -4,4 +4,5 @@ pub mod mainmenu; pub mod pausemenu; pub mod ingame; pub mod gameend; -pub mod shop; \ No newline at end of file +pub mod shop; +pub mod winscreen; \ No newline at end of file diff --git a/src/logic/winscreen.rs b/src/logic/winscreen.rs new file mode 100644 index 0000000..76628bb --- /dev/null +++ b/src/logic/winscreen.rs @@ -0,0 +1,93 @@ +use raylib::prelude::*; + +use crate::lib::utils::button::OnScreenButton; +use crate::{ + gamecore::{GameCore, GameState}, + lib::wrappers::audio::player::AudioPlayer, +}; + +use super::screen::Screen; + +const SCREEN_PANEL_SIZE: Vector2 = Vector2 { x: 300.0, y: 300.0 }; + +pub struct WinScreen {} + +impl WinScreen { + pub fn new() -> Self { + return Self {}; + } +} + +impl Screen for WinScreen { + fn render( + &mut self, + draw_handle: &mut RaylibDrawHandle, + thread: &RaylibThread, + audio_system: &mut AudioPlayer, + game_core: &mut GameCore, + ) -> Option { + 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( + "You've Won!!", + (win_width / 2) - ((SCREEN_PANEL_SIZE.x as i32 + 6) / 2) + 60, + (win_height / 2) - (SCREEN_PANEL_SIZE.y as i32 / 2) + 10, + 30, + Color::BLACK, + ); + + // Render message + draw_handle.draw_text( + "You can use the transponder to \ncontact help!", + ((win_width / 2) - ((SCREEN_PANEL_SIZE.x as i32 + 6) / 2)) + (0.15 * SCREEN_PANEL_SIZE.x)as i32, + (win_height / 2) - (SCREEN_PANEL_SIZE.y as i32 / 2) + 80, + 15, + Color::BLACK, + ); + + // Render button + let go_to_menu_button = OnScreenButton::new( + String::from("Return to menu"), + Rectangle { + x: (((win_width / 2) - ((SCREEN_PANEL_SIZE.x as i32 + 6) / 2) + 5) + + (0.15 * SCREEN_PANEL_SIZE.x) as i32) as f32, + y: (((win_height / 2) - (SCREEN_PANEL_SIZE.y as i32 / 2) + 90) as f32) + 100.0, + width: 210.0, + height: 50.0, + }, + Color::WHITE, + Color::BLACK, + Color::GRAY, + 25, + true, + ); + + go_to_menu_button.render(draw_handle); + + if go_to_menu_button.is_hovered(draw_handle) + && draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) + { + game_core.switch_state(GameState::MainMenu, Some(draw_handle)); + } + + return None; + } +} diff --git a/src/main.rs b/src/main.rs index 64c8e2a..2310fd4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,10 +11,7 @@ mod world; 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, shop::ShopScreen, -}; +use logic::{gameend::GameEndScreen, ingame::InGameScreen, loadingscreen::LoadingScreen, mainmenu::MainMenuScreen, pausemenu::PauseMenuScreen, screen::Screen, shop::ShopScreen, winscreen::{self, WinScreen}}; use raylib::prelude::*; use world::{load_world_colliders, World}; @@ -75,6 +72,7 @@ fn main() { let mut ingame_screen = InGameScreen::new(); let mut game_end_screen = GameEndScreen::new(); let mut shop_screen = ShopScreen::new(); + let mut win_screen = WinScreen::new(); // Main rendering loop while !raylib.window_should_close() { @@ -119,6 +117,12 @@ fn main() { &mut audio_system, &mut game_core, ), + GameState::WinGame => win_screen.render( + &mut draw_handle, + &raylib_thread, + &mut audio_system, + &mut game_core, + ) }; // If needed, update the global state