Skip to content

Commit

Permalink
Add ultrafast transition option.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramirisu committed Sep 9, 2024
1 parent 597774b commit b5737a0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/game/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,6 @@ impl Board {

impl Default for Board {
fn default() -> Self {
Self::new(0, Transition::Classic)
Self::new(0, Transition::Default)
}
}
2 changes: 1 addition & 1 deletion src/game/drop_speed.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum DropSpeed {
Classic,
Level,
Locked,
}
4 changes: 2 additions & 2 deletions src/game/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ impl Default for PlayerConfig {
Self {
start_level: 0,
lv39_linecap: false,
transition: Transition::Classic,
drop_speed: DropSpeed::Classic,
transition: Transition::Default,
drop_speed: DropSpeed::Level,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/tick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl FallTick {
pub fn set_level(&mut self, level: usize) {
self.initial_entry_delay = false;
match self.drop_speed {
DropSpeed::Classic => self.threshold = Self::get_trigger_tick(level, self.lv39_linecap),
DropSpeed::Level => self.threshold = Self::get_trigger_tick(level, self.lv39_linecap),
DropSpeed::Locked => (),
}
}
Expand Down
22 changes: 12 additions & 10 deletions src/game/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ use std::fmt::Display;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Transition {
Classic,
Fast,
Default,
Every10Lines,
Every4Lines,
}

impl Transition {
pub fn get_level(&self, start_level: usize, lines: usize) -> usize {
match self {
Transition::Classic => Self::get_level_classic(start_level, lines),
Transition::Fast => Self::get_level_fast(start_level, lines),
Transition::Default => Self::get_level_classic(start_level, lines),
Transition::Every10Lines => Self::get_level_every_n_lines(start_level, lines, 10),
Transition::Every4Lines => Self::get_level_every_n_lines(start_level, lines, 4),
}
}

Expand All @@ -35,8 +37,8 @@ impl Transition {
start_level
}

fn get_level_fast(start_level: usize, lines: usize) -> usize {
start_level + lines / 10
fn get_level_every_n_lines(start_level: usize, lines: usize, every: usize) -> usize {
start_level + lines / every
}
}

Expand All @@ -51,8 +53,8 @@ mod tests {
use super::*;

#[test]
fn classic() {
let transition = Transition::Classic;
fn test_default() {
let transition = Transition::Default;

assert_eq!(transition.get_level(0, 0), 0);
assert_eq!(transition.get_level(0, 10), 1);
Expand Down Expand Up @@ -123,8 +125,8 @@ mod tests {
}

#[test]
fn fast() {
let transition = Transition::Fast;
fn test_every_n_lines() {
let transition = Transition::Every10Lines;

assert_eq!(transition.get_level(0, 0), 0);
assert_eq!(transition.get_level(0, 10), 1);
Expand Down
34 changes: 24 additions & 10 deletions src/game_option_menu/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ impl GameOptionMenuData {
pub fn new() -> Self {
Self {
state: GameOptionMenuState::default(),
transition: Transition::Classic,
transition: Transition::Default,
lv39_linecap: false,
drop_speed: DropSpeed::Classic,
drop_speed: DropSpeed::Level,
#[cfg(not(target_arch = "wasm32"))]
window_mode: WindowMode::Windowed,
}
Expand Down Expand Up @@ -200,8 +200,13 @@ fn update_ui_system(
GameOptionMenuState::Transition => {
text.sections[0].value = fname("TRANSITION");
match game_option_menu_data.transition {
Transition::Classic => text.sections[1].value = fopt("CLASSIC", false, true),
Transition::Fast => text.sections[1].value = fopt("FAST", true, false),
Transition::Default => text.sections[1].value = fopt("DEFAULT", false, true),
Transition::Every10Lines => {
text.sections[1].value = fopt("10 LINES", true, false)
}
Transition::Every4Lines => {
text.sections[1].value = fopt(" 4 LINES", true, false)
}
};
}
GameOptionMenuState::Linecap => {
Expand All @@ -215,7 +220,7 @@ fn update_ui_system(
GameOptionMenuState::DropSpeed => {
text.sections[0].value = fname("DROPSPEED");
match game_option_menu_data.drop_speed {
DropSpeed::Classic => text.sections[1].value = fopt("CLASSIC", false, true),
DropSpeed::Level => text.sections[1].value = fopt("LEVEL", false, true),
DropSpeed::Locked => text.sections[1].value = fopt("LOCKED", true, false),
};
}
Expand Down Expand Up @@ -284,15 +289,24 @@ fn handle_input_system(
e_play_sound.send(PlaySoundEvent::MoveCursor);
}
match game_option_menu_data.transition {
Transition::Classic => {
Transition::Default => {
if player_inputs.right.0 {
game_option_menu_data.transition = Transition::Every10Lines;
e_play_sound.send(PlaySoundEvent::MoveCursor);
}
}
Transition::Every10Lines => {
if player_inputs.right.0 {
game_option_menu_data.transition = Transition::Fast;
game_option_menu_data.transition = Transition::Every4Lines;
e_play_sound.send(PlaySoundEvent::MoveCursor);
} else if player_inputs.left.0 {
game_option_menu_data.transition = Transition::Default;
e_play_sound.send(PlaySoundEvent::MoveCursor);
}
}
Transition::Fast => {
Transition::Every4Lines => {
if player_inputs.left.0 {
game_option_menu_data.transition = Transition::Classic;
game_option_menu_data.transition = Transition::Every10Lines;
e_play_sound.send(PlaySoundEvent::MoveCursor);
}
}
Expand Down Expand Up @@ -333,7 +347,7 @@ fn handle_input_system(
game_option_menu_data.drop_speed = DropSpeed::Locked;
e_play_sound.send(PlaySoundEvent::MoveCursor);
} else if player_inputs.left.0 {
game_option_menu_data.drop_speed = DropSpeed::Classic;
game_option_menu_data.drop_speed = DropSpeed::Level;
e_play_sound.send(PlaySoundEvent::MoveCursor);
}
}
Expand Down

0 comments on commit b5737a0

Please sign in to comment.