Compare commits
3 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
5ab49b9610 | |
|
|
d0a788ae59 | |
|
|
e130f91f39 |
|
|
@ -2235,9 +2235,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.162"
|
||||
version = "0.2.164"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398"
|
||||
checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f"
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
|
|
@ -3139,9 +3139,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
|||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.40"
|
||||
version = "0.38.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0"
|
||||
checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"errno",
|
||||
|
|
@ -3208,9 +3208,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.132"
|
||||
version = "1.0.133"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03"
|
||||
checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
|
|
|
|||
|
|
@ -2,14 +2,22 @@ use std::fmt::Display;
|
|||
|
||||
use bevy::prelude::Component;
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct Purchased(pub u32);
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum PurchasableObject {
|
||||
Cookie,
|
||||
Cursor,
|
||||
Grandma,
|
||||
Farm,
|
||||
Mine,
|
||||
Factory,
|
||||
Bank,
|
||||
Temple,
|
||||
WizardTower,
|
||||
}
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct Purchased {
|
||||
pub object: PurchasableObject,
|
||||
pub count: u32,
|
||||
}
|
||||
|
||||
impl Display for PurchasableObject {
|
||||
|
|
@ -18,9 +26,14 @@ impl Display for PurchasableObject {
|
|||
f,
|
||||
"{}",
|
||||
match self {
|
||||
PurchasableObject::Cookie => "Cookie",
|
||||
PurchasableObject::Cursor => "Cursor",
|
||||
PurchasableObject::Grandma => "Grandma",
|
||||
PurchasableObject::Farm => "Farm",
|
||||
PurchasableObject::Mine => "Mine",
|
||||
PurchasableObject::Factory => "Factory",
|
||||
PurchasableObject::Bank => "Bank",
|
||||
PurchasableObject::Temple => "Temple",
|
||||
PurchasableObject::WizardTower => "Wizard Tower",
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
@ -28,39 +41,47 @@ impl Display for PurchasableObject {
|
|||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct PlayerStats {
|
||||
pub money: f64,
|
||||
pub cookies: f64,
|
||||
}
|
||||
|
||||
impl PlayerStats {
|
||||
pub fn new() -> PlayerStats {
|
||||
return PlayerStats { money: 10.0 };
|
||||
return PlayerStats { cookies: 0.0 };
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_current_price(object: &PurchasableObject, num_owned: &u32) -> f64 {
|
||||
get_base_price(object) * get_scaling_factor(object) * f64::from(*num_owned)
|
||||
get_base_price(object) * (1.0 + get_price_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,
|
||||
_ => unimplemented!(),
|
||||
PurchasableObject::Cursor => 15.0,
|
||||
PurchasableObject::Grandma => 100.0,
|
||||
PurchasableObject::Farm => 1_100.0,
|
||||
PurchasableObject::Mine => 21_000.0,
|
||||
PurchasableObject::Factory => 130_000.0,
|
||||
PurchasableObject::Bank => 1_400_000.0,
|
||||
PurchasableObject::Temple => 20_000_000.0,
|
||||
PurchasableObject::WizardTower => 330_000_000.0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_scaling_factor(object: &PurchasableObject) -> f64 {
|
||||
pub fn get_price_scaling_factor(object: &PurchasableObject) -> f64 {
|
||||
match object {
|
||||
PurchasableObject::Cookie => 1.10,
|
||||
PurchasableObject::Cursor => 1.15,
|
||||
_ => unimplemented!(),
|
||||
_ => 0.15,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_base_returns(object: &PurchasableObject) -> f64 {
|
||||
match object {
|
||||
PurchasableObject::Cookie => 1.,
|
||||
PurchasableObject::Cursor => 2.,
|
||||
_ => unimplemented!(),
|
||||
PurchasableObject::Cursor => 0.1,
|
||||
PurchasableObject::Grandma => 1.0,
|
||||
PurchasableObject::Farm => 8.0,
|
||||
PurchasableObject::Mine => 47.0,
|
||||
PurchasableObject::Factory => 260.0,
|
||||
PurchasableObject::Bank => 1_400.0,
|
||||
PurchasableObject::Temple => 7_800.0,
|
||||
PurchasableObject::WizardTower => 44_000.0,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
60
src/main.rs
60
src/main.rs
|
|
@ -4,6 +4,12 @@ use bevy::app::{App, FixedUpdate};
|
|||
use bevy::prelude::*;
|
||||
use components::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
enum InputAction {
|
||||
TapCookie,
|
||||
Purchase(PurchasableObject),
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
|
|
@ -16,21 +22,21 @@ fn setup(mut commands: Commands) {
|
|||
commands.spawn(PlayerStats::new());
|
||||
}
|
||||
|
||||
fn get_cash(inv: Query<(&PurchasableObject, &Purchased)>, mut stats: Query<&mut PlayerStats>) {
|
||||
fn get_cash(time: Res<Time>, inv: Query<&Purchased>, mut stats: Query<&mut PlayerStats>) {
|
||||
let mut new_cash: f64 = 0.;
|
||||
|
||||
for (item, Purchased(count)) in &inv {
|
||||
new_cash += get_base_returns(item) * f64::from(*count);
|
||||
for Purchased { object, count } in &inv {
|
||||
new_cash += get_base_returns(&object) * f64::from(*count) * f64::from(time.delta_seconds());
|
||||
}
|
||||
|
||||
stats.single_mut().money += new_cash;
|
||||
stats.single_mut().cookies += new_cash;
|
||||
}
|
||||
|
||||
fn display(inv: Query<(&PurchasableObject, &Purchased)>, stats: Query<&PlayerStats>) {
|
||||
println!("money: {}", stats.single().money);
|
||||
fn display(inv: Query<&Purchased>, stats: Query<&PlayerStats>) {
|
||||
println!("money: {}", stats.single().cookies);
|
||||
println!("items:");
|
||||
for (item, Purchased(count)) in &inv {
|
||||
println!("\t{}: {}", item, count);
|
||||
for Purchased { object, count } in &inv {
|
||||
println!("\t{}: {}", object, count);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -40,16 +46,40 @@ fn handle_input(
|
|||
mut pur_items: Query<&mut Purchased>,
|
||||
mut stats: Query<&mut PlayerStats>,
|
||||
) {
|
||||
let items = keys
|
||||
.get_just_pressed()
|
||||
keys.get_just_pressed()
|
||||
.filter_map(|key| match key {
|
||||
KeyCode::KeyP => Some(PurchasableObject::Cookie),
|
||||
KeyCode::KeyC => Some(PurchasableObject::Cursor),
|
||||
KeyCode::KeyG => Some(PurchasableObject::Grandma),
|
||||
KeyCode::Space => Some(InputAction::TapCookie),
|
||||
KeyCode::KeyC => Some(InputAction::Purchase(PurchasableObject::Cursor)),
|
||||
KeyCode::KeyG => Some(InputAction::Purchase(PurchasableObject::Grandma)),
|
||||
_ => None,
|
||||
})
|
||||
.for_each(|item| {
|
||||
.for_each(|action| {
|
||||
let mut player_stats = stats.get_single_mut().unwrap();
|
||||
let cur_count = pur_items.get_mut(item);
|
||||
let item = if let InputAction::Purchase(item) = action {
|
||||
item
|
||||
} else {
|
||||
player_stats.cookies += 1.0;
|
||||
return;
|
||||
};
|
||||
|
||||
for mut object in &mut pur_items {
|
||||
if object.object == item {
|
||||
let price = get_current_price(&item, &object.count);
|
||||
if price <= player_stats.cookies {
|
||||
object.count += 1;
|
||||
player_stats.cookies -= price;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if get_base_price(&item) <= player_stats.cookies {
|
||||
println!("{}, {}", get_base_price(&item), player_stats.cookies);
|
||||
player_stats.cookies -= get_base_price(&item);
|
||||
commands.spawn(Purchased {
|
||||
object: item,
|
||||
count: 1,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue