add soul spot resource deposit and fix core placement bug

This commit is contained in:
Jim 2025-09-02 13:55:14 -04:00
parent 52da1f8acb
commit 68f4b0d8a0
Signed by: jim
GPG key ID: 3D7D94BA53088BF4
13 changed files with 171 additions and 27 deletions

14
Cargo.lock generated
View file

@ -1683,6 +1683,7 @@ dependencies = [
"combat", "combat",
"input", "input",
"physics", "physics",
"state",
"ui_range_indicator", "ui_range_indicator",
] ]
@ -2015,6 +2016,7 @@ dependencies = [
"level", "level",
"physics", "physics",
"resource_graveyard", "resource_graveyard",
"resource_soul_spot",
"resources", "resources",
"setup", "setup",
"state", "state",
@ -3240,6 +3242,7 @@ dependencies = [
"physics", "physics",
"rand", "rand",
"resource_graveyard", "resource_graveyard",
"resource_soul_spot",
"state", "state",
] ]
@ -4550,6 +4553,17 @@ dependencies = [
"state", "state",
] ]
[[package]]
name = "resource_soul_spot"
version = "0.1.0"
dependencies = [
"avian3d",
"bevy",
"input",
"resources",
"state",
]
[[package]] [[package]]
name = "resources" name = "resources"
version = "0.1.0" version = "0.1.0"

View file

@ -60,4 +60,5 @@ ui_health_bar = { path = "crates/ui_health_bar" }
ui_range_indicator = { path = "crates/ui_range_indicator" } ui_range_indicator = { path = "crates/ui_range_indicator" }
inhabitant_simbert = { path = "crates/inhabitant_simbert" } inhabitant_simbert = { path = "crates/inhabitant_simbert" }
inhabitant_endrake = { path = "crates/inhabitant_endrake" } inhabitant_endrake = { path = "crates/inhabitant_endrake" }
resource_soul_spot = { path = "crates/resource_soul_spot" }
#new internal crates go here #new internal crates go here

View file

@ -4,7 +4,7 @@
use bevy::prelude::*; use bevy::prelude::*;
use building::{BuildingInfo, BuildingPreview, PREVIEW_ALPHA, PopulatePlacedBuilding}; use building::{BuildingInfo, BuildingPreview, PREVIEW_ALPHA, PopulatePlacedBuilding};
use combat::{Defense, Health}; use combat::Health;
use combat_damagers::ContactDamage; use combat_damagers::ContactDamage;
use resources::{Cost, Quantity}; use resources::{Cost, Quantity};

View file

@ -11,6 +11,7 @@ building = { path = "../building" }
physics = { path = "../physics" } physics = { path = "../physics" }
input = { path = "../input" } input = { path = "../input" }
combat = { path = "../combat" } combat = { path = "../combat" }
state = { path = "../state" }
ui_range_indicator = { path = "../ui_range_indicator" } ui_range_indicator = { path = "../ui_range_indicator" }
[lints] [lints]

View file

@ -11,13 +11,19 @@ use building::{
use combat::Range; use combat::Range;
use input::{Cancellable, Inputs, Selected, actions::InputAction}; use input::{Cancellable, Inputs, Selected, actions::InputAction};
use physics::Ground; use physics::Ground;
use state::GameSystemSet;
use ui_range_indicator::DisplayCustomRangeIndicator; use ui_range_indicator::DisplayCustomRangeIndicator;
pub struct BuildingPlacementPlugin; pub struct BuildingPlacementPlugin;
impl Plugin for BuildingPlacementPlugin { impl Plugin for BuildingPlacementPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems(Update, (init, cancel_preview, select_preview).chain()) app.add_systems(
Update,
(init, cancel_preview, select_preview)
.in_set(GameSystemSet::Update)
.chain(),
)
.add_event::<SelectBuildingPreview>(); .add_event::<SelectBuildingPreview>();
} }
} }

View file

@ -19,6 +19,7 @@ inhabitant_coranth = { path = "../inhabitant_coranth" }
inhabitant_simbert = { path = "../inhabitant_simbert" } inhabitant_simbert = { path = "../inhabitant_simbert" }
inhabitant_endrake = { path = "../inhabitant_endrake" } inhabitant_endrake = { path = "../inhabitant_endrake" }
resource_graveyard = { path = "../resource_graveyard" } resource_graveyard = { path = "../resource_graveyard" }
resource_soul_spot = { path = "../resource_soul_spot" }
[lints] [lints]
workspace = true workspace = true

View file

@ -23,6 +23,7 @@ use inhabitant_simbert::SpawnSimbert;
use physics::{Ground, PhysicsLayers}; use physics::{Ground, PhysicsLayers};
use rand::{Rng, thread_rng}; use rand::{Rng, thread_rng};
use resource_graveyard::PlaceGraveyard; use resource_graveyard::PlaceGraveyard;
use resource_soul_spot::PlaceSoulSpot;
use state::{AppState, BasePhaseState, GameSystemSet, Phase}; use state::{AppState, BasePhaseState, GameSystemSet, Phase};
pub struct LevelPlugin; pub struct LevelPlugin;
@ -62,6 +63,7 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
mut graveyard_writer: EventWriter<PlaceGraveyard>, mut graveyard_writer: EventWriter<PlaceGraveyard>,
mut soul_spot_writer: EventWriter<PlaceSoulSpot>,
) { ) {
// Static physics object with a collision shape // Static physics object with a collision shape
commands.spawn(( commands.spawn((
@ -82,17 +84,17 @@ fn setup(
let mut rng = thread_rng(); let mut rng = thread_rng();
// place graveyards // place resources
let mut graveyards = Vec::new(); let mut resource_positions = Vec::new();
for _ in 0..rng.gen_range(3..=5) { for i in 0..rng.gen_range(4..=6) {
for _ in 0..10 { for _ in 0..10 {
let bounds = LEVEL_SIZE / 2. - 3.; let bounds = LEVEL_SIZE / 3. - 3.;
let pos = Vec3::new( let pos = Vec3::new(
rng.gen_range(-bounds..=bounds).round(), rng.gen_range(-bounds..=bounds).round(),
0.25, 0.25,
rng.gen_range(-bounds..=bounds).round(), rng.gen_range(-bounds..=bounds).round(),
); );
if graveyards if resource_positions
.iter() .iter()
.any(|loc: &Vec3| loc.distance_squared(pos) < 4.) .any(|loc: &Vec3| loc.distance_squared(pos) < 4.)
{ {
@ -100,8 +102,12 @@ fn setup(
info!("too close! {:?}", pos); info!("too close! {:?}", pos);
continue; continue;
} }
graveyards.push(pos); resource_positions.push(pos);
if i == 0 {
soul_spot_writer.write(PlaceSoulSpot(pos));
} else {
graveyard_writer.write(PlaceGraveyard(pos)); graveyard_writer.write(PlaceGraveyard(pos));
}
break; break;
} }
} }
@ -198,7 +204,7 @@ fn spawn_enemies(
2.0 + y as f32 * 0.5, 2.0 + y as f32 * 0.5,
spawn_origin.z, spawn_origin.z,
), ),
mega: clump_size > 1 && y == 0, mega: clump_size > 2 && y == 0,
}); });
// writer.write(SpawnCoranth { // writer.write(SpawnCoranth {
// transform: Transform::from_xyz( // transform: Transform::from_xyz(

View file

@ -65,9 +65,9 @@ fn spawn(
Transform::from_translation(*dest), Transform::from_translation(*dest),
ResourceDeposit { ResourceDeposit {
bounty: Quantity { souls: 0, bones: 5 }, bounty: Quantity { souls: 0, bones: 5 },
level: 0, level: 1,
harvest_time: Duration::from_secs(5), harvest_time: Duration::from_secs(5),
max_workers: 2, max_workers: 3,
}, },
Mesh3d(res.mesh.clone()), Mesh3d(res.mesh.clone()),
MeshMaterial3d(res.material.clone()), MeshMaterial3d(res.material.clone()),

View file

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

View file

@ -0,0 +1,82 @@
//bevy system signatures often violate these rules
#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]
use std::time::Duration;
use avian3d::prelude::{Collider, PhysicsPickable, RigidBody, Sensor};
use bevy::prelude::*;
use input::Selectable;
use resources::{Quantity, ResourceDeposit};
use state::GameSystemSet;
pub struct ResourceSoulSpotPlugin;
impl Plugin for ResourceSoulSpotPlugin {
fn build(&self, app: &mut App) {
app.add_event::<PlaceSoulSpot>()
.add_systems(Startup, init)
.add_systems(FixedUpdate, spawn.in_set(GameSystemSet::PostTick));
}
}
#[derive(Component)]
pub struct SoulSpot;
#[derive(Event)]
pub struct PlaceSoulSpot(pub Vec3);
#[derive(Resource)]
struct SoulSpotResources {
mesh: Handle<Mesh>,
material: Handle<StandardMaterial>,
}
const SIZE: Vec3 = Vec3::new(1.5, 0.5, 1.5);
fn init(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let mesh = meshes.add(Cuboid::from_size(SIZE));
let base_material = StandardMaterial {
base_color: Color::srgb_u8(210, 188, 166),
metallic: 0.8,
perceptual_roughness: 0.2,
..default()
};
let material = materials.add(base_material);
commands.insert_resource(SoulSpotResources {
mesh: mesh,
material: material,
});
}
fn spawn(
mut reader: EventReader<PlaceSoulSpot>,
mut commands: Commands,
res: Res<SoulSpotResources>,
) {
for PlaceSoulSpot(dest) in reader.read() {
commands.spawn((
SoulSpot,
Transform::from_translation(*dest),
ResourceDeposit {
bounty: Quantity { souls: 2, bones: 1 },
level: 1,
harvest_time: Duration::from_secs(2),
max_workers: 1,
},
Mesh3d(res.mesh.clone()),
MeshMaterial3d(res.material.clone()),
Sensor,
RigidBody::Static,
Collider::cuboid(SIZE.x, SIZE.y, SIZE.z),
PhysicsPickable,
Selectable,
Name::new("Soul Spot"),
));
}
}

View file

@ -33,7 +33,7 @@ impl Plugin for UiIngamePlugin {
place_core place_core
.run_if(in_state(GameUIState::Default).and(in_state(CoreState::Unplaced))), .run_if(in_state(GameUIState::Default).and(in_state(CoreState::Unplaced))),
side_panel side_panel
.run_if(in_state(GameUIState::Default).and(in_state(CoreState::Placed))), .run_if(in_state(GameUIState::Default).and(not(in_state(CoreState::Dead)))),
game_over.run_if(in_state(GameState::GameOver)), game_over.run_if(in_state(GameState::GameOver)),
plan_ui.run_if(in_state(GameUIState::Default).and(in_state(Phase::Plan))), plan_ui.run_if(in_state(GameUIState::Default).and(in_state(Phase::Plan))),
execute_ui.run_if(in_state(GameUIState::Default).and(in_state(Phase::Execute))), execute_ui.run_if(in_state(GameUIState::Default).and(in_state(Phase::Execute))),
@ -185,6 +185,7 @@ fn transition_ui(
fn side_panel( fn side_panel(
mut contexts: EguiContexts, mut contexts: EguiContexts,
core_state: Res<State<CoreState>>,
mut commands: Commands, mut commands: Commands,
mut resources: ResMut<Resources>, mut resources: ResMut<Resources>,
mut available_workers: ResMut<AvailableWorkers>, mut available_workers: ResMut<AvailableWorkers>,
@ -276,6 +277,13 @@ fn side_panel(
ui.label( ui.label(
RichText::new(format!("Bones: {}", deposit.bounty.bones)).size(FONT_SIZE), RichText::new(format!("Bones: {}", deposit.bounty.bones)).size(FONT_SIZE),
); );
ui.label(
RichText::new(format!(
"Produces every {:.1} seconds.",
deposit.harvest_time.as_secs_f32()
))
.size(FONT_SIZE),
);
} }
//upgrades //upgrades
@ -327,6 +335,10 @@ fn side_panel(
return; return;
} }
// --- view when nothing's selected --- // --- view when nothing's selected ---
if *core_state.get() == CoreState::Unplaced {
// don't allow placing tower's while core is not placed
return;
}
ui.label(RichText::new(format!("Souls: {}", resources.souls)).size(LARGE_FONT_SIZE)); ui.label(RichText::new(format!("Souls: {}", resources.souls)).size(LARGE_FONT_SIZE));
ui.label(RichText::new(format!("Bones: {}", resources.bones)).size(LARGE_FONT_SIZE)); ui.label(RichText::new(format!("Bones: {}", resources.bones)).size(LARGE_FONT_SIZE));
ui.heading(RichText::new("Buildings").underline()); ui.heading(RichText::new("Buildings").underline());
@ -350,6 +362,7 @@ fn side_panel(
fn place_core( fn place_core(
mut contexts: EguiContexts, mut contexts: EguiContexts,
mut selected_preview_writer: EventWriter<SelectBuildingPreview>, mut selected_preview_writer: EventWriter<SelectBuildingPreview>,
mut selected_writer: EventWriter<SelectEntity>,
core_preview: Single<Entity, With<CorePreview>>, core_preview: Single<Entity, With<CorePreview>>,
) { ) {
let ctx = contexts.ctx_mut().unwrap(); let ctx = contexts.ctx_mut().unwrap();
@ -363,6 +376,7 @@ fn place_core(
.button(RichText::new("COLONIZE").size(MEGA_FONT_SIZE)) .button(RichText::new("COLONIZE").size(MEGA_FONT_SIZE))
.clicked() .clicked()
{ {
selected_writer.write(SelectEntity(None));
selected_preview_writer.write(SelectBuildingPreview(Some(*core_preview))); selected_preview_writer.write(SelectBuildingPreview(Some(*core_preview)));
} }
}); });

View file

@ -13,8 +13,8 @@ fn main() {
.add_plugins(( .add_plugins((
state::StatePlugin, state::StatePlugin,
physics::PhysicsPlugin, physics::PhysicsPlugin,
// ui must come before the sub crates
( (
// ui must come before the sub crates
ui::UiPlugin, ui::UiPlugin,
ui_state::UiStatePlugin, ui_state::UiStatePlugin,
ui_debug::UiDebugPlugin, ui_debug::UiDebugPlugin,
@ -29,6 +29,7 @@ fn main() {
building_impaler::BuildingImpalerPlugin, building_impaler::BuildingImpalerPlugin,
combat_damagers::CombatDamagersPlugin, combat_damagers::CombatDamagersPlugin,
), ),
(
inhabitant::InhabitantPlugin, inhabitant::InhabitantPlugin,
inhabitant_coranth::InhabitantCoranthPlugin, inhabitant_coranth::InhabitantCoranthPlugin,
building_placement::BuildingPlacementPlugin, building_placement::BuildingPlacementPlugin,
@ -41,6 +42,8 @@ fn main() {
ui_range_indicator::UiRangeIndicatorPlugin, ui_range_indicator::UiRangeIndicatorPlugin,
inhabitant_simbert::InhabitantSimbertPlugin, inhabitant_simbert::InhabitantSimbertPlugin,
inhabitant_endrake::InhabitantEndrakePlugin, inhabitant_endrake::InhabitantEndrakePlugin,
resource_soul_spot::ResourceSoulSpotPlugin,
),
// new internal crates go here // new internal crates go here
)); ));

View file

@ -12,6 +12,7 @@ x improve enemy AI
- More upgrades - More upgrades
x More enemy types x More enemy types
- More resource deposit types - More resource deposit types
- Improve wave generation
--- STILL PRETTY IMPORTANT --- --- STILL PRETTY IMPORTANT ---
- Building repair - Building repair