70 lines
1.6 KiB
Rust
70 lines
1.6 KiB
Rust
|
|
use std::fmt::Display;
|
||
|
|
|
||
|
|
use bevy::prelude::Component;
|
||
|
|
|
||
|
|
#[derive(Debug, PartialEq)]
|
||
|
|
pub enum PurchasableObject {
|
||
|
|
Cookie,
|
||
|
|
Cursor,
|
||
|
|
Grandma,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Component, Debug)]
|
||
|
|
pub struct Purchased {
|
||
|
|
pub object: PurchasableObject,
|
||
|
|
pub count: u32,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Display for PurchasableObject {
|
||
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||
|
|
write!(
|
||
|
|
f,
|
||
|
|
"{}",
|
||
|
|
match self {
|
||
|
|
PurchasableObject::Cookie => "Cookie",
|
||
|
|
PurchasableObject::Cursor => "Cursor",
|
||
|
|
PurchasableObject::Grandma => "Grandma",
|
||
|
|
}
|
||
|
|
)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Component, Debug)]
|
||
|
|
pub struct PlayerStats {
|
||
|
|
pub money: f64,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl PlayerStats {
|
||
|
|
pub fn new() -> PlayerStats {
|
||
|
|
return PlayerStats { money: 10.0 };
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn get_current_price(object: &PurchasableObject, num_owned: &u32) -> f64 {
|
||
|
|
get_base_price(object) * get_scaling_factor(object) * f64::from(*num_owned)
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn get_base_price(object: &PurchasableObject) -> f64 {
|
||
|
|
match object {
|
||
|
|
PurchasableObject::Cookie => 10.0,
|
||
|
|
PurchasableObject::Cursor => 100.0,
|
||
|
|
PurchasableObject::Grandma => 1000.0,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn get_scaling_factor(object: &PurchasableObject) -> f64 {
|
||
|
|
match object {
|
||
|
|
PurchasableObject::Cookie => 1.10,
|
||
|
|
PurchasableObject::Cursor => 1.15,
|
||
|
|
PurchasableObject::Grandma => 1.20,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn get_base_returns(object: &PurchasableObject) -> f64 {
|
||
|
|
match object {
|
||
|
|
PurchasableObject::Cookie => 1.0,
|
||
|
|
PurchasableObject::Cursor => 2.0,
|
||
|
|
PurchasableObject::Grandma => 5.0,
|
||
|
|
}
|
||
|
|
}
|