working on buy buttons
This commit is contained in:
parent
010ad7ce26
commit
3a2caecfff
24
src/items.rs
24
src/items.rs
@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||
pub struct StunGun {
|
||||
pub range: f32,
|
||||
pub duration: f64,
|
||||
pub level: u8,
|
||||
}
|
||||
|
||||
impl StunGun {
|
||||
@ -11,18 +12,21 @@ impl StunGun {
|
||||
Self {
|
||||
range: 30.0,
|
||||
duration: 0.75,
|
||||
level: 1,
|
||||
}
|
||||
}
|
||||
pub fn lvl2() -> Self {
|
||||
Self {
|
||||
range: 60.0,
|
||||
duration: 1.25,
|
||||
level: 2,
|
||||
}
|
||||
}
|
||||
pub fn lvl3() -> Self {
|
||||
Self {
|
||||
range: 80.0,
|
||||
duration: 1.0,
|
||||
level: 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -30,45 +34,53 @@ impl StunGun {
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
||||
pub struct AirBag {
|
||||
extra_oxygen: u32,
|
||||
pub level: u8,
|
||||
}
|
||||
|
||||
impl AirBag {
|
||||
pub fn lvl1() -> Self {
|
||||
Self {
|
||||
extra_oxygen: 15,
|
||||
level: 1,
|
||||
}
|
||||
}
|
||||
pub fn lvl2() -> Self {
|
||||
Self {
|
||||
extra_oxygen: 30,
|
||||
level: 2,
|
||||
}
|
||||
}
|
||||
pub fn lvl3() -> Self {
|
||||
Self {
|
||||
extra_oxygen: 45,
|
||||
level: 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
||||
pub struct Flashlight {
|
||||
pub radius: f32
|
||||
pub radius: f32,
|
||||
pub level: u8,
|
||||
}
|
||||
|
||||
impl Flashlight {
|
||||
pub fn lvl1() -> Self {
|
||||
Self {
|
||||
radius: 0.25,
|
||||
level: 1,
|
||||
}
|
||||
}
|
||||
pub fn lvl2() -> Self {
|
||||
Self {
|
||||
radius: 0.5,
|
||||
level: 2,
|
||||
}
|
||||
}
|
||||
pub fn lvl3() -> Self {
|
||||
Self {
|
||||
radius: 1.0,
|
||||
level: 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -76,22 +88,26 @@ impl Flashlight{
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
||||
pub struct Flippers {
|
||||
pub speed_increase: f32,
|
||||
pub level: u8,
|
||||
}
|
||||
|
||||
impl Flippers {
|
||||
pub fn lvl1() -> Self {
|
||||
Self {
|
||||
speed_increase: 1.2
|
||||
speed_increase: 1.2,
|
||||
level: 1,
|
||||
}
|
||||
}
|
||||
pub fn lvl2() -> Self {
|
||||
Self {
|
||||
speed_increase: 1.5
|
||||
speed_increase: 1.5,
|
||||
level: 2,
|
||||
}
|
||||
}
|
||||
pub fn lvl3() -> Self {
|
||||
Self {
|
||||
speed_increase: 1.8
|
||||
speed_increase: 1.8,
|
||||
level: 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ impl OnScreenButton {
|
||||
self.bounds.x as i32 + 10,
|
||||
self.bounds.y as i32 + ((self.bounds.height as i32 - self.font_px) / 2),
|
||||
self.font_px,
|
||||
match is_being_hovered {
|
||||
match is_being_hovered && !self.draw_border {
|
||||
true => self.border_hover,
|
||||
false => self.border,
|
||||
},
|
||||
|
62
src/logic/shop/itemui.rs
Normal file
62
src/logic/shop/itemui.rs
Normal file
@ -0,0 +1,62 @@
|
||||
use crate::lib::utils::button::OnScreenButton;
|
||||
use raylib::prelude::*;
|
||||
|
||||
pub struct ShopItemUi {
|
||||
name: String,
|
||||
current_level: u8,
|
||||
max_level: u8,
|
||||
pub cost: u32,
|
||||
buy_button_hovered: bool,
|
||||
}
|
||||
|
||||
impl ShopItemUi {
|
||||
pub fn new(name: String, current_level: u8, max_level: u8, cost: u32) -> Self {
|
||||
Self {
|
||||
name,
|
||||
current_level,
|
||||
max_level,
|
||||
cost,
|
||||
buy_button_hovered: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(
|
||||
&self,
|
||||
draw_handle: &mut RaylibDrawHandle,
|
||||
bounds: Rectangle,
|
||||
can_be_bought: bool,
|
||||
) {
|
||||
// Render the background box
|
||||
draw_handle.draw_rectangle_rec(bounds, Color::WHITE);
|
||||
draw_handle.draw_rectangle_lines_ex(bounds, 3, Color::BLACK);
|
||||
|
||||
// Render the name
|
||||
draw_handle.draw_text(
|
||||
&format!("{}: {}/{}", self.name, self.current_level, self.max_level),
|
||||
bounds.x as i32 + 10,
|
||||
bounds.y as i32 + ((bounds.height as i32 - 20) / 2),
|
||||
20,
|
||||
Color::BLACK,
|
||||
);
|
||||
|
||||
// Render the buy button
|
||||
let buy_button = OnScreenButton::new(
|
||||
format!("Buy - {}f", self.cost),
|
||||
Rectangle {
|
||||
x: bounds.x + bounds.width - 150.0,
|
||||
y: bounds.y + 5.0,
|
||||
width: 145.0,
|
||||
height: bounds.height - 10.0,
|
||||
},
|
||||
match can_be_bought {
|
||||
true => Color::WHITE,
|
||||
false => Color::GRAY,
|
||||
},
|
||||
Color::BLACK,
|
||||
Color::GRAY,
|
||||
20,
|
||||
true,
|
||||
);
|
||||
buy_button.render(draw_handle);
|
||||
}
|
||||
}
|
71
src/logic/shop/mainui.rs
Normal file
71
src/logic/shop/mainui.rs
Normal file
@ -0,0 +1,71 @@
|
||||
use raylib::prelude::*;
|
||||
|
||||
use crate::{
|
||||
gamecore::{GameCore, GameState},
|
||||
lib::wrappers::audio::player::AudioPlayer,
|
||||
};
|
||||
|
||||
use super::itemui::ShopItemUi;
|
||||
|
||||
pub fn render_shop(
|
||||
draw_handle: &mut RaylibDrawHandle,
|
||||
_thread: &RaylibThread,
|
||||
audio_system: &mut AudioPlayer,
|
||||
game_core: &mut GameCore,
|
||||
bounds: Rectangle,
|
||||
) -> Option<GameState> {
|
||||
// Render background
|
||||
draw_handle.draw_rectangle_rec(bounds, Color::WHITE);
|
||||
draw_handle.draw_rectangle_lines_ex(bounds, 3, Color::BLACK);
|
||||
|
||||
// Title
|
||||
draw_handle.draw_text(
|
||||
"SHOP",
|
||||
bounds.x as i32 + (bounds.width / 2.0) as i32 - 50,
|
||||
bounds.y as i32 + 20,
|
||||
40,
|
||||
Color::BLACK,
|
||||
);
|
||||
|
||||
// Items
|
||||
let stun_gun_buy_ui = ShopItemUi::new(
|
||||
"Stun Gun".to_string(),
|
||||
match &game_core.player.inventory.stun_gun {
|
||||
Some(x) => x.level,
|
||||
None => 0,
|
||||
},
|
||||
3,
|
||||
10,
|
||||
);
|
||||
stun_gun_buy_ui.render(
|
||||
draw_handle,
|
||||
Rectangle {
|
||||
x: bounds.x + 5.0,
|
||||
y: bounds.y + 100.0,
|
||||
width: bounds.width - 10.0,
|
||||
height: 50.0,
|
||||
},
|
||||
game_core.player.coins >= stun_gun_buy_ui.cost,
|
||||
);
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
pub fn render_stats(
|
||||
draw_handle: &mut RaylibDrawHandle,
|
||||
game_core: &mut GameCore,
|
||||
bounds: Rectangle,
|
||||
) {
|
||||
// Render background
|
||||
draw_handle.draw_rectangle_rec(bounds, Color::WHITE);
|
||||
draw_handle.draw_rectangle_lines_ex(bounds, 3, Color::BLACK);
|
||||
|
||||
// Coins
|
||||
draw_handle.draw_text(
|
||||
&format!("Fish: {}", game_core.player.coins.min(99)),
|
||||
bounds.x as i32 + 5,
|
||||
bounds.y as i32 + 5,
|
||||
20,
|
||||
Color::BLACK,
|
||||
);
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
mod mainui;
|
||||
mod itemui;
|
||||
|
||||
use raylib::prelude::*;
|
||||
|
||||
use crate::{
|
||||
@ -5,6 +8,8 @@ use crate::{
|
||||
lib::wrappers::audio::player::AudioPlayer,
|
||||
};
|
||||
|
||||
use self::mainui::{render_shop, render_stats};
|
||||
|
||||
use super::screen::Screen;
|
||||
|
||||
const SCREEN_PANEL_SIZE: Vector2 = Vector2 { x: 300.0, y: 380.0 };
|
||||
@ -21,50 +26,6 @@ impl ShopScreen {
|
||||
}
|
||||
}
|
||||
|
||||
fn render_shop(
|
||||
&mut self,
|
||||
draw_handle: &mut RaylibDrawHandle,
|
||||
_thread: &RaylibThread,
|
||||
audio_system: &mut AudioPlayer,
|
||||
game_core: &mut GameCore,
|
||||
bounds: Rectangle,
|
||||
) -> Option<GameState> {
|
||||
// Render background
|
||||
draw_handle.draw_rectangle_rec(bounds, Color::WHITE);
|
||||
draw_handle.draw_rectangle_lines_ex(bounds, 3, Color::BLACK);
|
||||
|
||||
// Title
|
||||
draw_handle.draw_text(
|
||||
"SHOP",
|
||||
bounds.x as i32 + (bounds.width / 2.0) as i32 - 50,
|
||||
bounds.y as i32 + 20,
|
||||
40,
|
||||
Color::BLACK,
|
||||
);
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
fn render_stats(
|
||||
&mut self,
|
||||
draw_handle: &mut RaylibDrawHandle,
|
||||
game_core: &mut GameCore,
|
||||
bounds: Rectangle,
|
||||
) {
|
||||
// Render background
|
||||
draw_handle.draw_rectangle_rec(bounds, Color::WHITE);
|
||||
draw_handle.draw_rectangle_lines_ex(bounds, 3, Color::BLACK);
|
||||
|
||||
// Coins
|
||||
draw_handle.draw_text(
|
||||
&format!("Fish: {}", game_core.player.coins.min(99)),
|
||||
bounds.x as i32 + 5,
|
||||
bounds.y as i32 + 5,
|
||||
20,
|
||||
Color::BLACK,
|
||||
);
|
||||
}
|
||||
|
||||
// // Creates all the items
|
||||
// pub fn create_items(&mut self, screen_dimension: Vector2) {
|
||||
// // gets every item.. hacky
|
||||
@ -134,10 +95,10 @@ impl Screen for ShopScreen {
|
||||
|
||||
// Render the shop UI
|
||||
let next_state =
|
||||
self.render_shop(draw_handle, thread, audio_system, game_core, shop_ui_bounds);
|
||||
render_shop(draw_handle, thread, audio_system, game_core, shop_ui_bounds);
|
||||
|
||||
// Render the stats UI
|
||||
self.render_stats(draw_handle, game_core, stats_ui_bounds);
|
||||
render_stats(draw_handle, game_core, stats_ui_bounds);
|
||||
|
||||
return next_state;
|
||||
}
|
||||
|
Reference in New Issue
Block a user