mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2025-01-06 02:56:41 +00:00
Added strafing
This commit is contained in:
parent
befac5db85
commit
f26f019584
|
@ -64,6 +64,10 @@ impl PlayerController for DummyPlayerController {
|
|||
false
|
||||
}
|
||||
|
||||
fn strafe(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn trigger_up(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
@ -108,6 +112,10 @@ impl PlayerController for DummyPlayerController {
|
|||
false
|
||||
}
|
||||
|
||||
fn trigger_strafe(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn trigger_menu_ok(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use crate::bitfield;
|
||||
use crate::input::player_controller::PlayerController;
|
||||
use crate::player::TargetPlayer;
|
||||
use crate::shared_game_state::SharedGameState;
|
||||
use crate::framework::context::Context;
|
||||
use crate::framework::error::GameResult;
|
||||
use crate::framework::keyboard;
|
||||
use crate::framework::keyboard::ScanCode;
|
||||
use crate::input::player_controller::PlayerController;
|
||||
use crate::player::TargetPlayer;
|
||||
use crate::shared_game_state::SharedGameState;
|
||||
|
||||
bitfield! {
|
||||
#[derive(Clone, Copy)]
|
||||
|
@ -25,6 +25,7 @@ bitfield! {
|
|||
pub escape, set_escape: 10;
|
||||
pub enter, set_enter: 11;
|
||||
pub skip, set_skip: 12;
|
||||
pub strafe, set_strafe: 13;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -37,12 +38,7 @@ pub struct KeyboardController {
|
|||
|
||||
impl KeyboardController {
|
||||
pub fn new(target: TargetPlayer) -> KeyboardController {
|
||||
KeyboardController {
|
||||
target,
|
||||
state: KeyState(0),
|
||||
old_state: KeyState(0),
|
||||
trigger: KeyState(0),
|
||||
}
|
||||
KeyboardController { target, state: KeyState(0), old_state: KeyState(0), trigger: KeyState(0) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,6 +62,7 @@ impl PlayerController for KeyboardController {
|
|||
self.state.set_next_weapon(keyboard::is_key_pressed(ctx, keymap.next_weapon));
|
||||
self.state.set_enter(keyboard::is_key_pressed(ctx, ScanCode::Return));
|
||||
self.state.set_escape(keyboard::is_key_pressed(ctx, ScanCode::Escape));
|
||||
self.state.set_strafe(keyboard::is_key_pressed(ctx, keymap.strafe));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -121,6 +118,10 @@ impl PlayerController for KeyboardController {
|
|||
self.state.skip()
|
||||
}
|
||||
|
||||
fn strafe(&self) -> bool {
|
||||
self.state.strafe()
|
||||
}
|
||||
|
||||
fn trigger_up(&self) -> bool {
|
||||
self.trigger.up()
|
||||
}
|
||||
|
@ -165,6 +166,10 @@ impl PlayerController for KeyboardController {
|
|||
self.trigger.skip()
|
||||
}
|
||||
|
||||
fn trigger_strafe(&self) -> bool {
|
||||
self.trigger.strafe()
|
||||
}
|
||||
|
||||
fn trigger_menu_ok(&self) -> bool {
|
||||
self.trigger.jump() || self.trigger.enter()
|
||||
}
|
||||
|
|
|
@ -41,6 +41,9 @@ pub trait PlayerController: PlayerControllerClone {
|
|||
/// True if "skip" button is down.
|
||||
fn skip(&self) -> bool;
|
||||
|
||||
/// True if "strafe" button is down.
|
||||
fn strafe(&self) -> bool;
|
||||
|
||||
fn trigger_up(&self) -> bool;
|
||||
|
||||
fn trigger_left(&self) -> bool;
|
||||
|
@ -63,6 +66,8 @@ pub trait PlayerController: PlayerControllerClone {
|
|||
|
||||
fn trigger_skip(&self) -> bool;
|
||||
|
||||
fn trigger_strafe(&self) -> bool;
|
||||
|
||||
fn trigger_menu_ok(&self) -> bool;
|
||||
|
||||
fn trigger_menu_back(&self) -> bool;
|
||||
|
|
|
@ -278,6 +278,11 @@ impl PlayerController for TouchPlayerController {
|
|||
false
|
||||
}
|
||||
|
||||
fn strafe(&self) -> bool {
|
||||
// TODO
|
||||
false
|
||||
}
|
||||
|
||||
fn trigger_up(&self) -> bool {
|
||||
self.trigger.up()
|
||||
}
|
||||
|
@ -323,6 +328,11 @@ impl PlayerController for TouchPlayerController {
|
|||
false
|
||||
}
|
||||
|
||||
fn trigger_strafe(&self) -> bool {
|
||||
// TODO
|
||||
false
|
||||
}
|
||||
|
||||
fn trigger_menu_ok(&self) -> bool {
|
||||
self.trigger.jump()
|
||||
}
|
||||
|
|
|
@ -86,6 +86,7 @@ pub struct Player {
|
|||
pub skin: Box<dyn PlayerSkin>,
|
||||
pub controller: Box<dyn PlayerController>,
|
||||
pub popup: NumberPopup,
|
||||
strafe_up: bool,
|
||||
weapon_offset_y: i8,
|
||||
splash: bool,
|
||||
tick: u8,
|
||||
|
@ -141,6 +142,7 @@ impl Player {
|
|||
skin,
|
||||
controller: Box::new(DummyPlayerController::new()),
|
||||
popup: NumberPopup::new(),
|
||||
strafe_up: false,
|
||||
damage_counter: 0,
|
||||
damage_taken: 0,
|
||||
anim_num: 0,
|
||||
|
@ -202,6 +204,16 @@ impl Player {
|
|||
self.booster_switch = BoosterSwitch::None;
|
||||
}
|
||||
|
||||
if state.control_flags.control_enabled() {
|
||||
if self.controller.move_up() && self.controller.trigger_strafe() {
|
||||
self.strafe_up = true;
|
||||
} else if !self.controller.strafe() {
|
||||
self.strafe_up = false;
|
||||
}
|
||||
} else {
|
||||
self.strafe_up = false;
|
||||
}
|
||||
|
||||
// ground movement
|
||||
if self.flags.hit_bottom_wall() || self.flags.hit_right_slope() || self.flags.hit_left_slope() {
|
||||
self.booster_switch = BoosterSwitch::None;
|
||||
|
@ -241,12 +253,14 @@ impl Player {
|
|||
self.vel_x += physics.dash_ground;
|
||||
}
|
||||
|
||||
if self.controller.move_left() {
|
||||
self.direction = Direction::Left;
|
||||
}
|
||||
if !self.controller.strafe() {
|
||||
if self.controller.move_left() {
|
||||
self.direction = Direction::Left;
|
||||
}
|
||||
|
||||
if self.controller.move_right() {
|
||||
self.direction = Direction::Right;
|
||||
if self.controller.move_right() {
|
||||
self.direction = Direction::Right;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -310,12 +324,14 @@ impl Player {
|
|||
self.vel_x += physics.dash_air;
|
||||
}
|
||||
|
||||
if self.controller.look_left() {
|
||||
self.direction = Direction::Left;
|
||||
}
|
||||
if !self.controller.strafe() {
|
||||
if self.controller.look_left() {
|
||||
self.direction = Direction::Left;
|
||||
}
|
||||
|
||||
if self.controller.look_right() {
|
||||
self.direction = Direction::Right;
|
||||
if self.controller.look_right() {
|
||||
self.direction = Direction::Right;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -337,7 +353,7 @@ impl Player {
|
|||
|
||||
// jumping
|
||||
if state.control_flags.control_enabled() {
|
||||
self.up = self.controller.move_up();
|
||||
self.up = self.controller.move_up() || self.strafe_up;
|
||||
self.down = self.controller.move_down() && !self.flags.hit_bottom_wall();
|
||||
|
||||
if self.controller.trigger_jump()
|
||||
|
@ -674,7 +690,7 @@ impl Player {
|
|||
self.anim_num = 0;
|
||||
self.anim_counter = 0;
|
||||
} else if state.control_flags.control_enabled()
|
||||
&& self.controller.move_up()
|
||||
&& (self.controller.move_up() || self.strafe_up)
|
||||
&& (self.controller.move_left() || self.controller.move_right())
|
||||
{
|
||||
self.cond.set_fallen(true);
|
||||
|
@ -712,7 +728,7 @@ impl Player {
|
|||
if self.anim_num > 4 || self.anim_num < 1 {
|
||||
self.anim_num = 1;
|
||||
}
|
||||
} else if state.control_flags.control_enabled() && self.controller.move_up() {
|
||||
} else if state.control_flags.control_enabled() && (self.controller.move_up() || self.strafe_up) {
|
||||
if self.cond.fallen() {
|
||||
state.sound_manager.play_sfx(24);
|
||||
}
|
||||
|
@ -731,7 +747,7 @@ impl Player {
|
|||
self.anim_num = 0;
|
||||
self.anim_counter = 0;
|
||||
}
|
||||
} else if self.controller.look_up() && self.control_mode == ControlMode::Normal {
|
||||
} else if (self.controller.look_up() || self.strafe_up) && self.control_mode == ControlMode::Normal {
|
||||
self.skin.set_state(PlayerAnimationState::FallingLookingUp);
|
||||
self.anim_num = 0;
|
||||
self.anim_counter = 0;
|
||||
|
|
|
@ -54,7 +54,7 @@ fn default_true() -> bool {
|
|||
|
||||
#[inline(always)]
|
||||
fn current_version() -> u32 {
|
||||
5
|
||||
6
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -108,6 +108,12 @@ impl Settings {
|
|||
self.sfx_volume = default_vol();
|
||||
}
|
||||
|
||||
if self.version == 5 {
|
||||
self.version = 6;
|
||||
self.player1_key_map.strafe = ScanCode::LShift;
|
||||
self.player2_key_map.strafe = ScanCode::RShift;
|
||||
}
|
||||
|
||||
if self.version != initial_version {
|
||||
log::info!("Upgraded configuration file from version {} to {}.", initial_version, self.version);
|
||||
}
|
||||
|
@ -175,6 +181,7 @@ pub struct PlayerKeyMap {
|
|||
pub skip: ScanCode,
|
||||
pub inventory: ScanCode,
|
||||
pub map: ScanCode,
|
||||
pub strafe: ScanCode,
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -191,6 +198,7 @@ fn p1_default_keymap() -> PlayerKeyMap {
|
|||
skip: ScanCode::E,
|
||||
inventory: ScanCode::Q,
|
||||
map: ScanCode::W,
|
||||
strafe: ScanCode::LShift,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,5 +216,6 @@ fn p2_default_keymap() -> PlayerKeyMap {
|
|||
skip: ScanCode::U,
|
||||
inventory: ScanCode::T,
|
||||
map: ScanCode::Y,
|
||||
strafe: ScanCode::RShift,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue