add endrake and simberts

This commit is contained in:
Jim 2025-09-02 11:53:01 -04:00
parent 2d02e1cae6
commit 52da1f8acb
Signed by: jim
GPG key ID: 3D7D94BA53088BF4
14 changed files with 385 additions and 24 deletions

View file

@ -0,0 +1,19 @@
[package]
name = "inhabitant_endrake"
version = "0.1.0"
edition = "2024"
[dependencies]
bevy = { workspace = true }
avian3d = { workspace = true }
state = { path = "../state" }
combat = { path = "../combat" }
building = { path = "../building" }
inhabitant = { path = "../inhabitant" }
combat_damagers = { path = "../combat_damagers" }
ui_health_bar = { path = "../ui_health_bar" }
inhabitant_simbert = { path = "../inhabitant_simbert" }
[lints]
workspace = true

View file

@ -0,0 +1,125 @@
//bevy system signatures often violate these rules
#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]
use avian3d::prelude::*;
use bevy::prelude::*;
use building::Core;
use combat::{Health, Team};
use combat_damagers::ContactDamage;
use inhabitant::Inhabitant;
use inhabitant_simbert::SpawnSimbert;
use state::{BasePhaseState, GameSystemSet};
use ui_health_bar::BarSettings;
pub struct InhabitantEndrakePlugin;
impl Plugin for InhabitantEndrakePlugin {
fn build(&self, app: &mut App) {
app.add_event::<SpawnEndrake>()
.add_systems(Startup, init)
.add_systems(FixedUpdate, tick.in_set(GameSystemSet::Execute))
.add_systems(FixedUpdate, spawn.in_set(GameSystemSet::PostTick));
}
}
#[derive(Component)]
#[require(Inhabitant)]
pub struct Endrake {
spawn_timer: Timer,
spawn_count: u32,
}
#[derive(Event)]
pub struct SpawnEndrake {
pub transform: Transform,
}
#[derive(Resource)]
struct EndrakeResources {
material: Handle<StandardMaterial>,
mesh: Handle<Mesh>,
}
const BASE_RADIUS: f32 = 3.;
const HEIGHT: f32 = 4.;
const TOP_RADIUS: f32 = 2.;
fn init(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.insert_resource(EndrakeResources {
material: materials.add(StandardMaterial {
base_color: Color::srgb_u8(247, 187, 119),
emissive: Color::srgb_u8(242, 227, 206).to_linear() * 0.5,
metallic: 0.0,
perceptual_roughness: 1.0,
..default()
}),
mesh: meshes.add(ConicalFrustum {
radius_top: TOP_RADIUS,
radius_bottom: BASE_RADIUS,
height: HEIGHT,
}),
});
}
fn spawn(
mut reader: EventReader<SpawnEndrake>,
mut commands: Commands,
phase: Res<State<BasePhaseState>>,
res: Res<EndrakeResources>,
) {
for SpawnEndrake { transform } in reader.read() {
commands.spawn((
RigidBody::Dynamic,
Collider::cuboid(TOP_RADIUS * 2., HEIGHT, TOP_RADIUS * 2.),
Mesh3d(res.mesh.clone()),
MeshMaterial3d(res.material.clone()),
MaxLinearSpeed(0.5),
Mass(10.),
Endrake {
spawn_timer: Timer::from_seconds(2.0, TimerMode::Repeating),
spawn_count: 10,
},
transform.clone(),
Health::new(2000.0 + 100. * phase.get().phase_count() as f32),
// todo: change enemy health bar color to differentiate from buildings
BarSettings {
offset: HEIGHT + 0.5,
width: 24,
..default()
},
ContactDamage::new(5.0),
Name::from("Endrake"),
Team::Inhabitant.collision_layers(),
));
}
}
fn tick(
mut endrakes: Query<(&GlobalTransform, &mut LinearVelocity, &mut Endrake)>,
core_gtf: Single<&GlobalTransform, With<Core>>,
mut spawn_writer: EventWriter<SpawnSimbert>,
time: Res<Time>,
) {
let core_pos = core_gtf.translation();
let delta = time.delta();
for (endrake_tf, mut endrake_v, mut endrake) in endrakes.iter_mut() {
let endrake_pos = endrake_tf.translation();
endrake.spawn_timer.tick(delta);
if endrake.spawn_timer.just_finished() {
for y in 0..endrake.spawn_count {
spawn_writer.write(SpawnSimbert {
transform: Transform::from_translation(
endrake_pos + Vec3::Y * (HEIGHT + 1. + y as f32 * 1.5),
),
mega: true,
});
}
}
let delta = (core_pos - endrake_pos).with_y(0.);
endrake_v.0 += delta.normalize_or_zero() * 0.1;
}
}