minor balance tweaks
This commit is contained in:
parent
e9379a6a94
commit
283b86d04a
7 changed files with 99 additions and 31 deletions
|
|
@ -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<Timer>);
|
||||
|
||||
const LEVEL_SIZE: f32 = 100.;
|
||||
|
||||
fn setup(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
mut coranth_writer: EventWriter<SpawnCoranth>,
|
||||
mut graveyard_writer: EventWriter<PlaceGraveyard>,
|
||||
) {
|
||||
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<SpawnCoranth>,
|
||||
core_query: Single<(&GlobalTransform, &Range), With<Core>>,
|
||||
phase_state: Res<State<BasePhaseState>>,
|
||||
time: Res<Time>,
|
||||
mut setup: Local<bool>,
|
||||
mut timer: Local<Timer>,
|
||||
|
|
@ -128,18 +151,58 @@ fn spawn_enemies(
|
|||
*timer = Timer::new(Duration::from_secs(1), TimerMode::Repeating);
|
||||
*setup = true;
|
||||
}
|
||||
let phase = phase_state.get().phase_count();
|
||||
let clumps = 2 + (phase / 2).min(5);
|
||||
let clump_size = 1 + phase / 3;
|
||||
timer.tick(time.delta());
|
||||
if timer.just_finished() {
|
||||
for _ in 0..3 {
|
||||
writer.write(SpawnCoranth {
|
||||
transform: Transform::from_xyz(0.0, 2.0, 0.0),
|
||||
});
|
||||
let (core_gtf, core_range) = core_query.into_inner();
|
||||
let level_rect = Rect::new(
|
||||
-LEVEL_SIZE / 2.,
|
||||
-LEVEL_SIZE / 2.,
|
||||
LEVEL_SIZE / 2.,
|
||||
LEVEL_SIZE / 2.,
|
||||
);
|
||||
info!("rect: {:?}", level_rect);
|
||||
let safe_axes = [Vec3::X, Vec3::NEG_X, Vec3::Z, Vec3::NEG_Z]
|
||||
.iter()
|
||||
.copied()
|
||||
.map(|v| core_gtf.translation() + core_range.0 * v)
|
||||
.filter(|v| level_rect.contains(Vec2::new(v.x, v.z)))
|
||||
.collect::<Vec<_>>();
|
||||
let mut rng = thread_rng();
|
||||
let clump_angles = std::iter::repeat_with(|| rng.gen_range(-PI..=PI))
|
||||
.take(clumps as usize)
|
||||
.collect::<Vec<_>>();
|
||||
for angle in clump_angles.iter() {
|
||||
let mut spawn_origin = core_gtf.translation()
|
||||
+ core_range.0 * Quat::from_rotation_y(*angle).mul_vec3(Vec3::Z);
|
||||
if !level_rect.contains(Vec2::new(spawn_origin.x, spawn_origin.z)) {
|
||||
if !safe_axes.is_empty() {
|
||||
spawn_origin = safe_axes[rng.gen_range(0..safe_axes.len())];
|
||||
} else {
|
||||
// give up and spawn at 0,0, core range is too big
|
||||
spawn_origin = Vec3::ZERO;
|
||||
}
|
||||
}
|
||||
for y in 0..clump_size {
|
||||
writer.write(SpawnCoranth {
|
||||
transform: Transform::from_xyz(
|
||||
spawn_origin.x,
|
||||
2.0 + y as f32 * 0.5,
|
||||
spawn_origin.z,
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn on_execute(mut timer: ResMut<ExecuteTimer>) {
|
||||
timer.0 = Some(Timer::from_seconds(5., TimerMode::Once));
|
||||
fn on_execute(mut timer: ResMut<ExecuteTimer>, curr_phase: Res<State<BasePhaseState>>) {
|
||||
timer.0 = Some(Timer::from_seconds(
|
||||
(5. + 2. * curr_phase.get().phase_count() as f32).min(60.),
|
||||
TimerMode::Once,
|
||||
));
|
||||
}
|
||||
|
||||
fn tick_execute_timer(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue