Skip to content

Commit

Permalink
feat: Add smoke explosion on demon boss spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
PraxTube committed Dec 20, 2023
1 parent 30d9f11 commit 49a4c3b
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 7 deletions.
Binary file added assets/spell/smoke.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions assets/spell/smoke.trickfilm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
(
name: "main",
keyframes: KeyframesRange((start: 0, end: 12)),
duration: 1.0,
),
]
5 changes: 5 additions & 0 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ pub struct GameAssets {
pub demon_boss_explosion2: Handle<TextureAtlas>,
#[asset(paths("spell/explosion2.trickfilm#main"), collection(typed))]
pub demon_boss_explosion2_animations: Vec<Handle<AnimationClip2D>>,
#[asset(texture_atlas(tile_size_x = 64.0, tile_size_y = 64.0, columns = 12, rows = 1))]
#[asset(path = "spell/smoke.png")]
pub demon_boss_smoke: Handle<TextureAtlas>,
#[asset(paths("spell/smoke.trickfilm#main"), collection(typed))]
pub demon_boss_smoke_animations: Vec<Handle<AnimationClip2D>>,

// --- MAP ---
#[asset(path = "map/level.ldtk")]
Expand Down
51 changes: 50 additions & 1 deletion src/audio/bgm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::time::Duration;
use bevy::prelude::*;
use bevy_kira_audio::prelude::*;

use crate::{item::statue::StatueUnlockedDelayed, GameAssets, GameState};
use crate::{
item::{platform::TriggerFinalAct, statue::StatueUnlockedDelayed},
GameAssets, GameState,
};

use super::GameAudio;

Expand Down Expand Up @@ -38,6 +41,31 @@ fn play_bgm(
commands.spawn(Bgm { handle });
}

fn play_boss_bgm(
mut commands: Commands,
assets: Res<GameAssets>,
audio: Res<Audio>,
game_audio: Res<GameAudio>,
mut ev_trigger_final_act: EventReader<TriggerFinalAct>,
) {
if ev_trigger_final_act.is_empty() {
return;
}
ev_trigger_final_act.clear();

let volume = game_audio.main_volume * BGM_VOLUME;
let handle = audio
.play(assets.bgm_boss.clone())
.fade_in(AudioTween::new(
Duration::from_secs_f32(3.0),
AudioEasing::InPowi(3),
))
.with_volume(volume)
.looped()
.handle();
commands.spawn(Bgm { handle });
}

fn update_bgm_volumes(
game_audio: Res<GameAudio>,
mut audio_instances: ResMut<Assets<AudioInstance>>,
Expand Down Expand Up @@ -104,6 +132,25 @@ fn unmute_bgms(
}
}

fn despawn_normal_bgm(
mut commands: Commands,
mut audio_instances: ResMut<Assets<AudioInstance>>,
q_bgms: Query<(Entity, &Bgm)>,
mut ev_trigger_final_act: EventReader<TriggerFinalAct>,
) {
if ev_trigger_final_act.is_empty() {
return;
}
ev_trigger_final_act.clear();

for (entity, bgm) in &q_bgms {
if let Some(instance) = audio_instances.get_mut(bgm.handle.clone()) {
instance.stop(AudioTween::default());
}
commands.entity(entity).despawn_recursive();
}
}

pub struct BgmPlugin;

impl Plugin for BgmPlugin {
Expand All @@ -112,9 +159,11 @@ impl Plugin for BgmPlugin {
.add_systems(
Update,
(
play_boss_bgm.run_if(in_state(GameState::Gaming)),
update_bgm_volumes.run_if(in_state(GameState::GameOver)),
mute_bgms.after(update_bgm_volumes),
unmute_bgms,
despawn_normal_bgm,
),
);
}
Expand Down
33 changes: 29 additions & 4 deletions src/enemy/demon_boss/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::{
};

const SCALE: f32 = 1.5;
const SPAWN_POS: Vec3 = Vec3::new(250.0, 0.0, 0.0);
const SPAWN_POS: Vec3 = Vec3::new(200.0, 0.0, 0.0);

#[derive(Component)]
struct Shadow;
Expand All @@ -25,11 +25,30 @@ struct DemonCollider;

#[derive(Component, Deref, DerefMut)]
struct SpawnDelay(Timer);
#[derive(Component)]
struct Smoke;

fn spawn_smokes(commands: &mut Commands, assets: &Res<GameAssets>, pos: Vec3) {
let mut animator = AnimationPlayer2D::default();
animator.play(assets.demon_boss_smoke_animations[0].clone());

commands.spawn((
Smoke,
animator,
YSort(1.0),
SpriteSheetBundle {
texture_atlas: assets.demon_boss_smoke.clone(),
transform: Transform::from_translation(pos).with_scale(Vec3::splat(5.0)),
..default()
},
));
}

fn spawn_demon_boss(
mut commands: Commands,
assets: Res<GameAssets>,
time: Res<Time>,
q_smoke: Query<Entity, (With<Smoke>, Without<SpawnDelay>)>,
mut q_delay: Query<(Entity, &mut SpawnDelay)>,
) {
let (entity, mut delay) = match q_delay.get_single_mut() {
Expand All @@ -43,6 +62,13 @@ fn spawn_demon_boss(
}
commands.entity(entity).despawn_recursive();

let pos = PLAYER_SPAWN_POS + SPAWN_POS;
if q_smoke.is_empty() {
spawn_smokes(&mut commands, &assets, pos);
commands.spawn(SpawnDelay(Timer::from_seconds(0.2, TimerMode::Once)));
return;
}

let mut animator = AnimationPlayer2D::default();
animator
.play(assets.enemy_boss_animations[0].clone())
Expand Down Expand Up @@ -83,8 +109,7 @@ fn spawn_demon_boss(
YSort(36.0 * SCALE * TRANSLATION_TO_PIXEL),
SpriteSheetBundle {
texture_atlas: assets.enemy_boss.clone(),
transform: Transform::from_translation(PLAYER_SPAWN_POS + SPAWN_POS)
.with_scale(Vec3::splat(SCALE)),
transform: Transform::from_translation(pos).with_scale(Vec3::splat(SCALE)),
..default()
},
))
Expand All @@ -100,7 +125,7 @@ fn spawn_demon_boss_delay(
}
ev_trigger_final_act.clear();

commands.spawn(SpawnDelay(Timer::from_seconds(3.5, TimerMode::Once)));
commands.spawn(SpawnDelay(Timer::from_seconds(5.0, TimerMode::Once)));
}

fn despawn_demon_boss(
Expand Down
4 changes: 2 additions & 2 deletions src/item/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ fn trigger_final_act(
CollisionEvent::Stopped(_, _, _) => continue,
};

if !(&player.collider_entity == source && &item_entity == target)
&& !(&player.collider_entity == target && &item_entity == source)
if !(&player.collider_entity == source && &item_entity == target
|| &player.collider_entity == target && &item_entity == source)
{
continue;
}
Expand Down

0 comments on commit 49a4c3b

Please sign in to comment.