make coranths go straight for core, and make them into balls

This commit is contained in:
Jim 2025-09-02 10:29:17 -04:00
parent e2d0d553e9
commit 2d02e1cae6
Signed by: jim
GPG key ID: 3D7D94BA53088BF4
3 changed files with 57 additions and 29 deletions

View file

@ -1,11 +1,11 @@
( (
map: { map: {
KeyCode(ShiftLeft): [
MultiPlaceTower,
],
MouseButton(Middle): [ MouseButton(Middle): [
CameraOrbitEnable, CameraOrbitEnable,
], ],
KeyCode(ShiftLeft): [
MultiPlaceTower,
],
KeyCode(F1): [ KeyCode(F1): [
ToggleDebugUI, ToggleDebugUI,
], ],

View file

@ -4,7 +4,7 @@
use avian3d::prelude::*; use avian3d::prelude::*;
use bevy::prelude::*; use bevy::prelude::*;
use building::Building; use building::Core;
use combat::{GaveDamage, Health, Team}; use combat::{GaveDamage, Health, Team};
use combat_damagers::ContactDamage; use combat_damagers::ContactDamage;
use inhabitant::Inhabitant; use inhabitant::Inhabitant;
@ -15,6 +15,7 @@ pub struct InhabitantCoranthPlugin;
impl Plugin for InhabitantCoranthPlugin { impl Plugin for InhabitantCoranthPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_event::<SpawnCoranth>() app.add_event::<SpawnCoranth>()
.add_systems(Startup, init)
.add_systems(FixedUpdate, tick.in_set(GameSystemSet::Execute)) .add_systems(FixedUpdate, tick.in_set(GameSystemSet::Execute))
.add_systems(FixedUpdate, spawn.in_set(GameSystemSet::PostTick)); .add_systems(FixedUpdate, spawn.in_set(GameSystemSet::PostTick));
} }
@ -29,25 +30,42 @@ pub struct SpawnCoranth {
pub transform: Transform, pub transform: Transform,
} }
fn spawn( #[derive(Resource)]
mut reader: EventReader<SpawnCoranth>, struct CoranthResources {
material: Handle<StandardMaterial>,
mesh: Handle<Mesh>,
charge_timer: Timer,
}
fn init(
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>>,
) {
commands.insert_resource(CoranthResources {
material: materials.add(StandardMaterial {
base_color: Color::srgb_u8(220, 156, 86),
metallic: 1.0,
perceptual_roughness: 0.3,
..default()
}),
mesh: meshes.add(Sphere::new(0.25)),
charge_timer: Timer::from_seconds(1.5, TimerMode::Repeating),
});
}
fn spawn(
mut reader: EventReader<SpawnCoranth>,
mut commands: Commands,
phase: Res<State<BasePhaseState>>, phase: Res<State<BasePhaseState>>,
res: Res<CoranthResources>,
) { ) {
for SpawnCoranth { transform } in reader.read() { for SpawnCoranth { transform } in reader.read() {
commands commands
.spawn(( .spawn((
RigidBody::Dynamic, RigidBody::Dynamic,
Collider::cuboid(0.5, 0.5, 0.5), Collider::sphere(0.25),
Mesh3d(meshes.add(Cuboid::from_length(0.5))), Mesh3d(res.mesh.clone()),
MeshMaterial3d(materials.add(StandardMaterial { MeshMaterial3d(res.material.clone()),
base_color: Color::srgb_u8(220, 156, 86),
metallic: 1.0,
perceptual_roughness: 0.3,
..default()
})),
MaxLinearSpeed(25.), MaxLinearSpeed(25.),
Coranth, Coranth,
transform.clone(), transform.clone(),
@ -86,22 +104,32 @@ fn explode(
fn tick( fn tick(
mut coranths: Query<(&GlobalTransform, &mut LinearVelocity), With<Coranth>>, mut coranths: Query<(&GlobalTransform, &mut LinearVelocity), With<Coranth>>,
buildings: Query<&GlobalTransform, With<Building>>, core_gtf: Single<&GlobalTransform, With<Core>>,
mut res: ResMut<CoranthResources>,
time: Res<Time>,
) { ) {
res.charge_timer.tick(time.delta());
if !res.charge_timer.just_finished() {
return;
}
for (coranth_tf, mut coranth_v) in coranths.iter_mut() { for (coranth_tf, mut coranth_v) in coranths.iter_mut() {
let coranth_pos = coranth_tf.translation(); let coranth_pos = coranth_tf.translation();
if let Some(closest_building) = let core_pos = core_gtf.translation();
buildings
.iter() let delta = (core_pos - coranth_pos).with_y(0.);
.map(|gtf| gtf.translation()) coranth_v.0 += delta.normalize_or_zero().with_y(0.5) * 7.;
.min_by(|a, b| { // if let Some(closest_building) =
coranth_pos // buildings
.distance_squared(*a) // .iter()
.total_cmp(&coranth_pos.distance_squared(*b)) // .map(|gtf| gtf.translation())
}) // .min_by(|a, b| {
{ // coranth_pos
let delta = closest_building - coranth_pos; // .distance_squared(*a)
coranth_v.0 += delta.normalize_or_zero() * 0.1; // .total_cmp(&coranth_pos.distance_squared(*b))
} // })
// {
// let delta = (closest_building - coranth_pos).with_y(0.);
// coranth_v.0 += delta.normalize_or_zero().with_y(0.5) * 7.;
// }
} }
} }

View file

@ -4,7 +4,7 @@
- music - music
x limit workers per resource deposit x limit workers per resource deposit
- main menu - main menu
- improve enemy AI x improve enemy AI
- balance - balance
--- IMPORTANT --- --- IMPORTANT ---