You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

53 lines
1.0 KiB

use macroquad::prelude::*;
#[macroquad::main("cool game")]
async fn main() {
let mut game = Game::new();
loop {
if is_key_down(KeyCode::Escape) {
break;
}
game.draw();
game.update();
next_frame().await;
}
}
struct Game {
player: Rect,
}
impl Game {
fn new() -> Self {
Self {
player: Rect::new(50.0, 50.0, 25.0, 25.0),
}
}
fn update(&mut self) {
if is_key_down(KeyCode::Up) {
self.player.y -= 1.0;
}
if is_key_down(KeyCode::Down) {
self.player.y += 1.0;
}
if is_key_down(KeyCode::Right) {
self.player.x += 1.0;
}
if is_key_down(KeyCode::Left) {
self.player.x -= 1.0;
}
}
fn draw(&self) {
clear_background(DARKBLUE);
draw_rectangle(
self.player.x,
self.player.y,
self.player.w,
self.player.h,
PINK,
);
}
}