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",
"input",
"physics",
"state",
"ui_range_indicator",
]
@ -2015,6 +2016,7 @@ dependencies = [
"level",
"physics",
"resource_graveyard",
"resource_soul_spot",
"resources",
"setup",
"state",
@ -3240,6 +3242,7 @@ dependencies = [
"physics",
"rand",
"resource_graveyard",
"resource_soul_spot",
"state",
]
@ -4550,6 +4553,17 @@ dependencies = [
"state",
]
[[package]]
name = "resource_soul_spot"
version = "0.1.0"
dependencies = [
"avian3d",
"bevy",
"input",
"resources",
"state",
]
[[package]]
name = "resources"
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" }
inhabitant_simbert = { path = "crates/inhabitant_simbert" }
inhabitant_endrake = { path = "crates/inhabitant_endrake" }
resource_soul_spot = { path = "crates/resource_soul_spot" }
#new internal crates go here

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -65,9 +65,9 @@ fn spawn(
Transform::from_translation(*dest),
ResourceDeposit {
bounty: Quantity { souls: 0, bones: 5 },
level: 0,
level: 1,
harvest_time: Duration::from_secs(5),
max_workers: 2,
max_workers: 3,
},
Mesh3d(res.mesh.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
.run_if(in_state(GameUIState::Default).and(in_state(CoreState::Unplaced))),
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)),
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))),
@ -185,6 +185,7 @@ fn transition_ui(
fn side_panel(
mut contexts: EguiContexts,
core_state: Res<State<CoreState>>,
mut commands: Commands,
mut resources: ResMut<Resources>,
mut available_workers: ResMut<AvailableWorkers>,
@ -276,6 +277,13 @@ fn side_panel(
ui.label(
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
@ -327,6 +335,10 @@ fn side_panel(
return;
}
// --- 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!("Bones: {}", resources.bones)).size(LARGE_FONT_SIZE));
ui.heading(RichText::new("Buildings").underline());
@ -350,6 +362,7 @@ fn side_panel(
fn place_core(
mut contexts: EguiContexts,
mut selected_preview_writer: EventWriter<SelectBuildingPreview>,
mut selected_writer: EventWriter<SelectEntity>,
core_preview: Single<Entity, With<CorePreview>>,
) {
let ctx = contexts.ctx_mut().unwrap();
@ -363,6 +376,7 @@ fn place_core(
.button(RichText::new("COLONIZE").size(MEGA_FONT_SIZE))
.clicked()
{
selected_writer.write(SelectEntity(None));
selected_preview_writer.write(SelectBuildingPreview(Some(*core_preview)));
}
});

View file

@ -13,8 +13,8 @@ fn main() {
.add_plugins((
state::StatePlugin,
physics::PhysicsPlugin,
// ui must come before the sub crates
(
// ui must come before the sub crates
ui::UiPlugin,
ui_state::UiStatePlugin,
ui_debug::UiDebugPlugin,
@ -29,18 +29,21 @@ fn main() {
building_impaler::BuildingImpalerPlugin,
combat_damagers::CombatDamagersPlugin,
),
inhabitant::InhabitantPlugin,
inhabitant_coranth::InhabitantCoranthPlugin,
building_placement::BuildingPlacementPlugin,
ui_ingame::UiIngamePlugin,
resources::ResourcesPlugin,
building_barrager::BuildingBarragerPlugin,
resource_graveyard::ResourceGraveyardPlugin,
upgrade::UpgradePlugin,
ui_health_bar::UiHealthBarPlugin,
ui_range_indicator::UiRangeIndicatorPlugin,
inhabitant_simbert::InhabitantSimbertPlugin,
inhabitant_endrake::InhabitantEndrakePlugin,
(
inhabitant::InhabitantPlugin,
inhabitant_coranth::InhabitantCoranthPlugin,
building_placement::BuildingPlacementPlugin,
ui_ingame::UiIngamePlugin,
resources::ResourcesPlugin,
building_barrager::BuildingBarragerPlugin,
resource_graveyard::ResourceGraveyardPlugin,
upgrade::UpgradePlugin,
ui_health_bar::UiHealthBarPlugin,
ui_range_indicator::UiRangeIndicatorPlugin,
inhabitant_simbert::InhabitantSimbertPlugin,
inhabitant_endrake::InhabitantEndrakePlugin,
resource_soul_spot::ResourceSoulSpotPlugin,
),
// new internal crates go here
));

View file

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