Skip to content

Commit

Permalink
Formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
cnmorales committed Nov 18, 2023
1 parent a53d5e5 commit a3db188
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 50 deletions.
63 changes: 28 additions & 35 deletions src/game/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Plugin for PlayerPlugin {
fn build(&self, app: &mut App) {
app.add_event::<SpawnFireBreathEvent>();
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);
}
}
Expand All @@ -41,10 +41,7 @@ pub struct SpawnFireBreathEvent {

impl SpawnFireBreathEvent {
pub fn new(damage: i16, position: Vec2) -> Self {
Self {
damage,
position
}
Self { damage, position }
}
}

Expand Down Expand Up @@ -73,35 +70,31 @@ fn spawn_player(mut commands: Commands, asset_server: Res<AssetServer>) {
fn spawn_fire_breath(
mut commands: Commands,
mut spawn_fire_breath_event_reader: EventReader<SpawnFireBreathEvent>,
asset_server: Res<AssetServer>
){
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<AssetServer>,
) {
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);
}
}

18 changes: 5 additions & 13 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

Expand Down Expand Up @@ -75,20 +71,16 @@ fn mouse_input(
}
}


fn keyboard_input(
keys: Res<Input<KeyCode>>,
mut spawn_fire_breath_event_writer: EventWriter<SpawnFireBreathEvent>,
mut query: Query<&mut Transform, With<Player>>,
) {
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));
}
}
}
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use bevy::{
RenderPlugin,
},
};
use bevy_particle_systems::ParticleSystemPlugin;
use camera::CameraPlugin;
use fonts::{font_assets_loaded, FontsPlugin};
use game::GamePlugin;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a3db188

Please sign in to comment.