Skip to content

Commit 0570763

Browse files
committedJul 26, 2024·
Add eighth-beat resolution
1 parent 9472ec2 commit 0570763

File tree

10 files changed

+31
-17
lines changed

10 files changed

+31
-17
lines changed
 

‎assets/config/card.ron

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
icon: "step",
5454
action: Step,
5555
action_config: CardActionConfig(
56-
remove_on_beat: 2,
56+
remove_on_beat: 8,
5757
),
5858
),
5959
"double_beat": Card(
@@ -63,7 +63,7 @@
6363
icon: "double_beat",
6464
action: DoubleBeat,
6565
action_config: CardActionConfig(
66-
remove_on_beat: 2,
66+
remove_on_beat: 4,
6767
attack: Attack (
6868
power: 2.0,
6969
force: 4.0,
@@ -77,7 +77,7 @@
7777
background: "pink",
7878
icon: "counter_point",
7979
action_config: CardActionConfig(
80-
remove_on_beat: 2,
80+
remove_on_beat: 16,
8181
),
8282
),
8383
"splits": Card(
@@ -87,7 +87,7 @@
8787
icon: "splits",
8888
modifier: 1.0,
8989
action_config: CardActionConfig(
90-
remove_on_beat: 2,
90+
remove_on_beat: 16,
9191
),
9292
),
9393
}

‎src/game/card/action.rs

+2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ impl Default for CardAction {
9191
#[derive(Default, Reflect, Serialize, Deserialize, Clone)]
9292
#[serde(default)]
9393
pub struct CardActionConfig {
94+
/// Remove component after this many eighth-beats.
9495
#[serde(default)]
9596
remove_on_beat: usize,
97+
/// Remove component when this timer finishes.
9698
#[serde(default)]
9799
remove_on_timer: Timer,
98100
#[serde(default)]

‎src/game/card/attack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Configure for DoubleBeat {
4747
Update,
4848
double_beat
4949
.in_set(UpdateSet::RecordInput)
50-
.run_if(on_beat(1)),
50+
.run_if(on_beat(4)),
5151
);
5252
}
5353
}

‎src/game/card/deck.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::core::UpdateSet;
77
use crate::game::actor::player::IsPlayer;
88
use crate::game::card::card;
99
use crate::game::card::AddCardEvent;
10-
use crate::game::music::beat::on_beat;
10+
use crate::game::music::beat::on_full_beat;
1111
use crate::util::prelude::*;
1212

1313
pub(super) fn plugin(app: &mut App) {
@@ -30,7 +30,9 @@ impl Configure for Deck {
3030
Update,
3131
(
3232
add_cards_to_deck.in_set(UpdateSet::SyncLate),
33-
advance_deck.in_set(UpdateSet::PlayCards).run_if(on_beat(2)),
33+
advance_deck
34+
.in_set(UpdateSet::PlayCards)
35+
.run_if(on_full_beat(2)),
3436
),
3537
);
3638
}

‎src/game/cleanup.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ fn apply_despawn_on_beat(
9494
mut despawn_query: Query<(Entity, &mut DespawnOnBeat)>,
9595
) {
9696
for (entity, mut beat) in &mut despawn_query {
97-
if beat.0 <= 1 {
97+
if beat.0 > 0 {
98+
beat.0 -= 1;
99+
} else {
98100
despawn.recursive(entity);
99101
}
100-
beat.0 = beat.0.saturating_sub(1);
101102
}
102103
}
103104

@@ -222,6 +223,7 @@ fn apply_remove_on_timer<C: Component + TypePath>(
222223
}
223224
}
224225

226+
/// Remove a component after a certain number of eighth-beats.
225227
#[derive(Component, Reflect)]
226228
#[reflect(Component)]
227229
pub struct RemoveOnBeat<C: Component + TypePath> {
@@ -260,9 +262,10 @@ fn apply_remove_on_beat<C: Component + TypePath>(
260262
mut remove_query: Query<(Entity, &mut RemoveOnBeat<C>)>,
261263
) {
262264
for (entity, mut remove) in &mut remove_query {
263-
if remove.beat <= 1 {
265+
if remove.beat > 0 {
266+
remove.beat -= 1;
267+
} else {
264268
commands.entity(entity).remove::<(C, RemoveOnBeat<C>)>();
265269
}
266-
remove.beat = remove.beat.saturating_sub(1);
267270
}
268271
}

‎src/game/music.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ impl Config for MusicConfig {
2828
world
2929
.resource_mut::<BeatTimer>()
3030
.0
31-
.set_duration(Duration::from_secs_f32(60.0 / self.bpm));
31+
.set_duration(Duration::from_secs_f32(60.0 / 8.0 / self.bpm));
3232
}
3333
}

‎src/game/music/beat.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ fn pause_beat_timer(mut beat_timer: ResMut<BeatTimer>) {
5151
#[derive(Resource, Reflect, Default)]
5252
#[reflect(Resource)]
5353
pub struct Beat {
54+
/// The total number of eighth-beats counted.
5455
pub total: usize,
56+
/// The number of eighth-beats finished this tick (usually 0 or 1).
5557
pub this_tick: usize,
5658
}
5759

@@ -68,11 +70,16 @@ fn update_beat(beat_timer: Res<BeatTimer>, mut beat: ResMut<Beat>) {
6870
beat.total += beat.this_tick;
6971
}
7072

71-
/// A run condition to run a system every `n` beats.
73+
/// A run condition to run a system every `n` eighth-beats.
7274
pub fn on_beat(n: usize) -> impl Fn(Res<Beat>) -> bool {
7375
move |beat| {
7476
let hi = beat.total;
7577
let lo = hi - beat.this_tick;
7678
hi / n > lo / n
7779
}
7880
}
81+
82+
/// A run condition to run a system every `n` beats.
83+
pub fn on_full_beat(n: usize) -> impl Fn(Res<Beat>) -> bool {
84+
on_beat(8 * n)
85+
}

‎src/game/spotlight.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl Configure for IsSpotlightLampSpawner {
141141
Update,
142142
spawn_spotlight_lamps
143143
.in_set(UpdateSet::Update)
144-
.run_if(not(any_with_component::<Spotlight>).or_else(on_beat(1))),
144+
.run_if(not(any_with_component::<Spotlight>).or_else(on_beat(4))),
145145
);
146146
}
147147
}

‎src/game/sprite.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl Configure for SpriteAnimation {
3232
Update,
3333
update_sprite_animation
3434
.in_set(UpdateSet::Update)
35-
.run_if(on_beat(1)),
35+
.run_if(on_beat(4)),
3636
);
3737
}
3838
}

‎src/game/wave.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::core::camera::CameraRoot;
99
use crate::core::UpdateSet;
1010
use crate::game::actor::enemy::enemy;
1111
use crate::game::actor::level::Level;
12-
use crate::game::music::beat::on_beat;
12+
use crate::game::music::beat::on_full_beat;
1313
use crate::screen::Screen;
1414
use crate::util::prelude::*;
1515

@@ -63,7 +63,7 @@ impl Configure for Wave {
6363
Screen::Playing.on_update(
6464
spawn_wave_enemies
6565
.in_set(UpdateSet::Update)
66-
.run_if(on_beat(2)),
66+
.run_if(on_full_beat(1)),
6767
),
6868
);
6969
}

0 commit comments

Comments
 (0)
Please sign in to comment.