Added multipress support
This commit is contained in:
47
src/main.rs
47
src/main.rs
@@ -13,7 +13,7 @@ const BLOC_SPEED:f32 = 3.0;
|
||||
const MAX_SPEED:f32 = 20.0;
|
||||
const GRAVITY:f32 = 10.0;
|
||||
|
||||
const BOUNCE_RATIO:f32 = 110.0;
|
||||
const BOUNCE_RATIO:f32 = 80.0;
|
||||
|
||||
pub struct Game{
|
||||
main_bloc:Entity,
|
||||
@@ -113,31 +113,44 @@ pub struct Entity{
|
||||
shape:Rect,
|
||||
velocity:Point,
|
||||
}
|
||||
fn is_up_pressed(e: &sdl2::EventPump) -> bool {
|
||||
e.keyboard_state().is_scancode_pressed(Scancode::W) || e.keyboard_state().is_scancode_pressed(Scancode::Up)
|
||||
}
|
||||
fn is_down_pressed(e: &sdl2::EventPump)-> bool{
|
||||
e.keyboard_state().is_scancode_pressed(Scancode::S) || e.keyboard_state().is_scancode_pressed(Scancode::Down)
|
||||
}
|
||||
fn is_left_pressed(e: &sdl2::EventPump)-> bool{
|
||||
e.keyboard_state().is_scancode_pressed(Scancode::A) || e.keyboard_state().is_scancode_pressed(Scancode::Left)
|
||||
}
|
||||
fn is_right_pressed(e: &sdl2::EventPump)-> bool{
|
||||
e.keyboard_state().is_scancode_pressed(Scancode::D) || e.keyboard_state().is_scancode_pressed(Scancode::Right)
|
||||
}
|
||||
|
||||
pub fn main_loop(canvas: &mut sdl2::render::Canvas<sdl2::video::Window>,event_pump:&mut sdl2::EventPump,game:&mut Game){
|
||||
'running: loop {
|
||||
if is_up_pressed(event_pump){
|
||||
//println!("Hello");
|
||||
game.up();
|
||||
}
|
||||
if is_down_pressed(event_pump){
|
||||
//println!("Hello");
|
||||
game.down();
|
||||
}
|
||||
if is_left_pressed(event_pump){
|
||||
//println!("Hello");
|
||||
game.left();
|
||||
}
|
||||
if is_right_pressed(event_pump){
|
||||
//println!("Hello");
|
||||
game.right();
|
||||
}
|
||||
|
||||
for event in event_pump.poll_iter() {
|
||||
match event {
|
||||
Event::Quit {..} |
|
||||
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
|
||||
break 'running
|
||||
},
|
||||
Event::KeyDown { keycode: Some(Keycode::W), .. } | Event::KeyDown {keycode: Some(Keycode::Up), ..} => {
|
||||
//pressed up
|
||||
game.up();
|
||||
},
|
||||
Event::KeyDown { keycode: Some(Keycode::S), .. } | Event::KeyDown { keycode: Some(Keycode::Down), .. } => {
|
||||
//pressed up
|
||||
game.down();
|
||||
},
|
||||
Event::KeyDown { keycode: Some(Keycode::A), .. } | Event::KeyDown { keycode: Some(Keycode::Left), .. } => {
|
||||
//pressed up
|
||||
game.left();
|
||||
},
|
||||
Event::KeyDown { keycode: Some(Keycode::D), .. } | Event::KeyDown { keycode: Some(Keycode::Right), .. } => {
|
||||
//pressed up
|
||||
game.right();
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user