Skip to content

Commit

Permalink
effects on alextime being hit by mierda
Browse files Browse the repository at this point in the history
  • Loading branch information
stillonearth committed Dec 26, 2023
1 parent 66b7923 commit a11961c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bevy-inspector-egui = "0.19"
bevy_rapier2d = "0.22"
rand = "0.8.5"
pecs = "0.4"
# bevy_nine_slice_ui = "0.2"
bevy_particle_systems = "0.10"

[profile.dev.package."*"]
opt-level = 3
Expand Down
7 changes: 5 additions & 2 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::time::Duration;
use bevy::prelude::*;

use bevy_ecs_ldtk::prelude::*;
use bevy_particle_systems::ParticleSystemBundle;
// use bevy_particle_systems::*;
use bevy_rapier2d::prelude::*;

use crate::sprites::*;
Expand All @@ -11,7 +13,7 @@ use crate::sprites::*;
pub struct ColliderBundle {
pub collider: Collider,
pub rigid_body: RigidBody,
pub velocity: Velocity,
pub velocity: bevy_rapier2d::dynamics::Velocity,
pub rotation_constraints: LockedAxes,
pub gravity_scale: GravityScale,
pub friction: Friction,
Expand Down Expand Up @@ -50,14 +52,15 @@ pub struct Mierda {
pub is_dummy: bool,
}

#[derive(Clone, Default, Bundle)]
#[derive(Default, Bundle)]
pub struct PlayerBundle {
pub sprite_bundle: SpriteSheetBundle,
pub character_animation: CharacterAnimation,
pub animation_timer: AnimationTimer,
pub player: Player,
pub collider_bundle: ColliderBundle,
pub active_events: ActiveEvents,
// pub particle_system_bundle: ParticleSystemBundle,
}

#[derive(Component, Clone, Default, Reflect)]
Expand Down
37 changes: 35 additions & 2 deletions src/events.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::prelude::*;
use bevy_ecs_ldtk::{LdtkLevel, LevelSelection};
use bevy_particle_systems::*;
use bevy_rapier2d::prelude::Velocity;
use pecs::prelude::*;

Expand Down Expand Up @@ -203,13 +204,15 @@ pub fn event_mierda_hit(
}

pub fn event_player_hit(
mut commands: Commands,
mut ev_player_hit_reader: EventReader<PlayerHitEvent>,
mut ev_game_over: EventWriter<GameOverEvent>,
mut q_player: Query<(Entity, &mut Player)>,
mut q_player: Query<(Entity, &GlobalTransform, &mut Player)>,
mut q_ui_healthbar: Query<(Entity, &mut Style, &ui::UiPlayerHealth)>,
asset_server: Res<AssetServer>,
) {
for ev in ev_player_hit_reader.iter() {
let (_, mut player) = q_player.get_mut(ev.entity).unwrap();
let (_, player_transform, mut player) = q_player.get_mut(ev.entity).unwrap();

if player.health < 10 {
ev_game_over.send(GameOverEvent);
Expand All @@ -220,6 +223,36 @@ pub fn event_player_hit(
for (_, mut style, _) in q_ui_healthbar.iter_mut() {
style.width = Val::Percent(player.health as f32);
}

// particle effects

// continue;

commands.spawn((
ParticleSystemBundle {
transform: player_transform.clone().into(),
particle_system: ParticleSystem {
spawn_rate_per_second: 0.0.into(),
texture: ParticleTexture::Sprite(asset_server.load("px.png")),
max_particles: 5_000,
initial_speed: (0.0..300.0).into(),
scale: 1.0.into(),
velocity_modifiers: vec![
VelocityModifier::Drag(0.001.into()),
VelocityModifier::Vector(Vec3::new(0.0, -400.0, 0.0).into()),
],
color: (Color::RED..Color::rgba(1.0, 0.0, 0.0, 0.0)).into(),
bursts: vec![ParticleBurst {
time: 0.0,
count: 1000,
}],
looping: false,
..ParticleSystem::default()
},
..default()
},
Playing,
));
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/ldtk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::{HashMap, HashSet};

use bevy::prelude::*;
use bevy_ecs_ldtk::prelude::*;
use bevy_particle_systems::*;
use bevy_rapier2d::prelude::*;

use crate::components::*;
Expand Down Expand Up @@ -301,6 +302,24 @@ impl LdtkEntity for PlayerBundle {
collider_bundle,
active_events: ActiveEvents::COLLISION_EVENTS,
player: Player { health: 100 },
// particle_system_bundle: ParticleSystemBundle {
// particle_system: ParticleSystem {
// max_particles: 10_000,
// texture: ParticleTexture::Sprite(asset_server.load("my_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(Curve::new(vec![
// CurvePoint::new(Color::PURPLE, 0.0),
// CurvePoint::new(Color::RED, 0.5),
// CurvePoint::new(Color::rgba(0.0, 0.0, 1.0, 0.0), 1.0),
// ])),
// looping: true,
// system_duration_seconds: 10.0,
// ..ParticleSystem::default()
// },
// ..ParticleSystemBundle::default()
// },
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use bevy::{input::common_conditions::input_toggle_active, prelude::*};
use bevy_ecs_ldtk::prelude::*;
use bevy_inspector_egui::quick::WorldInspectorPlugin;
// use bevy_nine_slice_ui::*;
use bevy_particle_systems::*;
use bevy_rapier2d::prelude::*;
use components::Mierda;
use pecs::prelude::*;
Expand All @@ -13,6 +13,7 @@ mod components;
mod controls;
mod events;
mod ldtk;
mod particles;
mod physics;
mod sprites;
mod ui;
Expand All @@ -32,6 +33,7 @@ fn main() {
.add_plugins(
WorldInspectorPlugin::default().run_if(input_toggle_active(false, KeyCode::Escape)),
)
.add_plugins(ParticleSystemPlugin::default())
.add_systems(Startup, setup)
// UI
.add_systems(Startup, ui::draw_ui)
Expand Down Expand Up @@ -81,6 +83,8 @@ fn main() {
gravity: Vec2::new(0.0, 0.0),
..Default::default()
})
// Particles
.add_systems(Update, (particles::fix_particle_transform_z))
// Events
.add_systems(
Update,
Expand Down

0 comments on commit a11961c

Please sign in to comment.