Noëlle Anthony пре 4 година
родитељ
комит
4c73e872a9
1 измењених фајлова са 15 додато и 1 уклоњено
  1. 15
    1
      src/main.rs

+ 15
- 1
src/main.rs Прегледај датотеку

@@ -10,6 +10,7 @@ use std::time::Duration;
struct Player {
position: Point,
sprite: Rect,
speed: i32,
}

fn render(canvas: &mut WindowCanvas,
@@ -45,9 +46,10 @@ fn main() -> Result<(), String> {
let texture_creator = canvas.texture_creator();
let texture = texture_creator.load_texture("assets/bardo.png")?;

let player = Player {
let mut player = Player {
position: Point::new(0,0),
sprite: Rect::new(0, 0, 26, 36),
speed: 5,
};

let mut event_pump = sdl_context.event_pump()?;
@@ -59,6 +61,18 @@ fn main() -> Result<(), String> {
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
break 'running;
},
Event::KeyDown { keycode: Some(Keycode::Left), .. } => {
player.position = player.position.offset(-player.speed, 0);
},
Event::KeyDown { keycode: Some(Keycode::Right), .. } => {
player.position = player.position.offset(player.speed, 0);
},
Event::KeyDown { keycode: Some(Keycode::Up), .. } => {
player.position = player.position.offset(0, -player.speed);
},
Event::KeyDown { keycode: Some(Keycode::Down), .. } => {
player.position = player.position.offset(0, player.speed);
},
_ => {}
}
}

Loading…
Откажи
Сачувај