new character format

This commit is contained in:
2025-04-21 15:36:40 +02:00
parent 2dcc396666
commit 478efedd6c
15 changed files with 153 additions and 183 deletions

View File

@@ -1,15 +1,15 @@
use crate::{
GameState,
alien::Animations,
camera::{CameraArmRotation, CameraTarget},
cash::{Cash, CashCollectEvent},
character::{AnimatedCharacter, CharacterAnimations},
control::controller_common::{CharacterControllerBundle, PlayerMovement},
global_observer,
head::ActiveHead,
heads::{ActiveHeads, HeadChanged, HeadState},
heads_database::{HeadControls, HeadsDatabase},
hitpoints::Hitpoints,
loading_assets::{AudioAssets, GameAssets},
loading_assets::AudioAssets,
physics_layers::GameLayer,
sounds::PlaySound,
tb_entities::SpawnPoint,
@@ -29,9 +29,6 @@ pub struct Player;
#[derive(Component, Default)]
struct PlayerAnimations;
#[derive(Component, Default)]
struct PlayerHeadMesh;
#[derive(Component, Default)]
pub struct PlayerBodyMesh;
@@ -56,7 +53,6 @@ fn spawn(
mut commands: Commands,
asset_server: Res<AssetServer>,
query: Query<&Transform, With<SpawnPoint>>,
assets: Res<GameAssets>,
heads_db: Res<HeadsDatabase>,
) {
let Some(spawn) = query.iter().next() else {
@@ -65,9 +61,6 @@ fn spawn(
let transform = Transform::from_translation(spawn.translation + Vec3::new(0., 3., 0.));
let mesh = asset_server
.load(GltfAssetLabel::Scene(0).from_asset("models/heads/angry demonstrator.glb"));
let gravity = Vector::NEG_Y * 40.0;
let collider = Collider::capsule(0.9, 1.2);
@@ -94,21 +87,13 @@ fn spawn(
.with_children(|parent| {
parent
.spawn((
Name::from("body rig"),
Name::new("player-rig"),
Transform::default(),
Visibility::default(),
PlayerBodyMesh,
CameraArmRotation,
Transform::from_translation(Vec3::new(0., -1.45, 0.))
.with_rotation(Quat::from_rotation_y(std::f32::consts::PI))
.with_scale(Vec3::splat(1.4)),
SceneRoot(assets.mesh_alien.clone()),
))
.with_child((
Name::from("head"),
PlayerHeadMesh,
Transform::from_translation(Vec3::new(0., 1.6, 0.))
.with_scale(Vec3::splat(0.7)),
SceneRoot(mesh),
));
.with_child(AnimatedCharacter(0));
});
commands.spawn((
@@ -176,29 +161,33 @@ fn setup_animations_marker_for_player(
for ancestor in parent_query.iter_ancestors(entity) {
if player.contains(ancestor) {
commands.entity(entity).insert(PlayerAnimations);
return;
}
}
}
}
fn toggle_animation(
animations: Res<Animations>,
mut transitions: Query<
(&mut AnimationTransitions, &mut AnimationPlayer),
(
&mut AnimationTransitions,
&mut AnimationPlayer,
&CharacterAnimations,
),
With<PlayerAnimations>,
>,
movement: Res<PlayerMovement>,
) {
if movement.is_changed() {
let index = if movement.any_direction { 0 } else { 1 };
for (mut transition, mut player, animations) in &mut transitions {
let index = if movement.any_direction {
animations.run
} else {
animations.idle
};
for (mut transition, mut player) in &mut transitions {
transition
.play(
&mut player,
animations.animations[index],
Duration::from_millis(100),
)
.play(&mut player, index, Duration::from_millis(100))
.repeat();
}
}
@@ -207,13 +196,12 @@ fn toggle_animation(
fn on_update_head(
trigger: Trigger<HeadChanged>,
mut commands: Commands,
asset_server: Res<AssetServer>,
head: Query<Entity, With<PlayerHeadMesh>>,
body_mesh: Query<Entity, With<PlayerBodyMesh>>,
mut player_head: Query<&mut ActiveHead, With<Player>>,
head_db: Res<HeadsDatabase>,
audio_assets: Res<AudioAssets>,
) {
let Ok(head) = head.get_single() else {
let Ok(body_mesh) = body_mesh.get_single() else {
return;
};
@@ -227,27 +215,21 @@ fn on_update_head(
commands.trigger(PlaySound::Head(head_str.to_string()));
//TODO: load from dynamic asset collection? or keep lazy?
let mesh = asset_server
.load(GltfAssetLabel::Scene(0).from_asset(format!("models/heads/{}.glb", head_str)));
commands.entity(body_mesh).despawn_descendants();
commands.entity(head).despawn_descendants();
commands.entity(head).insert(SceneRoot(mesh));
commands
.entity(body_mesh)
.with_child(AnimatedCharacter(trigger.0));
//TODO: make part of full character mesh later
if head_db.head_stats(trigger.0).controls == HeadControls::Plane {
let mesh = asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/mig.glb"));
commands
.entity(head)
.with_child((Transform::from_xyz(0., -1., 0.), SceneRoot(mesh)))
.with_child((
Name::new("sfx"),
AudioPlayer::new(audio_assets.jet.clone()),
PlaybackSettings {
mode: bevy::audio::PlaybackMode::Loop,
..Default::default()
},
));
commands.entity(body_mesh).with_child((
Name::new("sfx"),
AudioPlayer::new(audio_assets.jet.clone()),
PlaybackSettings {
mode: bevy::audio::PlaybackMode::Loop,
..Default::default()
},
));
}
}