chore: decoupled up/down from left/right, more keys
Signed-off-by: Supermjork <markehabaziz@gmail.com>
This commit is contained in:
26
src/main.rs
26
src/main.rs
@@ -1,26 +1,28 @@
|
||||
use raylib::prelude::*;
|
||||
use controls::InputState;
|
||||
use player::Player;
|
||||
|
||||
mod controls;
|
||||
mod player;
|
||||
|
||||
fn main() {
|
||||
use raylib::prelude::*;
|
||||
let (mut rl, thread) = raylib::init().size(640, 480).title("My peanits").build();
|
||||
rl.set_target_fps(69);
|
||||
|
||||
let mut player: Player = Player::default();
|
||||
|
||||
while !rl.window_should_close() {
|
||||
rl.set_target_fps(69);
|
||||
// Player movement
|
||||
if rl.is_key_down(KeyboardKey::KEY_RIGHT) {
|
||||
player.handle_input(&InputState::new(true, false, false, false));
|
||||
println!("LEFT");
|
||||
} else if rl.is_key_down(KeyboardKey::KEY_LEFT) {
|
||||
player.handle_input(&InputState::new(false, true, false, false));
|
||||
} else if rl.is_key_down(KeyboardKey::KEY_DOWN) {
|
||||
player.handle_input(&InputState::new(false, false, true, false));
|
||||
} else if rl.is_key_down(KeyboardKey::KEY_SPACE) {
|
||||
player.handle_jump(&InputState::new(false, false, false, true));
|
||||
}
|
||||
let movement = InputState::new(
|
||||
rl.is_key_down(KeyboardKey::KEY_RIGHT) || rl.is_key_down(KeyboardKey::KEY_D),
|
||||
rl.is_key_down(KeyboardKey::KEY_LEFT) || rl.is_key_down(KeyboardKey::KEY_A),
|
||||
rl.is_key_down(KeyboardKey::KEY_DOWN) || rl.is_key_down(KeyboardKey::KEY_S),
|
||||
rl.is_key_down(KeyboardKey::KEY_SPACE) || rl.is_key_down(KeyboardKey::KEY_W)
|
||||
);
|
||||
|
||||
player.handle_lateral_movement(&movement);
|
||||
player.handle_vertical_movement(&movement);
|
||||
|
||||
let mut d = rl.begin_drawing(&thread);
|
||||
d.clear_background(Color::WHITE);
|
||||
d.draw_text("MY BIG PEANITS", 12, 12, 20, Color::BLACK);
|
||||
|
||||
@@ -30,20 +30,21 @@ impl Player {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_input(&mut self, input: &InputState) {
|
||||
// Da inpoot handol))
|
||||
pub fn handle_lateral_movement(&mut self, input: &InputState) {
|
||||
// Handles moving left and right
|
||||
if input.right {
|
||||
self.position.x += 2.0;
|
||||
} else if input.left {
|
||||
self.position.x -= 2.0;
|
||||
} else if input.down {
|
||||
self.position.y += 4.0;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_jump(&mut self, input: &InputState) {
|
||||
pub fn handle_vertical_movement(&mut self, input: &InputState) {
|
||||
// Handles moving up and down
|
||||
if input.jump {
|
||||
self.position.y -= 10.0;
|
||||
} else if input.down {
|
||||
self.position.y += 4.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user