add souls and bones + tower cost and enemy drops
This commit is contained in:
parent
bc02db7b26
commit
138a524abd
18 changed files with 151 additions and 14 deletions
21
Cargo.lock
generated
21
Cargo.lock
generated
|
|
@ -1624,6 +1624,7 @@ dependencies = [
|
|||
"avian3d",
|
||||
"bevy",
|
||||
"combat",
|
||||
"resources",
|
||||
"state",
|
||||
]
|
||||
|
||||
|
|
@ -1647,6 +1648,7 @@ dependencies = [
|
|||
"building",
|
||||
"combat",
|
||||
"combat_damagers",
|
||||
"resources",
|
||||
"state",
|
||||
]
|
||||
|
||||
|
|
@ -1817,6 +1819,7 @@ dependencies = [
|
|||
"avian3d",
|
||||
"bevy",
|
||||
"physics",
|
||||
"resources",
|
||||
"state",
|
||||
]
|
||||
|
||||
|
|
@ -1984,10 +1987,12 @@ dependencies = [
|
|||
"input",
|
||||
"level",
|
||||
"physics",
|
||||
"resources",
|
||||
"setup",
|
||||
"state",
|
||||
"ui",
|
||||
"ui_debug",
|
||||
"ui_ingame",
|
||||
"ui_pause",
|
||||
"ui_state",
|
||||
]
|
||||
|
|
@ -2870,6 +2875,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"bevy",
|
||||
"combat",
|
||||
"resources",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -4324,6 +4330,14 @@ version = "1.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
|
||||
|
||||
[[package]]
|
||||
name = "resources"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"state",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "robust"
|
||||
version = "1.2.0"
|
||||
|
|
@ -5075,6 +5089,13 @@ dependencies = [
|
|||
"state",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ui_ingame"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ui_pause"
|
||||
version = "0.1.0"
|
||||
|
|
|
|||
|
|
@ -50,4 +50,6 @@ combat_damagers = { path = "crates/combat_damagers" }
|
|||
inhabitant = { path = "crates/inhabitant" }
|
||||
inhabitant_coranth = { path = "crates/inhabitant_coranth" }
|
||||
building_placement = { path = "crates/building_placement" }
|
||||
ui_ingame = { path = "crates/ui_ingame" }
|
||||
resources = { path = "crates/resources" }
|
||||
#new internal crates go here
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@
|
|||
MouseButton(Middle): [
|
||||
CameraOrbitEnable,
|
||||
],
|
||||
MouseButton(Right): [
|
||||
PlaceTower,
|
||||
],
|
||||
MouseButton(Left): [
|
||||
CameraPanEnable,
|
||||
],
|
||||
KeyCode(F1): [
|
||||
ToggleDebugUI,
|
||||
],
|
||||
MouseButton(Right): [
|
||||
PlaceTower,
|
||||
],
|
||||
MouseScroll: [
|
||||
CameraZoom,
|
||||
],
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ bevy = { workspace = true }
|
|||
avian3d = { workspace = true }
|
||||
combat = { path = "../combat" }
|
||||
state = { path = "../state" }
|
||||
resources = { path = "../resources" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use bevy::{
|
|||
prelude::*,
|
||||
};
|
||||
use combat::{Health, Team};
|
||||
use resources::{Cost, Resources};
|
||||
use state::GameSystemSet;
|
||||
|
||||
pub struct BuildingPlugin;
|
||||
|
|
@ -54,7 +55,7 @@ fn on_building_removed(mut world: DeferredWorld, context: HookContext) {
|
|||
}
|
||||
|
||||
#[derive(Component, Clone)]
|
||||
#[require(Name)]
|
||||
#[require(Name, Cost)]
|
||||
#[component(on_add = register_building_info)]
|
||||
#[component(on_remove = unregister_building_info)]
|
||||
#[component(immutable)]
|
||||
|
|
@ -197,14 +198,15 @@ fn place_building(
|
|||
mut reader: EventReader<PlaceBuilding>,
|
||||
mut building_map: ResMut<PlacedBuildings>,
|
||||
mut commands: Commands,
|
||||
info_query: Query<&BuildingInfo>,
|
||||
mut resources: ResMut<Resources>,
|
||||
info_query: Query<(&BuildingInfo, &Cost)>,
|
||||
) {
|
||||
for PlaceBuilding {
|
||||
info: info_entity,
|
||||
location,
|
||||
} 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!");
|
||||
continue;
|
||||
};
|
||||
|
|
@ -212,6 +214,10 @@ fn place_building(
|
|||
error!("invalid building placement at {:?}, rejecting", location);
|
||||
continue;
|
||||
}
|
||||
if !resources.buy(&cost) {
|
||||
info!("not enough money to buy tower!");
|
||||
continue;
|
||||
}
|
||||
let size_v3 = info.size.as_vec3();
|
||||
let instance = commands
|
||||
.spawn((
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ avian3d = { workspace = true }
|
|||
state = { path = "../state" }
|
||||
combat = { path = "../combat" }
|
||||
building = { path = "../building" }
|
||||
resources = { path = "../resources" }
|
||||
combat_damagers = { path = "../combat_damagers" }
|
||||
|
||||
[lints]
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use building::{
|
|||
};
|
||||
use combat::{Defense, Health};
|
||||
use combat_damagers::ContactDamage;
|
||||
use resources::Cost;
|
||||
|
||||
pub struct BuildingImpalerPlugin;
|
||||
|
||||
|
|
@ -63,6 +64,7 @@ fn register(
|
|||
preview,
|
||||
size: SIZE,
|
||||
},
|
||||
Cost { souls: 5, bones: 0 },
|
||||
Name::new("Impaler"),
|
||||
));
|
||||
commands.insert_resource(ImpalerResources {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ avian3d = { workspace = true }
|
|||
|
||||
state = { path = "../state" }
|
||||
physics = { path = "../physics"}
|
||||
resources = { path = "../resources" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use std::time::Duration;
|
|||
|
||||
use avian3d::prelude::*;
|
||||
use bevy::prelude::*;
|
||||
use resources::{Drops, Resources};
|
||||
use state::GameSystemSet;
|
||||
|
||||
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()) {
|
||||
info!(
|
||||
"{:?} killed {:?}!",
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ edition = "2024"
|
|||
[dependencies]
|
||||
bevy = { workspace = true }
|
||||
combat = { path = "../combat" }
|
||||
resources = { path = "../resources" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use bevy::prelude::*;
|
||||
use combat::{Health, Team};
|
||||
use resources::Drops;
|
||||
|
||||
pub struct InhabitantPlugin;
|
||||
|
||||
|
|
@ -12,5 +13,5 @@ impl Plugin for InhabitantPlugin {
|
|||
}
|
||||
|
||||
#[derive(Component, Default)]
|
||||
#[require(Health, Team::Inhabitant)]
|
||||
#[require(Health, Team::Inhabitant, Drops)]
|
||||
pub struct Inhabitant;
|
||||
|
|
|
|||
|
|
@ -64,7 +64,6 @@ fn explode(
|
|||
trigger_query: Query<&GlobalTransform>,
|
||||
mut other_query: Query<(&GlobalTransform, &mut LinearVelocity)>,
|
||||
) {
|
||||
info!("blasthing!");
|
||||
let Ok(gtf) = trigger_query.get(trigger.target()) else {
|
||||
return;
|
||||
};
|
||||
|
|
@ -78,7 +77,7 @@ fn explode(
|
|||
) {
|
||||
if let Ok((gtf, mut v)) = other_query.get_mut(e) {
|
||||
let delta = gtf.translation() - origin;
|
||||
v.0 += delta.normalize_or_zero() * 10.0;
|
||||
v.0 += delta.normalize_or_zero() * 2.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
crates/resources/Cargo.toml
Normal file
12
crates/resources/Cargo.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "resources"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bevy = { workspace = true }
|
||||
|
||||
state = { path = "../state" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
58
crates/resources/src/lib.rs
Normal file
58
crates/resources/src/lib.rs
Normal 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 }
|
||||
}
|
||||
}
|
||||
10
crates/ui_ingame/Cargo.toml
Normal file
10
crates/ui_ingame/Cargo.toml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "ui_ingame"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bevy = { workspace = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
11
crates/ui_ingame/src/lib.rs
Normal file
11
crates/ui_ingame/src/lib.rs
Normal 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) {}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use bevy::prelude::*;
|
||||
use input::{actions::InputAction, conditions::action_just_pressed};
|
||||
use state::{GameState, GameSystemSet};
|
||||
use state::GameState;
|
||||
|
||||
pub struct UiPausePlugin;
|
||||
|
||||
|
|
@ -12,9 +12,7 @@ impl Plugin for UiPausePlugin {
|
|||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(
|
||||
Update,
|
||||
toggle_pause
|
||||
.in_set(GameSystemSet::PreUpdate)
|
||||
.run_if(action_just_pressed::<Update>(InputAction::TogglePause)),
|
||||
toggle_pause.run_if(action_just_pressed::<Update>(InputAction::TogglePause)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ fn main() {
|
|||
inhabitant::InhabitantPlugin,
|
||||
inhabitant_coranth::InhabitantCoranthPlugin,
|
||||
building_placement::BuildingPlacementPlugin,
|
||||
ui_ingame::UiIngamePlugin,
|
||||
resources::ResourcesPlugin,
|
||||
// new internal crates go here
|
||||
));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue