WIP thruster particles

This commit is contained in:
yuni 2024-09-15 23:56:03 +02:00
parent dcb6e6e5a9
commit b01823c641
3 changed files with 46 additions and 13 deletions

BIN
assets/textures/exhaust.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View file

@ -12,7 +12,6 @@
use crate::prelude::*;
use bevy::color::palettes::css;
use bevy::pbr::ExtendedMaterial;
use bevy::prelude::*;
use bevy::scene::SceneInstance;
use bevy::window::{PrimaryWindow, Window, WindowMode};
@ -471,22 +470,30 @@ fn update_id2v(mut id2v: ResMut<Id2V>, q_id: Query<(&LinearVelocity, &actor::Ide
fn debug(
settings: Res<var::Settings>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut commands: Commands,
mut extended_materials: ResMut<
Assets<ExtendedMaterial<StandardMaterial, load::AsteroidSurface>>,
>,
// mut commands: Commands,
// mut extended_materials: ResMut<
// Assets<bevy::pbr::ExtendedMaterial<StandardMaterial, load::AsteroidSurface>>,
// >,
mut achievement_tracker: ResMut<var::AchievementTracker>,
vars: Res<var::GameVars>,
materials: Query<(Entity, Option<&Name>, &Handle<Mesh>)>,
q_playercam: Query<(&Position, &LinearVelocity), With<actor::PlayerCamera>>,
mut ew_effect: EventWriter<visual::SpawnEffectEvent>,
// materials: Query<(Entity, Option<&Name>, &Handle<Mesh>)>,
) {
if settings.dev_mode && keyboard_input.just_pressed(KeyCode::KeyP) {
for (entity, _name, mesh) in &materials {
dbg!(mesh);
let mut entity = commands.entity(entity);
entity.remove::<Handle<StandardMaterial>>();
let material = extended_materials.add(load::AsteroidSurface::material());
entity.insert(material);
}
let (pos, v) = q_playercam.get_single().unwrap();
ew_effect.send(visual::SpawnEffectEvent {
duration: 0.0,
class: visual::Effects::ThrusterParticle(pos.clone(), v.clone()),
});
// for (entity, _name, mesh) in &materials {
// dbg!(mesh);
// let mut entity = commands.entity(entity);
// entity.remove::<Handle<StandardMaterial>>();
// let material = extended_materials.add(load::AsteroidSurface::material());
// entity.insert(material);
// }
}
if settings.dev_mode && keyboard_input.just_pressed(KeyCode::KeyN) {
achievement_tracker.achieve_all();

View file

@ -12,6 +12,7 @@
use crate::prelude::*;
use bevy::prelude::*;
use bevy_xpbd_3d::prelude::*;
use std::time::Duration;
pub struct VisualPlugin;
@ -37,6 +38,7 @@ impl Plugin for VisualPlugin {
pub enum Effects {
FadeIn(Color),
FadeOut(Color),
ThrusterParticle(Position, LinearVelocity),
}
// Blackout disabled for now
@ -109,6 +111,9 @@ pub fn setup(
pub fn spawn_effects(
mut commands: Commands,
mut er_effect: EventReader<SpawnEffectEvent>,
mut materials: ResMut<Assets<StandardMaterial>>,
mut meshes: ResMut<Assets<Mesh>>,
asset_server: Res<AssetServer>,
time: Res<Time>,
) {
let now = time.elapsed_seconds_f64();
@ -144,6 +149,27 @@ pub fn spawn_effects(
},
));
}
Effects::ThrusterParticle(pos, v) => {
let texture = asset_server.load("textures/exhaust.png");
commands.spawn((
RigidBody::Kinematic,
bevy::pbr::NotShadowCaster,
pos,
v,
world::DespawnOnPlayerDeath,
actor::WantsToLookAt(cmd::ID_SPECIAL_PLAYERCAM.into()),
PbrBundle {
mesh: meshes.add(Mesh::from(Rectangle::new(1.0, 1.0))),
material: materials.add(StandardMaterial {
base_color_texture: Some(texture),
perceptual_roughness: 1.0,
alpha_mode: AlphaMode::Blend,
..Default::default()
}),
..default()
},
));
}
}
}
}