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