From b5737a0458cf92bf49448c814409d155589aeb91 Mon Sep 17 00:00:00 2001 From: Ramirisu Date: Tue, 10 Sep 2024 06:12:38 +0800 Subject: [PATCH] Add ultrafast transition option. --- src/game/board.rs | 2 +- src/game/drop_speed.rs | 2 +- src/game/player.rs | 4 ++-- src/game/tick.rs | 2 +- src/game/transition.rs | 22 ++++++++++++---------- src/game_option_menu/plugin.rs | 34 ++++++++++++++++++++++++---------- 6 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/game/board.rs b/src/game/board.rs index 98e71a6..b37f28a 100644 --- a/src/game/board.rs +++ b/src/game/board.rs @@ -278,6 +278,6 @@ impl Board { impl Default for Board { fn default() -> Self { - Self::new(0, Transition::Classic) + Self::new(0, Transition::Default) } } diff --git a/src/game/drop_speed.rs b/src/game/drop_speed.rs index 1b4f139..0620e8c 100644 --- a/src/game/drop_speed.rs +++ b/src/game/drop_speed.rs @@ -1,5 +1,5 @@ #[derive(Clone, Copy, PartialEq, Eq)] pub enum DropSpeed { - Classic, + Level, Locked, } diff --git a/src/game/player.rs b/src/game/player.rs index 90ac79a..740aeb4 100644 --- a/src/game/player.rs +++ b/src/game/player.rs @@ -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, } } } diff --git a/src/game/tick.rs b/src/game/tick.rs index 430e4ff..67eee82 100644 --- a/src/game/tick.rs +++ b/src/game/tick.rs @@ -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 => (), } } diff --git a/src/game/transition.rs b/src/game/transition.rs index ee75e79..656b74b 100644 --- a/src/game/transition.rs +++ b/src/game/transition.rs @@ -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), } } @@ -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 } } @@ -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); @@ -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); diff --git a/src/game_option_menu/plugin.rs b/src/game_option_menu/plugin.rs index 6921a8d..7eb9e32 100644 --- a/src/game_option_menu/plugin.rs +++ b/src/game_option_menu/plugin.rs @@ -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, } @@ -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 => { @@ -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), }; } @@ -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); } } @@ -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); } }