diff --git a/src/logic/gameend.rs b/src/logic/gameend.rs index 94690dd..eeb7136 100644 --- a/src/logic/gameend.rs +++ b/src/logic/gameend.rs @@ -2,7 +2,7 @@ use raylib::prelude::*; use crate::{ gamecore::{GameCore, GameState}, - lib::wrappers::audio::player::AudioPlayer, + lib::{utils::button::OnScreenButton, wrappers::audio::player::AudioPlayer}, }; use super::screen::Screen; @@ -26,9 +26,11 @@ impl Screen for GameEndScreen { 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); // Window dimensions let win_height = draw_handle.get_screen_height(); @@ -53,14 +55,48 @@ impl Screen for GameEndScreen { // Render heading text draw_handle.draw_text( "OUT OF BREATH", - (win_width / 2) - 80, + (win_width / 2) - ((SCREEN_PANEL_SIZE.x as i32 + 6) / 2) + 25, (win_height / 2) - (SCREEN_PANEL_SIZE.y as i32 / 2) + 10, - 40, + 30, Color::BLACK, ); - // TODO: Save game progress + // Render message + draw_handle.draw_text( + "Your clone can now buy items ", + ((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) + 50, + 15, + Color::BLACK, + ); + // Render button + let go_to_menu_button = OnScreenButton::new( + String::from("Return to shop"), + 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::InShop, Some(draw_handle)); + + } + + // TODO: Save game progress // // Close and quit buttons // let bottom_left_button_dimensions = Rectangle { diff --git a/src/logic/ingame/mod.rs b/src/logic/ingame/mod.rs index ea95cf2..cb64580 100644 --- a/src/logic/ingame/mod.rs +++ b/src/logic/ingame/mod.rs @@ -216,6 +216,7 @@ impl Screen for InGameScreen { // Render the hud hud::render_hud(draw_handle, game_core, window_center); + // Handle player out of breath if game_core.player.breath_percent == 0.0 { return Some(GameState::GameEnd); diff --git a/src/logic/loadingscreen.rs b/src/logic/loadingscreen.rs index 06056c1..aa13ef2 100644 --- a/src/logic/loadingscreen.rs +++ b/src/logic/loadingscreen.rs @@ -89,10 +89,10 @@ impl LoadingScreen { let mask = self.get_logo_mask(playthrough_percent); // Create modified colors - let alpha_orange = Color { - r: RUST_ORANGE.r, - g: RUST_ORANGE.g, - b: RUST_ORANGE.b, + let alpha_black = Color { + r: 0, + g: 0, + b: 0, a: mask.a, }; @@ -102,7 +102,7 @@ impl LoadingScreen { win_height / 2 - 128, 256, 256, - alpha_orange, + alpha_black, ); draw_handle.draw_rectangle( win_width / 2 - 112, @@ -111,19 +111,19 @@ impl LoadingScreen { 224, Color::WHITE, ); - draw_handle.draw_text( - "rust", - win_width / 2 - 69, - win_height / 2 + 18, - 50, - alpha_orange, - ); + // draw_handle.draw_text( + // "rust", + // win_width / 2 - 69, + // win_height / 2 + 18, + // 50, + // alpha_orange, + // ); draw_handle.draw_text( "raylib", win_width / 2 - 44, win_height / 2 + 48, 50, - alpha_orange, + alpha_black, ); // Move on to next logo if needed diff --git a/src/logic/mainmenu.rs b/src/logic/mainmenu.rs index 3dc3f90..6ea0d94 100644 --- a/src/logic/mainmenu.rs +++ b/src/logic/mainmenu.rs @@ -28,8 +28,10 @@ impl Screen for MainMenuScreen { let win_height = draw_handle.get_screen_height(); let win_width = draw_handle.get_screen_width(); - // Clear frame - draw_handle.clear_background(Color::BLUE); + // // Clear frame + // draw_handle.clear_background(Color::BLUE); + // Render the background + draw_handle.draw_texture(&game_core.resources.shop_background, 0, 0, Color::WHITE); // Render title draw_handle.draw_text( @@ -56,7 +58,7 @@ impl Screen for MainMenuScreen { (win_width / 4), 60, match hovering_play_button { - true => Color::GREEN, + true => Color::BLUE, false => Color::BLACK, }, ); @@ -66,7 +68,7 @@ impl Screen for MainMenuScreen { (win_width / 4) + 100, 60, match hovering_shop_button { - true => Color::GREEN, + true => Color::BLUE, false => Color::BLACK, }, ); @@ -76,7 +78,7 @@ impl Screen for MainMenuScreen { (win_width / 4) + 200, 60, match hovering_quit_button { - true => Color::GREEN, + true => Color::RED, false => Color::BLACK, }, ); diff --git a/src/logic/shop/item.rs b/src/logic/shop/item.rs index 2c94f3b..dc7d8bd 100644 --- a/src/logic/shop/item.rs +++ b/src/logic/shop/item.rs @@ -46,8 +46,8 @@ impl ShopItemWrapper { &self.item } - pub fn can_player_afford(&self, player: &Player) -> bool { - return player.coins >= self.item.get_cost(); + pub fn can_player_afford(&self, player: &Player, players_item: &Option) -> bool { + return player.coins >= self.item.get_cost() && ((players_item.is_some() && players_item.as_ref().unwrap().get_level() < 3) || players_item.is_none()); } pub fn purchase(&self, player: &mut Player) -> T { @@ -66,7 +66,7 @@ impl ShopItemWrapper { return self.bounds.check_collision_point_rec(draw_handle.get_mouse_position()); } - pub fn render(&mut self, draw_handle: &mut RaylibDrawHandle, player: &Player) { - self.ui.render(draw_handle, self.bounds, self.can_player_afford(player)); + pub fn render(&mut self, draw_handle: &mut RaylibDrawHandle, player: &Player, players_item: &Option) { + self.ui.render(draw_handle, self.bounds, self.can_player_afford(player, players_item)); } } diff --git a/src/logic/shop/mainui.rs b/src/logic/shop/mainui.rs index 759da23..55eec57 100644 --- a/src/logic/shop/mainui.rs +++ b/src/logic/shop/mainui.rs @@ -87,31 +87,31 @@ pub fn render_shop( ); // Render items - stun_gun_buy_ui.render(draw_handle, &game_core.player); - air_bag_buy_ui.render(draw_handle, &game_core.player); - flashlight_buy_ui.render(draw_handle, &game_core.player); - flippers_buy_ui.render(draw_handle, &game_core.player); + stun_gun_buy_ui.render(draw_handle, &game_core.player, &game_core.player.inventory.stun_gun); + air_bag_buy_ui.render(draw_handle, &game_core.player, &game_core.player.inventory.air_bag); + flashlight_buy_ui.render(draw_handle, &game_core.player, &game_core.player.inventory.flashlight); + flippers_buy_ui.render(draw_handle, &game_core.player, &game_core.player.inventory.flippers); // Handle buying items - if stun_gun_buy_ui.can_player_afford(&game_core.player) + if stun_gun_buy_ui.can_player_afford(&game_core.player, &game_core.player.inventory.stun_gun) && stun_gun_buy_ui.user_clicked_buy(draw_handle) { let item = stun_gun_buy_ui.purchase(&mut game_core.player); game_core.player.inventory.stun_gun = Some(item); } - if air_bag_buy_ui.can_player_afford(&game_core.player) + if air_bag_buy_ui.can_player_afford(&game_core.player, &game_core.player.inventory.air_bag) && air_bag_buy_ui.user_clicked_buy(draw_handle) { let item = air_bag_buy_ui.purchase(&mut game_core.player); game_core.player.inventory.air_bag = Some(item); } - if flashlight_buy_ui.can_player_afford(&game_core.player) + if flashlight_buy_ui.can_player_afford(&game_core.player, &game_core.player.inventory.flashlight) && flashlight_buy_ui.user_clicked_buy(draw_handle) { let item = flashlight_buy_ui.purchase(&mut game_core.player); game_core.player.inventory.flashlight = Some(item); } - if flippers_buy_ui.can_player_afford(&game_core.player) + if flippers_buy_ui.can_player_afford(&game_core.player, &game_core.player.inventory.flippers) && flippers_buy_ui.user_clicked_buy(draw_handle) { let item = flippers_buy_ui.purchase(&mut game_core.player); @@ -243,7 +243,7 @@ pub fn render_stats( // Coins draw_handle.draw_text( - &format!("Fish: {}", game_core.player.coins.min(99)), + &format!("Fish: {}", game_core.player.coins.min(999)), bounds.x as i32 + 5, bounds.y as i32 + 5, 20,