add souls and bones + tower cost and enemy drops

This commit is contained in:
Jim 2025-08-30 23:39:18 -04:00
parent bc02db7b26
commit 138a524abd
Signed by: jim
GPG key ID: 3D7D94BA53088BF4
18 changed files with 151 additions and 14 deletions

View file

@ -0,0 +1,12 @@
[package]
name = "resources"
version = "0.1.0"
edition = "2024"
[dependencies]
bevy = { workspace = true }
state = { path = "../state" }
[lints]
workspace = true

View file

@ -0,0 +1,58 @@
//bevy system signatures often violate these rules
#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]
use bevy::prelude::*;
use state::AppState;
pub struct ResourcesPlugin;
impl Plugin for ResourcesPlugin {
fn build(&self, app: &mut App) {
app.add_systems(OnEnter(AppState::Game), setup);
}
}
fn setup(mut commands: Commands) {
commands.insert_resource(Resources {
souls: 10,
bones: 10,
});
}
#[derive(Resource, Default)]
pub struct Resources {
pub souls: u32,
pub bones: u32,
}
impl Resources {
pub fn can_buy(&self, cost: &Cost) -> bool {
self.souls >= cost.souls && self.bones >= cost.bones
}
pub fn buy(&mut self, cost: &Cost) -> bool {
if !self.can_buy(cost) {
return false;
}
self.souls = self.souls.saturating_sub(cost.souls);
self.bones = self.bones.saturating_sub(cost.bones);
true
}
}
#[derive(Component, Default)]
pub struct Cost {
pub souls: u32,
pub bones: u32,
}
#[derive(Component)]
pub struct Drops {
pub souls: u32,
}
impl Default for Drops {
fn default() -> Self {
Self { souls: 1 }
}
}