improve inputs
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
#[derive(Default, Clone, Copy, Debug)]
|
||||
pub struct Input {
|
||||
pub up: bool,
|
||||
pub down: bool,
|
||||
pub left: bool,
|
||||
pub right: bool,
|
||||
|
||||
pub a_down: bool,
|
||||
pub b_down: bool,
|
||||
|
||||
pub start: bool,
|
||||
pub select: bool,
|
||||
}
|
||||
|
||||
impl Input {
|
||||
pub fn begin_frame(&mut self) {
|
||||
// No v0, nada a fazer.
|
||||
// No futuro: a_pressed/a_released, etc.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#[derive(Default, Clone, Copy, Debug)]
|
||||
pub struct InputSignals {
|
||||
// PAD
|
||||
pub up_signal: bool,
|
||||
pub down_signal: bool,
|
||||
pub left_signal: bool,
|
||||
pub right_signal: bool,
|
||||
|
||||
pub a_signal: bool,
|
||||
pub d_signal: bool,
|
||||
pub w_signal: bool,
|
||||
pub s_signal: bool,
|
||||
pub q_signal: bool,
|
||||
pub e_signal: bool,
|
||||
|
||||
pub start_signal: bool,
|
||||
pub select_signal: bool,
|
||||
|
||||
// TOUCH
|
||||
pub t_signal: bool,
|
||||
pub x_pos: i32,
|
||||
pub y_pos: i32,
|
||||
}
|
||||
|
||||
impl InputSignals {
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
mod gfx;
|
||||
mod input;
|
||||
mod pad;
|
||||
mod touch;
|
||||
mod input_signal;
|
||||
|
||||
pub use gfx::Gfx;
|
||||
pub use input::Input;
|
||||
pub use input_signal::InputSignals;
|
||||
pub use pad::Pad;
|
||||
pub use touch::Touch;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
use crate::c_button::CButton;
|
||||
use crate::peripherals::input_signal::InputSignals;
|
||||
|
||||
#[derive(Default, Clone, Copy, Debug)]
|
||||
pub struct Pad {
|
||||
pub up: CButton,
|
||||
pub down: CButton,
|
||||
pub left: CButton,
|
||||
pub right: CButton,
|
||||
|
||||
pub a: CButton, // ps: square
|
||||
pub d: CButton, // ps: circle
|
||||
pub w: CButton, // ps: triangle
|
||||
pub s: CButton, // ps: cross
|
||||
pub q: CButton, // ps: R
|
||||
pub e: CButton, // ps: L
|
||||
|
||||
pub start: CButton,
|
||||
pub select: CButton,
|
||||
}
|
||||
|
||||
impl Pad {
|
||||
pub fn begin_frame(&mut self, signals: &InputSignals) {
|
||||
self.up.begin_frame(signals.up_signal);
|
||||
self.down.begin_frame(signals.down_signal);
|
||||
self.left.begin_frame(signals.left_signal);
|
||||
self.right.begin_frame(signals.right_signal);
|
||||
|
||||
self.a.begin_frame(signals.a_signal);
|
||||
self.d.begin_frame(signals.d_signal);
|
||||
self.w.begin_frame(signals.w_signal);
|
||||
self.s.begin_frame(signals.s_signal);
|
||||
self.q.begin_frame(signals.q_signal);
|
||||
self.e.begin_frame(signals.e_signal);
|
||||
|
||||
self.start.begin_frame(signals.start_signal);
|
||||
self.select.begin_frame(signals.select_signal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
use crate::c_button::CButton;
|
||||
use crate::peripherals::input_signal::InputSignals;
|
||||
|
||||
#[derive(Default, Clone, Copy, Debug)]
|
||||
pub struct Touch {
|
||||
pub present: bool,
|
||||
pub down: bool,
|
||||
pub pressed: bool,
|
||||
pub released: bool,
|
||||
pub f: CButton,
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
}
|
||||
|
||||
impl Touch {
|
||||
/// Flags transitórias devem durar apenas 1 frame.
|
||||
pub fn begin_frame(&mut self) {
|
||||
self.pressed = false;
|
||||
self.released = false;
|
||||
pub fn begin_frame(&mut self, signals: &InputSignals) {
|
||||
self.f.begin_frame(signals.t_signal);
|
||||
self.x = signals.x_pos;
|
||||
self.y = signals.y_pos;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user