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

21
Cargo.lock generated
View file

@ -1624,6 +1624,7 @@ dependencies = [
"avian3d", "avian3d",
"bevy", "bevy",
"combat", "combat",
"resources",
"state", "state",
] ]
@ -1647,6 +1648,7 @@ dependencies = [
"building", "building",
"combat", "combat",
"combat_damagers", "combat_damagers",
"resources",
"state", "state",
] ]
@ -1817,6 +1819,7 @@ dependencies = [
"avian3d", "avian3d",
"bevy", "bevy",
"physics", "physics",
"resources",
"state", "state",
] ]
@ -1984,10 +1987,12 @@ dependencies = [
"input", "input",
"level", "level",
"physics", "physics",
"resources",
"setup", "setup",
"state", "state",
"ui", "ui",
"ui_debug", "ui_debug",
"ui_ingame",
"ui_pause", "ui_pause",
"ui_state", "ui_state",
] ]
@ -2870,6 +2875,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"bevy", "bevy",
"combat", "combat",
"resources",
] ]
[[package]] [[package]]
@ -4324,6 +4330,14 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832" checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
[[package]]
name = "resources"
version = "0.1.0"
dependencies = [
"bevy",
"state",
]
[[package]] [[package]]
name = "robust" name = "robust"
version = "1.2.0" version = "1.2.0"
@ -5075,6 +5089,13 @@ dependencies = [
"state", "state",
] ]
[[package]]
name = "ui_ingame"
version = "0.1.0"
dependencies = [
"bevy",
]
[[package]] [[package]]
name = "ui_pause" name = "ui_pause"
version = "0.1.0" version = "0.1.0"

View file

@ -50,4 +50,6 @@ combat_damagers = { path = "crates/combat_damagers" }
inhabitant = { path = "crates/inhabitant" } inhabitant = { path = "crates/inhabitant" }
inhabitant_coranth = { path = "crates/inhabitant_coranth" } inhabitant_coranth = { path = "crates/inhabitant_coranth" }
building_placement = { path = "crates/building_placement" } building_placement = { path = "crates/building_placement" }
ui_ingame = { path = "crates/ui_ingame" }
resources = { path = "crates/resources" }
#new internal crates go here #new internal crates go here

View file

@ -3,15 +3,15 @@
MouseButton(Middle): [ MouseButton(Middle): [
CameraOrbitEnable, CameraOrbitEnable,
], ],
MouseButton(Right): [
PlaceTower,
],
MouseButton(Left): [ MouseButton(Left): [
CameraPanEnable, CameraPanEnable,
], ],
KeyCode(F1): [ KeyCode(F1): [
ToggleDebugUI, ToggleDebugUI,
], ],
MouseButton(Right): [
PlaceTower,
],
MouseScroll: [ MouseScroll: [
CameraZoom, CameraZoom,
], ],

View file

@ -8,6 +8,7 @@ bevy = { workspace = true }
avian3d = { workspace = true } avian3d = { workspace = true }
combat = { path = "../combat" } combat = { path = "../combat" }
state = { path = "../state" } state = { path = "../state" }
resources = { path = "../resources" }
[lints] [lints]
workspace = true workspace = true

View file

@ -9,6 +9,7 @@ use bevy::{
prelude::*, prelude::*,
}; };
use combat::{Health, Team}; use combat::{Health, Team};
use resources::{Cost, Resources};
use state::GameSystemSet; use state::GameSystemSet;
pub struct BuildingPlugin; pub struct BuildingPlugin;
@ -54,7 +55,7 @@ fn on_building_removed(mut world: DeferredWorld, context: HookContext) {
} }
#[derive(Component, Clone)] #[derive(Component, Clone)]
#[require(Name)] #[require(Name, Cost)]
#[component(on_add = register_building_info)] #[component(on_add = register_building_info)]
#[component(on_remove = unregister_building_info)] #[component(on_remove = unregister_building_info)]
#[component(immutable)] #[component(immutable)]
@ -197,14 +198,15 @@ fn place_building(
mut reader: EventReader<PlaceBuilding>, mut reader: EventReader<PlaceBuilding>,
mut building_map: ResMut<PlacedBuildings>, mut building_map: ResMut<PlacedBuildings>,
mut commands: Commands, mut commands: Commands,
info_query: Query<&BuildingInfo>, mut resources: ResMut<Resources>,
info_query: Query<(&BuildingInfo, &Cost)>,
) { ) {
for PlaceBuilding { for PlaceBuilding {
info: info_entity, info: info_entity,
location, location,
} in reader.read() } in reader.read()
{ {
let Ok(info) = info_query.get(*info_entity) else { let Ok((info, cost)) = info_query.get(*info_entity) else {
error!("tried to place building without info!"); error!("tried to place building without info!");
continue; continue;
}; };
@ -212,6 +214,10 @@ fn place_building(
error!("invalid building placement at {:?}, rejecting", location); error!("invalid building placement at {:?}, rejecting", location);
continue; continue;
} }
if !resources.buy(&cost) {
info!("not enough money to buy tower!");
continue;
}
let size_v3 = info.size.as_vec3(); let size_v3 = info.size.as_vec3();
let instance = commands let instance = commands
.spawn(( .spawn((

View file

@ -10,6 +10,7 @@ avian3d = { workspace = true }
state = { path = "../state" } state = { path = "../state" }
combat = { path = "../combat" } combat = { path = "../combat" }
building = { path = "../building" } building = { path = "../building" }
resources = { path = "../resources" }
combat_damagers = { path = "../combat_damagers" } combat_damagers = { path = "../combat_damagers" }
[lints] [lints]

View file

@ -9,6 +9,7 @@ use building::{
}; };
use combat::{Defense, Health}; use combat::{Defense, Health};
use combat_damagers::ContactDamage; use combat_damagers::ContactDamage;
use resources::Cost;
pub struct BuildingImpalerPlugin; pub struct BuildingImpalerPlugin;
@ -63,6 +64,7 @@ fn register(
preview, preview,
size: SIZE, size: SIZE,
}, },
Cost { souls: 5, bones: 0 },
Name::new("Impaler"), Name::new("Impaler"),
)); ));
commands.insert_resource(ImpalerResources { commands.insert_resource(ImpalerResources {

View file

@ -9,6 +9,7 @@ avian3d = { workspace = true }
state = { path = "../state" } state = { path = "../state" }
physics = { path = "../physics"} physics = { path = "../physics"}
resources = { path = "../resources" }
[lints] [lints]
workspace = true workspace = true

View file

@ -6,6 +6,7 @@ use std::time::Duration;
use avian3d::prelude::*; use avian3d::prelude::*;
use bevy::prelude::*; use bevy::prelude::*;
use resources::{Drops, Resources};
use state::GameSystemSet; use state::GameSystemSet;
pub struct CombatPlugin; pub struct CombatPlugin;
@ -190,7 +191,17 @@ fn on_attack(
} }
} }
fn on_die(trigger: Trigger<Died>, names: Query<&Name>, mut commands: Commands) { fn on_die(
trigger: Trigger<Died>,
names: Query<&Name>,
drops: Query<&Drops>,
mut resources: ResMut<Resources>,
mut commands: Commands,
) {
if let Ok(drop) = drops.get(trigger.target()) {
resources.souls += drop.souls;
info!("you now have {} souls", resources.souls);
}
if let Ok(mut ec) = commands.get_entity(trigger.target()) { if let Ok(mut ec) = commands.get_entity(trigger.target()) {
info!( info!(
"{:?} killed {:?}!", "{:?} killed {:?}!",

View file

@ -6,6 +6,7 @@ edition = "2024"
[dependencies] [dependencies]
bevy = { workspace = true } bevy = { workspace = true }
combat = { path = "../combat" } combat = { path = "../combat" }
resources = { path = "../resources" }
[lints] [lints]
workspace = true workspace = true

View file

@ -4,6 +4,7 @@
use bevy::prelude::*; use bevy::prelude::*;
use combat::{Health, Team}; use combat::{Health, Team};
use resources::Drops;
pub struct InhabitantPlugin; pub struct InhabitantPlugin;
@ -12,5 +13,5 @@ impl Plugin for InhabitantPlugin {
} }
#[derive(Component, Default)] #[derive(Component, Default)]
#[require(Health, Team::Inhabitant)] #[require(Health, Team::Inhabitant, Drops)]
pub struct Inhabitant; pub struct Inhabitant;

View file

@ -64,7 +64,6 @@ fn explode(
trigger_query: Query<&GlobalTransform>, trigger_query: Query<&GlobalTransform>,
mut other_query: Query<(&GlobalTransform, &mut LinearVelocity)>, mut other_query: Query<(&GlobalTransform, &mut LinearVelocity)>,
) { ) {
info!("blasthing!");
let Ok(gtf) = trigger_query.get(trigger.target()) else { let Ok(gtf) = trigger_query.get(trigger.target()) else {
return; return;
}; };
@ -78,7 +77,7 @@ fn explode(
) { ) {
if let Ok((gtf, mut v)) = other_query.get_mut(e) { if let Ok((gtf, mut v)) = other_query.get_mut(e) {
let delta = gtf.translation() - origin; let delta = gtf.translation() - origin;
v.0 += delta.normalize_or_zero() * 10.0; v.0 += delta.normalize_or_zero() * 2.0;
} }
} }
} }

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 }
}
}

View file

@ -0,0 +1,10 @@
[package]
name = "ui_ingame"
version = "0.1.0"
edition = "2024"
[dependencies]
bevy = { workspace = true }
[lints]
workspace = true

View file

@ -0,0 +1,11 @@
//bevy system signatures often violate these rules
#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]
use bevy::prelude::*;
pub struct UiIngamePlugin;
impl Plugin for UiIngamePlugin {
fn build(&self, app: &mut App) {}
}

View file

@ -4,7 +4,7 @@
use bevy::prelude::*; use bevy::prelude::*;
use input::{actions::InputAction, conditions::action_just_pressed}; use input::{actions::InputAction, conditions::action_just_pressed};
use state::{GameState, GameSystemSet}; use state::GameState;
pub struct UiPausePlugin; pub struct UiPausePlugin;
@ -12,9 +12,7 @@ impl Plugin for UiPausePlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems( app.add_systems(
Update, Update,
toggle_pause toggle_pause.run_if(action_just_pressed::<Update>(InputAction::TogglePause)),
.in_set(GameSystemSet::PreUpdate)
.run_if(action_just_pressed::<Update>(InputAction::TogglePause)),
); );
} }
} }

View file

@ -32,6 +32,8 @@ fn main() {
inhabitant::InhabitantPlugin, inhabitant::InhabitantPlugin,
inhabitant_coranth::InhabitantCoranthPlugin, inhabitant_coranth::InhabitantCoranthPlugin,
building_placement::BuildingPlacementPlugin, building_placement::BuildingPlacementPlugin,
ui_ingame::UiIngamePlugin,
resources::ResourcesPlugin,
// new internal crates go here // new internal crates go here
)); ));