diff --git a/src/logic/shop/item.rs b/src/logic/shop/item.rs index 6afdb8b..1bddfd2 100644 --- a/src/logic/shop/item.rs +++ b/src/logic/shop/item.rs @@ -62,7 +62,7 @@ impl ShopItemWrapper { return self.ui.buy_button_hovered && draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON); } - pub fn render(&self, draw_handle: &mut RaylibDrawHandle, player: &Player) { + pub fn render(&mut self, draw_handle: &mut RaylibDrawHandle, player: &Player) { self.ui.render(draw_handle, self.bounds, self.can_player_afford(player)); } } diff --git a/src/logic/shop/itemui.rs b/src/logic/shop/itemui.rs index c6b98f2..0084e84 100644 --- a/src/logic/shop/itemui.rs +++ b/src/logic/shop/itemui.rs @@ -21,7 +21,7 @@ impl ShopItemUi { } pub fn render( - &self, + &mut self, draw_handle: &mut RaylibDrawHandle, bounds: Rectangle, can_be_bought: bool, @@ -58,5 +58,6 @@ impl ShopItemUi { true, ); buy_button.render(draw_handle); + self.buy_button_hovered = buy_button.is_hovered(draw_handle); } } diff --git a/src/logic/shop/mainui.rs b/src/logic/shop/mainui.rs index 39cdf76..d6d02a7 100644 --- a/src/logic/shop/mainui.rs +++ b/src/logic/shop/mainui.rs @@ -33,7 +33,7 @@ pub fn render_shop( }; // Create items - let stun_gun_buy_ui = ShopItemWrapper::new( + let mut stun_gun_buy_ui = ShopItemWrapper::new( match &game_core.player.inventory.stun_gun { Some(x) => match x.get_level() { 1 => StunGun::lvl2(), @@ -45,7 +45,7 @@ pub fn render_shop( first_bounds, 0, ); - let air_bag_buy_ui = ShopItemWrapper::new( + let mut air_bag_buy_ui = ShopItemWrapper::new( match &game_core.player.inventory.air_bag { Some(x) => match x.get_level() { 1 => AirBag::lvl2(), @@ -57,7 +57,7 @@ pub fn render_shop( first_bounds, 1, ); - let flashlight_buy_ui = ShopItemWrapper::new( + let mut flashlight_buy_ui = ShopItemWrapper::new( match &game_core.player.inventory.flashlight { Some(x) => match x.get_level() { 1 => Flashlight::lvl2(), @@ -69,7 +69,7 @@ pub fn render_shop( first_bounds, 2, ); - let flippers_buy_ui = ShopItemWrapper::new( + let mut flippers_buy_ui = ShopItemWrapper::new( match &game_core.player.inventory.flippers { Some(x) => match x.get_level() { 1 => Flippers::lvl2(), @@ -90,7 +90,20 @@ pub fn render_shop( // Handle buying items if stun_gun_buy_ui.can_player_afford(&game_core.player) && stun_gun_buy_ui.user_clicked_buy(draw_handle) { - stun_gun_buy_ui.purchase(&mut game_core.player); + 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) && 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) && 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) && flippers_buy_ui.user_clicked_buy(draw_handle) { + let item = flippers_buy_ui.purchase(&mut game_core.player); + game_core.player.inventory.flippers = Some(item); } diff --git a/src/player.rs b/src/player.rs index e7f367e..ea81463 100644 --- a/src/player.rs +++ b/src/player.rs @@ -24,8 +24,8 @@ pub struct PlayerInventory { impl PlayerInventory { pub fn new() -> Self { Self { - stun_gun: Some(StunGun::lvl1()), //TMP - flashlight: Some(Flashlight::lvl1()), //TMP + // stun_gun: Some(StunGun::lvl1()), //TMP + // flashlight: Some(Flashlight::lvl1()), //TMP ..Default::default() } } @@ -58,6 +58,7 @@ impl Player { radius: 4.5, position: spawn.clone(), inventory: PlayerInventory::new(), + coins: 50, //TMP ..Default::default() } }