diff --git a/Cargo.lock b/Cargo.lock index 6421221..d86e7bc 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -3204,6 +3204,7 @@ dependencies = [ "inhabitant", "inhabitant_coranth", "physics", + "rand", "resource_graveyard", "state", ] diff --git a/assets/settings/input_map.ron b/assets/settings/input_map.ron index ed21f50..954bb8b 100755 --- a/assets/settings/input_map.ron +++ b/assets/settings/input_map.ron @@ -1,22 +1,22 @@ ( map: { + KeyCode(ShiftLeft): [ + MultiPlaceTower, + ], MouseButton(Middle): [ CameraOrbitEnable, ], + KeyCode(F1): [ + ToggleDebugUI, + ], MouseButton(Right): [ PlaceTower, ], - MouseButton(Left): [ - CameraPanEnable, - ], - KeyCode(ShiftLeft): [ - MultiPlaceTower, - ], MouseScroll: [ CameraZoom, ], - KeyCode(F1): [ - ToggleDebugUI, + MouseButton(Left): [ + CameraPanEnable, ], MouseMovementX: [ CameraYaw, diff --git a/crates/combat/src/lib.rs b/crates/combat/src/lib.rs index 5b585a3..d6edd89 100755 --- a/crates/combat/src/lib.rs +++ b/crates/combat/src/lib.rs @@ -10,7 +10,7 @@ use avian3d::prelude::*; use bevy::prelude::*; use physics::PhysicsLayers; use resources::{Drops, Resources}; -use state::GameSystemSet; +use state::{BasePhaseState, GameSystemSet}; pub struct CombatPlugin; @@ -212,6 +212,7 @@ fn on_die( trigger: Trigger, names: Query<&Name>, drops: Query<&Drops>, + phase: Res>, mut resources: ResMut, mut commands: Commands, ) { diff --git a/crates/inhabitant_coranth/src/lib.rs b/crates/inhabitant_coranth/src/lib.rs index 121a2b8..4658350 100755 --- a/crates/inhabitant_coranth/src/lib.rs +++ b/crates/inhabitant_coranth/src/lib.rs @@ -8,7 +8,7 @@ use building::Building; use combat::{GaveDamage, Health, Team}; use combat_damagers::ContactDamage; use inhabitant::Inhabitant; -use state::GameSystemSet; +use state::{BasePhaseState, GameSystemSet}; pub struct InhabitantCoranthPlugin; @@ -34,6 +34,7 @@ fn spawn( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, + phase: Res>, ) { for SpawnCoranth { transform } in reader.read() { commands @@ -50,7 +51,7 @@ fn spawn( MaxLinearSpeed(25.), Coranth, transform.clone(), - Health::new(5.0), + Health::new(1.0 + phase.get().phase_count() as f32), ContactDamage::new(5.0), Name::from("Coranth"), Team::Inhabitant.collision_layers(), @@ -70,7 +71,7 @@ fn explode( }; let origin = gtf.translation(); for e in spatial_query.shape_intersections( - &Collider::sphere(5.0), + &Collider::sphere(2.0), origin, Quat::IDENTITY, // &SpatialQueryFilter::from_mask(Team::Inhabitant), @@ -78,7 +79,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() * 2.0; + v.0 += delta.normalize_or_zero(); } } } diff --git a/crates/level/Cargo.toml b/crates/level/Cargo.toml index 9734351..247ff33 100755 --- a/crates/level/Cargo.toml +++ b/crates/level/Cargo.toml @@ -7,6 +7,7 @@ edition = "2024" bevy = { workspace = true } avian3d = { workspace = true } bevy_egui = { workspace = true } +rand = { workspace = true } state = { path = "../state" } camera = { path = "../camera" } diff --git a/crates/level/src/lib.rs b/crates/level/src/lib.rs index ded9b89..657d543 100755 --- a/crates/level/src/lib.rs +++ b/crates/level/src/lib.rs @@ -4,7 +4,7 @@ use std::time::Duration; -use avian3d::prelude::*; +use avian3d::{math::PI, prelude::*}; use bevy::{ core_pipeline::{bloom::Bloom, experimental::taa::TemporalAntiAliasing}, pbr::{Atmosphere, ScreenSpaceAmbientOcclusion, light_consts::lux}, @@ -12,10 +12,13 @@ use bevy::{ render::camera::Exposure, }; use bevy_egui::PrimaryEguiContext; +use building::Core; use camera::ControlledCamera; +use combat::Range; use inhabitant::Inhabitant; use inhabitant_coranth::SpawnCoranth; use physics::{Ground, PhysicsLayers}; +use rand::{Rng, thread_rng}; use resource_graveyard::PlaceGraveyard; use state::{AppState, BasePhaseState, GameSystemSet, Phase}; @@ -49,19 +52,19 @@ impl Plugin for LevelPlugin { #[derive(Resource, Default, Deref, DerefMut)] pub struct ExecuteTimer(pub Option); +const LEVEL_SIZE: f32 = 100.; + fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, - mut coranth_writer: EventWriter, mut graveyard_writer: EventWriter, ) { - let level_size = 50.0; // Static physics object with a collision shape commands.spawn(( RigidBody::Static, - Collider::cuboid(level_size, 1.0, level_size), - Mesh3d(meshes.add(Cuboid::new(level_size, 1.0, level_size))), + Collider::cuboid(LEVEL_SIZE, 1.0, LEVEL_SIZE), + Mesh3d(meshes.add(Cuboid::new(LEVEL_SIZE, 1.0, LEVEL_SIZE))), Transform::from_xyz(0.0, -0.5, 0.0), MeshMaterial3d(materials.add(StandardMaterial { base_color: Color::srgb_u8(52, 125, 117), @@ -74,13 +77,31 @@ fn setup( Name::new("ground"), )); - for y in 5..15 { - coranth_writer.write(SpawnCoranth { - transform: Transform::from_xyz(y as f32 * 0.25, y as f32 * 1.1, 0.0), - }); - } + let mut rng = thread_rng(); - graveyard_writer.write(PlaceGraveyard(Vec3::new(-10., 0.25, -10.))); + // place graveyards + let mut graveyards = Vec::new(); + for _ in 0..rng.gen_range(3..=5) { + for _ in 0..10 { + let bounds = LEVEL_SIZE / 2. - 3.; + let pos = Vec3::new( + rng.gen_range(-bounds..=bounds).round(), + 0.25, + rng.gen_range(-bounds..=bounds).round(), + ); + if graveyards + .iter() + .any(|loc: &Vec3| loc.distance_squared(pos) < 4.) + { + // too close + info!("too close! {:?}", pos); + continue; + } + graveyards.push(pos); + graveyard_writer.write(PlaceGraveyard(pos)); + break; + } + } // Light commands.spawn(( @@ -120,6 +141,8 @@ fn setup( fn spawn_enemies( mut writer: EventWriter, + core_query: Single<(&GlobalTransform, &Range), With>, + phase_state: Res>, time: Res