Skip to content

Commit

Permalink
Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
cnmorales committed Nov 18, 2023
1 parent f4c0468 commit ff3168e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 45 deletions.
1 change: 1 addition & 0 deletions src/game/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ pub use enemy::Enemy;
pub use hitpoints::Hitpoints;
pub use level::BorderTile;
pub use player::Player;
pub use player::SpawnFireBreathEvent;
pub use plugin::GamePlugin;
54 changes: 54 additions & 0 deletions src/game/player.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bevy::prelude::*;
use bevy_particle_systems::*;
use bevy_rapier2d::prelude::Collider;

use crate::{
Expand All @@ -12,6 +13,9 @@ pub(super) struct PlayerPlugin;

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(OnEnter(AppState::InGame), spawn_player);
}
}
Expand All @@ -29,6 +33,21 @@ pub struct PlayerBundle {
#[derive(Component)]
pub struct Player;

#[derive(Event)]
pub struct SpawnFireBreathEvent {
damage: i16,
position: Vec2,
}

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

fn spawn_player(mut commands: Commands, asset_server: Res<AssetServer>) {
let texture = asset_server
.get_handle("textures/dragon.png")
Expand All @@ -50,3 +69,38 @@ 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()
{
info!("event received");
commands.spawn(ParticleSystemBundle {
transform: Transform::from_translation(position.extend(1.0)),
particle_system: ParticleSystem {
max_particles: 10_000,
texture: ParticleTexture::Sprite(asset_server.load("fire_particle.png")),
spawn_rate_per_second: 25.0.into(),
initial_speed: JitteredValue::jittered(3.0, -1.0..1.0),
lifetime: JitteredValue::jittered(8.0, -2.0..2.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: true,
system_duration_seconds: 3.0,
..ParticleSystem::default()
},
..ParticleSystemBundle::default()
})
// Add the playing component so it starts playing. This can be added later as well.
.insert(Playing);
}
}

27 changes: 12 additions & 15 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ use std::f32::consts::FRAC_PI_2;

use bevy::{ecs::system::SystemParam, prelude::*, window::PrimaryWindow};

use crate::{game::Player, playing};
use crate::spawn_particle_system;
use crate::{
game::Player,
game::SpawnFireBreathEvent,
playing}
;

pub struct InputPlugin;

Expand Down Expand Up @@ -75,24 +78,18 @@ 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>>,
mut gizmos: Gizmos,
) {
if keys.pressed(KeyCode::Key1) {
// Key number 1 is being held down
info!("Pressed 1");
let mut player_transform = query.single_mut();
let player_transform = query.single_mut();
let player_position = player_transform.translation.truncate();

// TODO: spawn_particle on vec
// spawn.push(ParticleBundle.clone().with(Transform {
// position: player_position
// } )

spawn_particle_system;



spawn_fire_breath_event_writer.send(SpawnFireBreathEvent::new(
1000,
player_position,
));
info!("Event sent");
}

}
32 changes: 2 additions & 30 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy::{
RenderPlugin,
},
};
use bevy_particle_systems::*;
use bevy_particle_systems::ParticleSystemPlugin;
use camera::CameraPlugin;
use fonts::{font_assets_loaded, FontsPlugin};
use game::GamePlugin;
Expand Down Expand Up @@ -44,14 +44,13 @@ fn main() {
InputPlugin,
PhysicsPlugin,
TexturesPlugin,
ParticleSystemPlugin::default()
));

app.add_state::<AppState>();

app.add_systems(
Update,
(handle_asset_load,spawn_particle_system).run_if(assets_loaded().and_then(run_once())),
handle_asset_load.run_if(assets_loaded().and_then(run_once())),
);

app.run();
Expand Down Expand Up @@ -79,30 +78,3 @@ fn assets_loaded() -> impl Condition<()> {
.and_then(audio_assets_loaded())
.and_then(font_assets_loaded())
}

// TODO Move to new file
pub fn spawn_particle_system(mut commands: Commands, asset_server: Res<AssetServer>) {
commands

// Add the bundle specifying the particle system itself.
.spawn(ParticleSystemBundle {
particle_system: ParticleSystem {
max_particles: 10_000,
texture: ParticleTexture::Sprite(asset_server.load("fire_particle.png")),
spawn_rate_per_second: 25.0.into(),
initial_speed: JitteredValue::jittered(3.0, -1.0..1.0),
lifetime: JitteredValue::jittered(8.0, -2.0..2.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: true,
system_duration_seconds: 10.0,
..ParticleSystem::default()
},
..ParticleSystemBundle::default()
})

// Add the playing component so it starts playing. This can be added later as well.
.insert(Playing);
}

0 comments on commit ff3168e

Please sign in to comment.