BANG BIG PEANITS
This commit is contained in:
17
src/controls.rs
Normal file
17
src/controls.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
pub struct InputState {
|
||||
pub right: bool,
|
||||
pub left: bool,
|
||||
pub down: bool,
|
||||
pub jump: bool,
|
||||
}
|
||||
|
||||
impl InputState {
|
||||
pub fn new(right: bool, left: bool, down: bool, jump: bool) -> Self {
|
||||
Self {
|
||||
right,
|
||||
left,
|
||||
down,
|
||||
jump,
|
||||
}
|
||||
}
|
||||
}
|
||||
53
src/main.rs
Normal file
53
src/main.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
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();
|
||||
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 mut d = rl.begin_drawing(&thread);
|
||||
d.clear_background(Color::WHITE);
|
||||
d.draw_text("MY BIG PEANITS", 12, 12, 20, Color::BLACK);
|
||||
d.draw_rectangle(
|
||||
player.position.x as i32,
|
||||
player.position.y as i32,
|
||||
100,
|
||||
200,
|
||||
Color::RED,
|
||||
);
|
||||
d.draw_circle(
|
||||
(player.position.x + 50.0) as i32,
|
||||
player.position.y as i32,
|
||||
50.0,
|
||||
Color::RED,
|
||||
);
|
||||
d.draw_circle(
|
||||
(player.position.x + 100.0) as i32,
|
||||
(player.position.y + 210.0) as i32,
|
||||
50.0,
|
||||
Color::RED,
|
||||
);
|
||||
d.draw_circle(
|
||||
(player.position.x + 15.0) as i32,
|
||||
(player.position.y + 210.0) as i32,
|
||||
50.0,
|
||||
Color::RED,
|
||||
);
|
||||
}
|
||||
}
|
||||
54
src/player.rs
Normal file
54
src/player.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use super::controls::InputState;
|
||||
use raylib::prelude::*;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Player {
|
||||
pub position: Vector2,
|
||||
width: f32,
|
||||
height: f32,
|
||||
speed: f32,
|
||||
jump_velocity: f32,
|
||||
grounded: bool,
|
||||
}
|
||||
|
||||
impl Player {
|
||||
fn new(
|
||||
position: Vector2,
|
||||
width: f32,
|
||||
height: f32,
|
||||
speed: f32,
|
||||
jump_velocity: f32,
|
||||
grounded: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
position,
|
||||
width,
|
||||
height,
|
||||
speed,
|
||||
jump_velocity,
|
||||
grounded,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_input(&mut self, input: &InputState) {
|
||||
// Da inpoot handol))
|
||||
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) {
|
||||
if input.jump {
|
||||
self.position.y -= 10.0;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rect(&self) -> Rectangle {
|
||||
todo!()
|
||||
// Collision bawx n shi
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user