diff --git a/Cargo.lock b/Cargo.lock index 54a0a14..1aef5fa 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index f437731..2d871bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/crates/building_impaler/src/lib.rs b/crates/building_impaler/src/lib.rs index 6a52791..9b70611 100755 --- a/crates/building_impaler/src/lib.rs +++ b/crates/building_impaler/src/lib.rs @@ -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}; diff --git a/crates/building_placement/Cargo.toml b/crates/building_placement/Cargo.toml index 4f90c75..6b27572 100644 --- a/crates/building_placement/Cargo.toml +++ b/crates/building_placement/Cargo.toml @@ -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] diff --git a/crates/building_placement/src/lib.rs b/crates/building_placement/src/lib.rs index 416dbd0..4cd90a5 100644 --- a/crates/building_placement/src/lib.rs +++ b/crates/building_placement/src/lib.rs @@ -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::(); + app.add_systems( + Update, + (init, cancel_preview, select_preview) + .in_set(GameSystemSet::Update) + .chain(), + ) + .add_event::(); } } diff --git a/crates/level/Cargo.toml b/crates/level/Cargo.toml index d2c93e7..be7764b 100755 --- a/crates/level/Cargo.toml +++ b/crates/level/Cargo.toml @@ -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 diff --git a/crates/level/src/lib.rs b/crates/level/src/lib.rs index 64e0ad4..2c31519 100755 --- a/crates/level/src/lib.rs +++ b/crates/level/src/lib.rs @@ -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>, mut materials: ResMut>, mut graveyard_writer: EventWriter, + mut soul_spot_writer: EventWriter, ) { // 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( diff --git a/crates/resource_graveyard/src/lib.rs b/crates/resource_graveyard/src/lib.rs index ecb989a..624cc95 100644 --- a/crates/resource_graveyard/src/lib.rs +++ b/crates/resource_graveyard/src/lib.rs @@ -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()), diff --git a/crates/resource_soul_spot/Cargo.toml b/crates/resource_soul_spot/Cargo.toml new file mode 100644 index 0000000..87cdb3e --- /dev/null +++ b/crates/resource_soul_spot/Cargo.toml @@ -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 diff --git a/crates/resource_soul_spot/src/lib.rs b/crates/resource_soul_spot/src/lib.rs new file mode 100644 index 0000000..6b22ea3 --- /dev/null +++ b/crates/resource_soul_spot/src/lib.rs @@ -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::() + .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, + material: Handle, +} + +const SIZE: Vec3 = Vec3::new(1.5, 0.5, 1.5); + +fn init( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, +) { + 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, + mut commands: Commands, + res: Res, +) { + 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"), + )); + } +} diff --git a/crates/ui_ingame/src/lib.rs b/crates/ui_ingame/src/lib.rs index c344cf1..5735211 100644 --- a/crates/ui_ingame/src/lib.rs +++ b/crates/ui_ingame/src/lib.rs @@ -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>, mut commands: Commands, mut resources: ResMut, mut available_workers: ResMut, @@ -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, + mut selected_writer: EventWriter, core_preview: Single>, ) { 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))); } }); diff --git a/src/main.rs b/src/main.rs index 0fe23c6..69061a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 )); diff --git a/todo.txt b/todo.txt index 7c0fbb6..572f5b6 100644 --- a/todo.txt +++ b/todo.txt @@ -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