Skip to content

Commit 7f29752

Browse files
committed
Fix various bugs
1 parent 7d36ffc commit 7f29752

File tree

8 files changed

+63
-37
lines changed

8 files changed

+63
-37
lines changed

src/game/actor.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use crate::game::actor::movement::MovementController;
3030
use crate::game::actor::movement::OldMovementController;
3131
use crate::game::audio::music::Beat;
3232
use crate::game::card::deck::Deck;
33-
use crate::game::combat::death::DespawnOnDeath;
3433
use crate::game::combat::hit::Hurtbox;
3534
use crate::game::sprite::SpriteAnimation;
3635
use crate::util::prelude::*;
@@ -142,8 +141,7 @@ impl EntityCommand for Actor {
142141
AttackController::default(),
143142
self.health,
144143
Hurtbox,
145-
// TODO: Death animation instead, despawn when it's finished.
146-
DespawnOnDeath,
144+
// TODO: Death animation.
147145
),
148146
// Inventory:
149147
(Level::default(), Xp::default(), self.xp_reward, self.deck),

src/game/actor/enemy.rs

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use bevy::prelude::*;
55
use crate::game::actor::facing::FacePlayer;
66
use crate::game::actor::faction::Faction;
77
use crate::game::actor::ActorConfig;
8+
use crate::game::combat::death::DespawnOnDeath;
89
use crate::game::GameLayer;
910
use crate::game::GameRoot;
1011
use crate::util::prelude::*;
@@ -41,6 +42,8 @@ pub fn enemy(key: impl Into<String>) -> impl EntityCommand<World> {
4142
Faction::Enemy,
4243
CollisionLayers::new(GameLayer::Enemy, LayerMask::ALL),
4344
FacePlayer,
45+
// TODO: Despawn when death animation is finished, instead.
46+
DespawnOnDeath,
4447
))
4548
.set_parent(parent);
4649
}

src/game/audio/music.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use pyri_state::prelude::*;
55
use crate::core::pause::Pause;
66
use crate::core::UpdateSet;
77
use crate::game::audio::AudioConfig;
8+
use crate::screen::playing::PlayingAssets;
89
use crate::screen::Screen;
910
use crate::util::prelude::*;
1011

@@ -36,17 +37,22 @@ pub fn stop_music(
3637
mut audio_instances: ResMut<Assets<AudioInstance>>,
3738
) {
3839
let music = r!(audio_instances.get_mut(&music_handle.0));
39-
music.seek_to(0.0);
40-
music.pause(AudioTween::default());
40+
music.stop(AudioTween::default());
4141
}
4242

4343
pub fn start_music(
44-
music_handle: Res<MusicHandle>,
45-
mut audio_instances: ResMut<Assets<AudioInstance>>,
44+
config: ConfigRef<AudioConfig>,
45+
audio: Res<Audio>,
46+
assets: Res<PlayingAssets>,
47+
mut music_handle: ResMut<MusicHandle>,
4648
) {
47-
let music = r!(audio_instances.get_mut(&music_handle.0));
48-
music.seek_to(0.0);
49-
music.resume(AudioTween::default());
49+
let config = r!(config.get());
50+
music_handle.0 = audio
51+
.play(assets.music.clone())
52+
.with_volume(config.music_volume)
53+
.loop_from(config.music_loop_start)
54+
.loop_until(config.music_loop_end)
55+
.handle();
5056
}
5157

5258
pub fn pause_music(

src/game/combat/death.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,15 @@ impl Configure for DespawnOnDeath {
4040
}
4141
}
4242

43-
fn despawn_on_death(trigger: Trigger<OnDeath>, mut despawn: ResMut<LateDespawn>) {
44-
despawn.recursive(r!(trigger.get_entity()));
43+
fn despawn_on_death(
44+
trigger: Trigger<OnDeath>,
45+
despawn_query: Query<(), With<DespawnOnDeath>>,
46+
mut despawn: ResMut<LateDespawn>,
47+
) {
48+
let entity = r!(trigger.get_entity());
49+
if despawn_query.contains(entity) {
50+
despawn.recursive(entity);
51+
}
4552
}
4653

4754
#[derive(Component, Reflect)]

src/screen/playing.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,18 @@ impl Configure for PlayingAction {
127127
app.add_plugins(InputManagerPlugin::<Self>::default());
128128
app.add_systems(
129129
StateFlush,
130-
PlayingMenu::Pause
131-
.toggle()
132-
.in_set(ResolveStateSet::<PlayingMenu>::Compute)
133-
.run_if(
134-
Screen::Playing
135-
.will_exit()
136-
.and_then(not(PlayingMenu::LevelUp.will_exit()))
137-
.and_then(action_just_pressed(Self::TogglePause)),
138-
),
130+
(
131+
Screen::Playing.on_exit(PlayingMenu::disable),
132+
PlayingMenu::Pause
133+
.toggle()
134+
.in_set(ResolveStateSet::<PlayingMenu>::Compute)
135+
.run_if(
136+
PlayingMenu::is_disabled
137+
.or_else(PlayingMenu::Pause.will_exit())
138+
.and_then(Screen::Playing.will_enter())
139+
.and_then(action_just_pressed(Self::TogglePause)),
140+
),
141+
),
139142
);
140143
}
141144
}

src/screen/playing/defeat_menu.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use pyri_state::extra::entity_scope::StateScope;
55
use pyri_state::prelude::*;
66

77
use crate::core::pause::Pause;
8-
use crate::core::UpdateSet;
98
use crate::game::actor::player::IsPlayer;
9+
use crate::game::combat::death::OnDeath;
1010
use crate::screen::fade_out;
1111
use crate::screen::playing::PlayingAssets;
1212
use crate::screen::playing::PlayingMenu;
@@ -15,29 +15,32 @@ use crate::ui::prelude::*;
1515
use crate::util::prelude::*;
1616

1717
pub(super) fn plugin(app: &mut App) {
18+
app.observe(detect_defeat);
19+
1820
app.add_systems(
1921
StateFlush,
2022
PlayingMenu::Defeat.on_edge(Pause::disable, (Pause::enable_default, open_defeat_menu)),
2123
);
24+
}
2225

23-
app.add_systems(
24-
Update,
25-
PlayingMenu::Defeat
26-
.enter()
27-
.in_set(UpdateSet::SyncLate)
28-
.run_if(detect_defeat),
29-
);
26+
fn detect_defeat(
27+
trigger: Trigger<OnDeath>,
28+
player_query: Query<(), With<IsPlayer>>,
29+
mut playing_menu: NextMut<PlayingMenu>,
30+
) {
31+
let entity = r!(trigger.get_entity());
32+
if !player_query.contains(entity) {
33+
return;
34+
}
35+
36+
playing_menu.enter(PlayingMenu::Defeat);
3037
}
3138

3239
fn open_defeat_menu(mut commands: Commands, ui_root: Res<UiRoot>) {
3340
commands.spawn_with(defeat_overlay).set_parent(ui_root.body);
3441
commands.spawn_with(defeat_menu).set_parent(ui_root.body);
3542
}
3643

37-
pub fn detect_defeat(player_query: Query<Entity, With<IsPlayer>>) -> bool {
38-
player_query.is_empty()
39-
}
40-
4144
fn defeat_overlay(mut entity: EntityWorldMut) {
4245
entity.add(widget::blocking_overlay).insert((
4346
Name::new("DefeatOverlay"),
@@ -126,7 +129,9 @@ fn restart_button(mut entity: EntityWorldMut) {
126129

127130
fn quit_to_title_button(mut entity: EntityWorldMut) {
128131
entity.add(widget::menu_button("Quit to title")).insert((
129-
On::<Pointer<Click>>::run(Screen::Title.enter()),
132+
On::<Pointer<Click>>::run(|mut commands: Commands| {
133+
commands.spawn_with(fade_out(Screen::Title));
134+
}),
130135
Style {
131136
height: Vw(9.0),
132137
width: Vw(38.0),

src/screen/playing/pause_menu.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn pause_menu(mut entity: EntityWorldMut) {
5151
});
5252
}
5353

54-
const HEADER: &str = "Paused :)";
54+
const HEADER: &str = "Paused :|";
5555

5656
fn header(mut entity: EntityWorldMut) {
5757
entity.insert((
@@ -133,7 +133,9 @@ fn restart_button(mut entity: EntityWorldMut) {
133133

134134
fn quit_to_title_button(mut entity: EntityWorldMut) {
135135
entity.add(widget::menu_button("Quit to title")).insert((
136-
On::<Pointer<Click>>::run(Screen::Title.enter()),
136+
On::<Pointer<Click>>::run(|mut commands: Commands| {
137+
commands.spawn_with(fade_out(Screen::Title));
138+
}),
137139
Style {
138140
height: Vw(9.0),
139141
width: Vw(38.0),

src/screen/playing/victory_menu.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ fn restart_button(mut entity: EntityWorldMut) {
165165

166166
fn quit_to_title_button(mut entity: EntityWorldMut) {
167167
entity.add(widget::menu_button("Quit to title")).insert((
168-
On::<Pointer<Click>>::run(Screen::Title.enter()),
168+
On::<Pointer<Click>>::run(|mut commands: Commands| {
169+
commands.spawn_with(fade_out(Screen::Title));
170+
}),
169171
Style {
170172
height: Vw(9.0),
171173
width: Vw(38.0),

0 commit comments

Comments
 (0)