idler/src/components.rs

70 lines
1.6 KiB
Rust
Raw Normal View History

2024-11-18 15:42:43 -05:00
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 {
2024-11-21 12:12:05 -05:00
get_base_price(object) * (1.0 + get_scaling_factor(object) * f64::from(*num_owned))
2024-11-18 15:42:43 -05:00
}
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 {
2024-11-21 12:12:05 -05:00
PurchasableObject::Cookie => 0.10,
PurchasableObject::Cursor => 0.15,
PurchasableObject::Grandma => 0.20,
2024-11-18 15:42:43 -05:00
}
}
pub fn get_base_returns(object: &PurchasableObject) -> f64 {
match object {
PurchasableObject::Cookie => 1.0,
PurchasableObject::Cursor => 2.0,
PurchasableObject::Grandma => 5.0,
}
}