Skip to content

Commit

Permalink
Adjust soft reset buttons.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramirisu committed Sep 16, 2024
1 parent 5102a3f commit 672ca60
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 37 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ A Classic Tetris (NES Tetris) clone written in BEVY/RUST.

## Keybindings

| Menu | In Game | Keyboard | Controller Type A (NES) | Controller Type B (NES) |
| :--------- | :------------------------ | :--------------: | :---------------------: | :---------------------: |
| Move Up | ||||
| Move Down | Soft Drop ||||
| Move Left | Move Left ||||
| Move Right | Move Right ||||
| | Rotate Clockwisely | X | A | B |
| Back | Rotate Counterclockwisely | Z | B | Y |
| Start | Pause/Resume | Enter | Start | Start |
| Soft Reset | Soft Reset | Left Shift / Esc | Select | Select |
| Menu | In Game | Keyboard | Controller: Type A | Controller: Type B |
| :--------- | :------------------------ | :------: | :--------------------: | :--------------------: |
| Move Up | ||||
| Move Down | Soft Drop ||||
| Move Left | Move Left ||||
| Move Right | Move Right ||||
| | Rotate Clockwisely | X | A (→) | B (↓) |
| Back | Rotate Counterclockwisely | Z | B (↓) | Y (←) |
| Start | Pause/Resume | Enter | Start | Start |
| Soft Reset | Soft Reset | Esc | Select + Start + A + B | Select + Start + B + Y |

> A, B, X and Y button mapping is in NES/SNES/NSwitch Controller layout.
## Build & Run

Expand Down
22 changes: 22 additions & 0 deletions src/game/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,18 @@ mod state_game_running {
mut e_play_sound: EventWriter<PlaySoundEvent>,
mut player_data: ResMut<PlayerData>,
mut player_state: ResMut<NextState<PlayerState>>,
mut app_state: ResMut<NextState<AppState>>,
square_image_assets: Res<SquareImageAssets>,
) {
let player_inputs = PlayerInputs::with_keyboard(&keys)
| PlayerInputs::with_gamepads(&buttons, &controller, *controller_type);

if player_inputs.soft_reset {
e_play_sound.send(PlaySoundEvent::StartGame);
app_state.set(AppState::Splash);
return;
}

if player_inputs.start {
*query.p1().single_mut() = Visibility::Inherited;
player_state.set(PlayerState::GamePause);
Expand Down Expand Up @@ -839,11 +846,19 @@ mod state_game_pause {
controller: Res<Controller>,
controller_type: Res<ControllerType>,
mut query: ParamSet<(Query<&mut Visibility, With<BoardCoverEntityMarker>>,)>,
mut e_play_sound: EventWriter<PlaySoundEvent>,
mut player_state: ResMut<NextState<PlayerState>>,
mut app_state: ResMut<NextState<AppState>>,
) {
let player_inputs = PlayerInputs::with_keyboard(&keys)
| PlayerInputs::with_gamepads(&buttons, &controller, *controller_type);

if player_inputs.soft_reset {
e_play_sound.send(PlaySoundEvent::StartGame);
app_state.set(AppState::Splash);
return;
}

if player_inputs.start {
*query.p0().single_mut() = Visibility::Hidden;
player_state.set(PlayerState::GameRunning);
Expand All @@ -859,11 +874,18 @@ mod state_game_over {
buttons: Res<ButtonInput<GamepadButton>>,
controller: Res<Controller>,
controller_type: Res<ControllerType>,
mut e_play_sound: EventWriter<PlaySoundEvent>,
mut app_state: ResMut<NextState<AppState>>,
) {
let player_inputs = PlayerInputs::with_keyboard(&keys)
| PlayerInputs::with_gamepads(&buttons, &controller, *controller_type);

if player_inputs.soft_reset {
e_play_sound.send(PlaySoundEvent::StartGame);
app_state.set(AppState::Splash);
return;
}

if player_inputs.start {
app_state.set(AppState::LevelMenu);
}
Expand Down
6 changes: 6 additions & 0 deletions src/game_option_menu/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ fn handle_input_system(
let player_inputs = PlayerInputs::with_keyboard(&keys)
| PlayerInputs::with_gamepads(&buttons, &controller, *controller_type);

if player_inputs.soft_reset {
e_play_sound.send(PlaySoundEvent::StartGame);
app_state.set(AppState::Splash);
return;
}

if player_inputs.b.0 {
app_state.set(AppState::Splash);
e_play_sound.send(PlaySoundEvent::StartGame);
Expand Down
15 changes: 9 additions & 6 deletions src/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ impl PlayerInputs {
),
start: inputs.just_pressed(KeyCode::Enter),
select: inputs.just_pressed(KeyCode::ShiftLeft),
soft_reset: inputs.just_pressed(KeyCode::ShiftLeft)
|| inputs.just_pressed(KeyCode::Escape),
soft_reset: inputs.just_pressed(KeyCode::Escape),
}
}

Expand Down Expand Up @@ -126,8 +125,10 @@ impl PlayerInputs {
),
start: buttons.just_pressed(Self::gamepad_button(gamepad, GamepadButtonType::Start)),
select: buttons.just_pressed(Self::gamepad_button(gamepad, GamepadButtonType::Select)),
soft_reset: buttons
.just_pressed(Self::gamepad_button(gamepad, GamepadButtonType::Select)),
soft_reset: buttons.pressed(Self::gamepad_button(gamepad, GamepadButtonType::Select))
&& buttons.pressed(Self::gamepad_button(gamepad, GamepadButtonType::Start))
&& buttons.pressed(Self::gamepad_button(gamepad, GamepadButtonType::East))
&& buttons.pressed(Self::gamepad_button(gamepad, GamepadButtonType::South)),
}
}

Expand Down Expand Up @@ -159,8 +160,10 @@ impl PlayerInputs {
),
start: buttons.just_pressed(Self::gamepad_button(gamepad, GamepadButtonType::Start)),
select: buttons.just_pressed(Self::gamepad_button(gamepad, GamepadButtonType::Select)),
soft_reset: buttons
.just_pressed(Self::gamepad_button(gamepad, GamepadButtonType::Select)),
soft_reset: buttons.pressed(Self::gamepad_button(gamepad, GamepadButtonType::Select))
&& buttons.pressed(Self::gamepad_button(gamepad, GamepadButtonType::Start))
&& buttons.pressed(Self::gamepad_button(gamepad, GamepadButtonType::South))
&& buttons.pressed(Self::gamepad_button(gamepad, GamepadButtonType::West)),
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/level_menu/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ fn handle_input_system(
let player_inputs = PlayerInputs::with_keyboard(&keys)
| PlayerInputs::with_gamepads(&buttons, &controller, *controller_type);

if player_inputs.soft_reset {
e_play_sound.send(PlaySoundEvent::StartGame);
app_state.set(AppState::Splash);
return;
}

match (player_inputs.up.0, player_inputs.down.0) {
(true, false) => {
level_menu_data.selected_level.1 =
Expand Down
21 changes: 0 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use audio::plugin::PlaySoundEvent;
use bevy::{
color::palettes::css::GREEN,
prelude::*,
Expand All @@ -18,8 +17,6 @@ mod utility;

use app_state::AppState;
use bevy_dev_tools::fps_overlay::{FpsOverlayConfig, FpsOverlayPlugin};
use controller::Controller;
use inputs::{ControllerType, PlayerInputs};

fn main() {
App::new()
Expand Down Expand Up @@ -48,7 +45,6 @@ fn main() {
.insert_resource(ClearColor(Color::BLACK)) // application background color
.init_state::<AppState>()
.add_systems(Startup, setup_camera)
.add_systems(Update, handle_input_system)
.add_plugins((
controller::setup,
inputs::setup,
Expand All @@ -64,20 +60,3 @@ fn main() {
fn setup_camera(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
}

fn handle_input_system(
keys: Res<ButtonInput<KeyCode>>,
buttons: Res<ButtonInput<GamepadButton>>,
controller: Res<Controller>,
controller_type: Res<ControllerType>,
mut e_play_sound: EventWriter<PlaySoundEvent>,
mut app_state: ResMut<NextState<AppState>>,
) {
let player_inputs = PlayerInputs::with_keyboard(&keys)
| PlayerInputs::with_gamepads(&buttons, &controller, *controller_type);

if player_inputs.soft_reset {
e_play_sound.send(PlaySoundEvent::StartGame);
app_state.set(AppState::Splash);
}
}
2 changes: 2 additions & 0 deletions src/splash/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use bevy::{color::palettes::css::WHITE, prelude::*};

use crate::{
app_state::AppState,
audio::plugin::PlaySoundEvent,
controller::Controller,
inputs::{ControllerType, PlayerInputs},
logo::{load_logo_images, TETRIS_BITMAP},
Expand Down Expand Up @@ -93,6 +94,7 @@ fn handle_input_system(
controller: Res<Controller>,
controller_type: Res<ControllerType>,
mut app_state: ResMut<NextState<AppState>>,
mut e_play_sound: EventWriter<PlaySoundEvent>,
) {
let player_inputs = PlayerInputs::with_keyboard(&keys)
| PlayerInputs::with_gamepads(&buttons, &controller, *controller_type);
Expand Down

0 comments on commit 672ca60

Please sign in to comment.