diff --git a/src/game/player.rs b/src/game/player.rs index ff03c0e..85a6bc3 100644 --- a/src/game/player.rs +++ b/src/game/player.rs @@ -15,7 +15,7 @@ impl Plugin for PlayerPlugin { fn build(&self, app: &mut App) { app.add_event::(); app.add_plugins(ParticleSystemPlugin::default()); - app.add_systems(Update,spawn_fire_breath); + app.add_systems(Update, spawn_fire_breath); app.add_systems(OnEnter(AppState::InGame), spawn_player); } } @@ -41,10 +41,7 @@ pub struct SpawnFireBreathEvent { impl SpawnFireBreathEvent { pub fn new(damage: i16, position: Vec2) -> Self { - Self { - damage, - position - } + Self { damage, position } } } @@ -73,35 +70,31 @@ fn spawn_player(mut commands: Commands, asset_server: Res) { fn spawn_fire_breath( mut commands: Commands, mut spawn_fire_breath_event_reader: EventReader, - asset_server: Res -){ - for &SpawnFireBreathEvent { - damage, - position, - } in spawn_fire_breath_event_reader.read() - { - commands.spawn(ParticleSystemBundle { - transform: Transform::from_translation(position.extend(1.0)), - - particle_system: ParticleSystem { - max_particles: 10_000, - texture: ParticleTexture::Sprite(asset_server.load("textures/fire_breath.png")), - spawn_rate_per_second: 10.0.into(), - initial_speed: JitteredValue::jittered(3.0, -1.0..1.0), - lifetime: JitteredValue::jittered(4.0, -1.0..1.0), - /* color: ColorOverTime::Gradient(Gradient::new(vec![ - ColorPoint::new(Color::WHITE, 0.0), - ColorPoint::new(Color::rgba(0.0, 0.0, 1.0, 0.0), 1.0), - ])), */ - looping: false, - despawn_on_finish : true, - system_duration_seconds: 1.0, - ..ParticleSystem::default() - }, - ..ParticleSystemBundle::default() - }) - // Add the playing component so it starts playing. This can be added later as well. - .insert(Playing); + asset_server: Res, +) { + for &SpawnFireBreathEvent { damage, position } in spawn_fire_breath_event_reader.read() { + commands + .spawn(ParticleSystemBundle { + transform: Transform::from_translation(position.extend(1.0)), + + particle_system: ParticleSystem { + max_particles: 10_000, + texture: ParticleTexture::Sprite(asset_server.load("textures/fire_breath.png")), + spawn_rate_per_second: 10.0.into(), + initial_speed: JitteredValue::jittered(3.0, -1.0..1.0), + lifetime: JitteredValue::jittered(4.0, -1.0..1.0), + /* color: ColorOverTime::Gradient(Gradient::new(vec![ + ColorPoint::new(Color::WHITE, 0.0), + ColorPoint::new(Color::rgba(0.0, 0.0, 1.0, 0.0), 1.0), + ])), */ + looping: false, + despawn_on_finish: true, + system_duration_seconds: 1.0, + ..ParticleSystem::default() + }, + ..ParticleSystemBundle::default() + }) + // Add the playing component so it starts playing. This can be added later as well. + .insert(Playing); } } - diff --git a/src/input.rs b/src/input.rs index 8b27271..63064ea 100644 --- a/src/input.rs +++ b/src/input.rs @@ -2,17 +2,13 @@ use std::f32::consts::FRAC_PI_2; use bevy::{ecs::system::SystemParam, prelude::*, window::PrimaryWindow}; -use crate::{ - game::Player, - game::SpawnFireBreathEvent, - playing} - ; +use crate::{game::Player, game::SpawnFireBreathEvent, playing}; pub struct InputPlugin; impl Plugin for InputPlugin { fn build(&self, app: &mut App) { - app.add_systems(Update, (mouse_input,keyboard_input).run_if(playing())); + app.add_systems(Update, (mouse_input, keyboard_input).run_if(playing())); } } @@ -75,20 +71,16 @@ fn mouse_input( } } - fn keyboard_input( keys: Res>, mut spawn_fire_breath_event_writer: EventWriter, mut query: Query<&mut Transform, With>, ) { - if keys.pressed(KeyCode::Key1) { + if keys.pressed(KeyCode::Key1) { // Key number 1 is being held down let player_transform = query.single_mut(); let player_position = player_transform.translation.truncate(); - spawn_fire_breath_event_writer.send(SpawnFireBreathEvent::new( - 1000, - player_position, - )); + spawn_fire_breath_event_writer.send(SpawnFireBreathEvent::new(1000, player_position)); } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 5623746..507734e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,6 @@ use bevy::{ RenderPlugin, }, }; -use bevy_particle_systems::ParticleSystemPlugin; use camera::CameraPlugin; use fonts::{font_assets_loaded, FontsPlugin}; use game::GamePlugin; @@ -50,7 +49,7 @@ fn main() { app.add_systems( Update, - handle_asset_load.run_if(assets_loaded().and_then(run_once())), + handle_asset_load.run_if(assets_loaded().and_then(run_once())), ); app.run();