Skip to main content

input_keys/
input_keys.rs

1use macroquad::prelude::*;
2
3#[macroquad::main("InputKeys")]
4async fn main() {
5    let mut x = screen_width() / 2.0;
6    let mut y = screen_height() / 2.0;
7
8    loop {
9        clear_background(LIGHTGRAY);
10
11        if is_key_down(KeyCode::Right) {
12            x += 1.0;
13        }
14        if is_key_down(KeyCode::Left) {
15            x -= 1.0;
16        }
17        if is_key_down(KeyCode::Down) {
18            y += 1.0;
19        }
20        if is_key_down(KeyCode::Up) {
21            y -= 1.0;
22        }
23
24        draw_circle(x, y, 15.0, YELLOW);
25        draw_text("move the ball with arrow keys", 20.0, 20.0, 20.0, DARKGRAY);
26        next_frame().await
27    }
28}