minor balance tweaks

This commit is contained in:
Jim 2025-09-01 23:21:49 -04:00
parent e9379a6a94
commit 283b86d04a
Signed by: jim
GPG key ID: 3D7D94BA53088BF4
7 changed files with 99 additions and 31 deletions

1
Cargo.lock generated
View file

@ -3204,6 +3204,7 @@ dependencies = [
"inhabitant", "inhabitant",
"inhabitant_coranth", "inhabitant_coranth",
"physics", "physics",
"rand",
"resource_graveyard", "resource_graveyard",
"state", "state",
] ]

View file

@ -1,22 +1,22 @@
( (
map: { map: {
KeyCode(ShiftLeft): [
MultiPlaceTower,
],
MouseButton(Middle): [ MouseButton(Middle): [
CameraOrbitEnable, CameraOrbitEnable,
], ],
KeyCode(F1): [
ToggleDebugUI,
],
MouseButton(Right): [ MouseButton(Right): [
PlaceTower, PlaceTower,
], ],
MouseButton(Left): [
CameraPanEnable,
],
KeyCode(ShiftLeft): [
MultiPlaceTower,
],
MouseScroll: [ MouseScroll: [
CameraZoom, CameraZoom,
], ],
KeyCode(F1): [ MouseButton(Left): [
ToggleDebugUI, CameraPanEnable,
], ],
MouseMovementX: [ MouseMovementX: [
CameraYaw, CameraYaw,

View file

@ -10,7 +10,7 @@ use avian3d::prelude::*;
use bevy::prelude::*; use bevy::prelude::*;
use physics::PhysicsLayers; use physics::PhysicsLayers;
use resources::{Drops, Resources}; use resources::{Drops, Resources};
use state::GameSystemSet; use state::{BasePhaseState, GameSystemSet};
pub struct CombatPlugin; pub struct CombatPlugin;
@ -212,6 +212,7 @@ fn on_die(
trigger: Trigger<Died>, trigger: Trigger<Died>,
names: Query<&Name>, names: Query<&Name>,
drops: Query<&Drops>, drops: Query<&Drops>,
phase: Res<State<BasePhaseState>>,
mut resources: ResMut<Resources>, mut resources: ResMut<Resources>,
mut commands: Commands, mut commands: Commands,
) { ) {

View file

@ -8,7 +8,7 @@ use building::Building;
use combat::{GaveDamage, Health, Team}; use combat::{GaveDamage, Health, Team};
use combat_damagers::ContactDamage; use combat_damagers::ContactDamage;
use inhabitant::Inhabitant; use inhabitant::Inhabitant;
use state::GameSystemSet; use state::{BasePhaseState, GameSystemSet};
pub struct InhabitantCoranthPlugin; pub struct InhabitantCoranthPlugin;
@ -34,6 +34,7 @@ fn spawn(
mut commands: Commands, mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
phase: Res<State<BasePhaseState>>,
) { ) {
for SpawnCoranth { transform } in reader.read() { for SpawnCoranth { transform } in reader.read() {
commands commands
@ -50,7 +51,7 @@ fn spawn(
MaxLinearSpeed(25.), MaxLinearSpeed(25.),
Coranth, Coranth,
transform.clone(), transform.clone(),
Health::new(5.0), Health::new(1.0 + phase.get().phase_count() as f32),
ContactDamage::new(5.0), ContactDamage::new(5.0),
Name::from("Coranth"), Name::from("Coranth"),
Team::Inhabitant.collision_layers(), Team::Inhabitant.collision_layers(),
@ -70,7 +71,7 @@ fn explode(
}; };
let origin = gtf.translation(); let origin = gtf.translation();
for e in spatial_query.shape_intersections( for e in spatial_query.shape_intersections(
&Collider::sphere(5.0), &Collider::sphere(2.0),
origin, origin,
Quat::IDENTITY, Quat::IDENTITY,
// &SpatialQueryFilter::from_mask(Team::Inhabitant), // &SpatialQueryFilter::from_mask(Team::Inhabitant),
@ -78,7 +79,7 @@ fn explode(
) { ) {
if let Ok((gtf, mut v)) = other_query.get_mut(e) { if let Ok((gtf, mut v)) = other_query.get_mut(e) {
let delta = gtf.translation() - origin; let delta = gtf.translation() - origin;
v.0 += delta.normalize_or_zero() * 2.0; v.0 += delta.normalize_or_zero();
} }
} }
} }

View file

@ -7,6 +7,7 @@ edition = "2024"
bevy = { workspace = true } bevy = { workspace = true }
avian3d = { workspace = true } avian3d = { workspace = true }
bevy_egui = { workspace = true } bevy_egui = { workspace = true }
rand = { workspace = true }
state = { path = "../state" } state = { path = "../state" }
camera = { path = "../camera" } camera = { path = "../camera" }

View file

@ -4,7 +4,7 @@
use std::time::Duration; use std::time::Duration;
use avian3d::prelude::*; use avian3d::{math::PI, prelude::*};
use bevy::{ use bevy::{
core_pipeline::{bloom::Bloom, experimental::taa::TemporalAntiAliasing}, core_pipeline::{bloom::Bloom, experimental::taa::TemporalAntiAliasing},
pbr::{Atmosphere, ScreenSpaceAmbientOcclusion, light_consts::lux}, pbr::{Atmosphere, ScreenSpaceAmbientOcclusion, light_consts::lux},
@ -12,10 +12,13 @@ use bevy::{
render::camera::Exposure, render::camera::Exposure,
}; };
use bevy_egui::PrimaryEguiContext; use bevy_egui::PrimaryEguiContext;
use building::Core;
use camera::ControlledCamera; use camera::ControlledCamera;
use combat::Range;
use inhabitant::Inhabitant; use inhabitant::Inhabitant;
use inhabitant_coranth::SpawnCoranth; use inhabitant_coranth::SpawnCoranth;
use physics::{Ground, PhysicsLayers}; use physics::{Ground, PhysicsLayers};
use rand::{Rng, thread_rng};
use resource_graveyard::PlaceGraveyard; use resource_graveyard::PlaceGraveyard;
use state::{AppState, BasePhaseState, GameSystemSet, Phase}; use state::{AppState, BasePhaseState, GameSystemSet, Phase};
@ -49,19 +52,19 @@ impl Plugin for LevelPlugin {
#[derive(Resource, Default, Deref, DerefMut)] #[derive(Resource, Default, Deref, DerefMut)]
pub struct ExecuteTimer(pub Option<Timer>); pub struct ExecuteTimer(pub Option<Timer>);
const LEVEL_SIZE: f32 = 100.;
fn setup( fn setup(
mut commands: Commands, mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
mut coranth_writer: EventWriter<SpawnCoranth>,
mut graveyard_writer: EventWriter<PlaceGraveyard>, mut graveyard_writer: EventWriter<PlaceGraveyard>,
) { ) {
let level_size = 50.0;
// Static physics object with a collision shape // Static physics object with a collision shape
commands.spawn(( commands.spawn((
RigidBody::Static, RigidBody::Static,
Collider::cuboid(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))), Mesh3d(meshes.add(Cuboid::new(LEVEL_SIZE, 1.0, LEVEL_SIZE))),
Transform::from_xyz(0.0, -0.5, 0.0), Transform::from_xyz(0.0, -0.5, 0.0),
MeshMaterial3d(materials.add(StandardMaterial { MeshMaterial3d(materials.add(StandardMaterial {
base_color: Color::srgb_u8(52, 125, 117), base_color: Color::srgb_u8(52, 125, 117),
@ -74,13 +77,31 @@ fn setup(
Name::new("ground"), Name::new("ground"),
)); ));
for y in 5..15 { let mut rng = thread_rng();
coranth_writer.write(SpawnCoranth {
transform: Transform::from_xyz(y as f32 * 0.25, y as f32 * 1.1, 0.0),
});
}
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 // Light
commands.spawn(( commands.spawn((
@ -120,6 +141,8 @@ fn setup(
fn spawn_enemies( fn spawn_enemies(
mut writer: EventWriter<SpawnCoranth>, mut writer: EventWriter<SpawnCoranth>,
core_query: Single<(&GlobalTransform, &Range), With<Core>>,
phase_state: Res<State<BasePhaseState>>,
time: Res<Time>, time: Res<Time>,
mut setup: Local<bool>, mut setup: Local<bool>,
mut timer: Local<Timer>, mut timer: Local<Timer>,
@ -128,18 +151,58 @@ fn spawn_enemies(
*timer = Timer::new(Duration::from_secs(1), TimerMode::Repeating); *timer = Timer::new(Duration::from_secs(1), TimerMode::Repeating);
*setup = true; *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()); timer.tick(time.delta());
if timer.just_finished() { if timer.just_finished() {
for _ in 0..3 { let (core_gtf, core_range) = core_query.into_inner();
writer.write(SpawnCoranth { let level_rect = Rect::new(
transform: Transform::from_xyz(0.0, 2.0, 0.0), -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>) { fn on_execute(mut timer: ResMut<ExecuteTimer>, curr_phase: Res<State<BasePhaseState>>) {
timer.0 = Some(Timer::from_seconds(5., TimerMode::Once)); timer.0 = Some(Timer::from_seconds(
(5. + 2. * curr_phase.get().phase_count() as f32).min(60.),
TimerMode::Once,
));
} }
fn tick_execute_timer( fn tick_execute_timer(

View file

@ -186,7 +186,7 @@ fn transition_ui(
fn side_panel( fn side_panel(
mut contexts: EguiContexts, mut contexts: EguiContexts,
mut commands: Commands, mut commands: Commands,
resources: Res<Resources>, mut resources: ResMut<Resources>,
mut available_workers: ResMut<AvailableWorkers>, mut available_workers: ResMut<AvailableWorkers>,
buildings: Query<(&BuildingInfo, &Cost, &Name)>, buildings: Query<(&BuildingInfo, &Cost, &Name)>,
selected: Query<(Entity, &Name), With<Selected>>, selected: Query<(Entity, &Name), With<Selected>>,
@ -292,6 +292,7 @@ fn side_panel(
RichText::new(upgrade_name.as_str()).size(LARGE_FONT_SIZE); RichText::new(upgrade_name.as_str()).size(LARGE_FONT_SIZE);
if resources.0.can_buy(upgrade.cost) { if resources.0.can_buy(upgrade.cost) {
if ui.button(button_text).clicked() { if ui.button(button_text).clicked() {
resources.0 = resources.0 - upgrade.cost;
commands.trigger_targets( commands.trigger_targets(
UnlockUpgrade { building: selected }, UnlockUpgrade { building: selected },
upgrade_entity, upgrade_entity,