mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2024-11-22 05:33:02 +00:00
small refactoring
This commit is contained in:
parent
f1e1d41931
commit
31db4bcc80
47
src/main.rs
47
src/main.rs
|
@ -31,7 +31,7 @@ use crate::ggez::graphics::DrawParam;
|
|||
use crate::ggez::input::keyboard;
|
||||
use crate::ggez::mint::ColumnMatrix4;
|
||||
use crate::ggez::nalgebra::Vector2;
|
||||
use crate::live_debugger::LiveDebugger;
|
||||
|
||||
use crate::rng::RNG;
|
||||
use crate::scene::loading_scene::LoadingScene;
|
||||
use crate::scene::Scene;
|
||||
|
@ -112,7 +112,7 @@ pub struct SharedGameState {
|
|||
impl SharedGameState {
|
||||
pub fn update_key_trigger(&mut self) {
|
||||
let mut trigger = self.key_state.0 ^ self.key_old;
|
||||
trigger = self.key_state.0 & trigger;
|
||||
trigger &= self.key_state.0;
|
||||
self.key_old = self.key_state.0;
|
||||
self.key_trigger = KeyState(trigger);
|
||||
}
|
||||
|
@ -267,33 +267,30 @@ pub fn main() -> GameResult {
|
|||
ctx.process_event(&event);
|
||||
game.ui.handle_events(ctx, &event);
|
||||
|
||||
match event {
|
||||
Event::WindowEvent { event, .. } => match event {
|
||||
WindowEvent::CloseRequested => event::quit(ctx),
|
||||
WindowEvent::KeyboardInput {
|
||||
input:
|
||||
KeyboardInput {
|
||||
state: el_state,
|
||||
virtual_keycode: Some(keycode),
|
||||
modifiers,
|
||||
..
|
||||
},
|
||||
if let Event::WindowEvent { event, .. } = event { match event {
|
||||
WindowEvent::CloseRequested => event::quit(ctx),
|
||||
WindowEvent::KeyboardInput {
|
||||
input:
|
||||
KeyboardInput {
|
||||
state: el_state,
|
||||
virtual_keycode: Some(keycode),
|
||||
modifiers,
|
||||
..
|
||||
} => {
|
||||
match el_state {
|
||||
ElementState::Pressed => {
|
||||
let repeat = keyboard::is_key_repeated(ctx);
|
||||
game.key_down_event(ctx, keycode, modifiers.into(), repeat);
|
||||
}
|
||||
ElementState::Released => {
|
||||
game.key_up_event(ctx, keycode, modifiers.into());
|
||||
}
|
||||
},
|
||||
..
|
||||
} => {
|
||||
match el_state {
|
||||
ElementState::Pressed => {
|
||||
let repeat = keyboard::is_key_repeated(ctx);
|
||||
game.key_down_event(ctx, keycode, modifiers.into(), repeat);
|
||||
}
|
||||
ElementState::Released => {
|
||||
game.key_up_event(ctx, keycode, modifiers.into());
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
} }
|
||||
});
|
||||
|
||||
game.update(ctx)?;
|
||||
|
|
|
@ -105,12 +105,12 @@ pub struct Player {
|
|||
}
|
||||
|
||||
impl Player {
|
||||
pub fn new(state: &mut SharedGameState, ctx: &mut Context) -> GameResult<Player> {
|
||||
pub fn new(state: &mut SharedGameState) -> Self {
|
||||
let constants = &state.constants;
|
||||
|
||||
let tex_player_name = str!("MyChar");
|
||||
|
||||
Ok(Player {
|
||||
Self {
|
||||
x: 0,
|
||||
y: 0,
|
||||
vel_x: 0,
|
||||
|
@ -122,7 +122,7 @@ impl Player {
|
|||
cond: Cond(constants.my_char.cond),
|
||||
flags: Flags(constants.my_char.flags),
|
||||
equip: Equip(constants.my_char.equip),
|
||||
direction: constants.my_char.direction.clone(),
|
||||
direction: constants.my_char.direction,
|
||||
view: constants.my_char.view,
|
||||
hit: constants.my_char.hit,
|
||||
unit: constants.my_char.unit,
|
||||
|
@ -143,7 +143,7 @@ impl Player {
|
|||
anim_wait: 0,
|
||||
anim_rect: constants.my_char.animations_right[0],
|
||||
tex_player_name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn tick_normal(&mut self, state: &mut SharedGameState) -> GameResult {
|
||||
|
@ -285,11 +285,9 @@ impl Player {
|
|||
self.up = state.key_state.up();
|
||||
self.down = state.key_state.down() && !self.flags.flag_x08();
|
||||
|
||||
if state.key_trigger.jump() && (self.flags.flag_x08() || self.flags.flag_x10() || self.flags.flag_x20()) {
|
||||
if !self.flags.force_up() {
|
||||
self.vel_y = -physics.jump;
|
||||
// todo: PlaySoundObject(15, SOUND_MODE_PLAY);
|
||||
}
|
||||
if state.key_trigger.jump() && (self.flags.flag_x08() || self.flags.flag_x10() || self.flags.flag_x20()) && !self.flags.force_up() {
|
||||
self.vel_y = -physics.jump;
|
||||
// todo: PlaySoundObject(15, SOUND_MODE_PLAY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -393,9 +391,9 @@ impl Player {
|
|||
}
|
||||
|
||||
let max_move = if self.flags.underwater() && !(self.flags.force_left() || self.flags.force_up() || self.flags.force_right() || self.flags.force_down()) {
|
||||
physics.max_move
|
||||
state.constants.my_char.water_physics.max_move
|
||||
} else {
|
||||
physics.max_move
|
||||
state.constants.my_char.air_physics.max_move
|
||||
};
|
||||
|
||||
self.vel_x = clamp(self.vel_x, -max_move, max_move);
|
||||
|
|
|
@ -56,7 +56,7 @@ impl GameScene {
|
|||
Ok(Self {
|
||||
tick: 0,
|
||||
stage,
|
||||
player: Player::new(state, ctx)?,
|
||||
player: Player::new(state),
|
||||
frame: Frame {
|
||||
x: 0,
|
||||
y: 0,
|
||||
|
|
Loading…
Reference in a new issue