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

  1. use macroquad::prelude::*;
  2. #[macroquad::main("cool game")]
  3. async fn main() {
  4. let mut game = Game::new();
  5. loop {
  6. if is_key_down(KeyCode::Escape) {
  7. break;
  8. }
  9. game.draw();
  10. game.update();
  11. next_frame().await;
  12. }
  13. }
  14. struct Game {
  15. player: Rect,
  16. }
  17. impl Game {
  18. fn new() -> Self {
  19. Self {
  20. player: Rect::new(50.0, 50.0, 25.0, 25.0),
  21. }
  22. }
  23. fn update(&mut self) {
  24. if is_key_down(KeyCode::Up) {
  25. self.player.y -= 1.0;
  26. }
  27. if is_key_down(KeyCode::Down) {
  28. self.player.y += 1.0;
  29. }
  30. if is_key_down(KeyCode::Right) {
  31. self.player.x += 1.0;
  32. }
  33. if is_key_down(KeyCode::Left) {
  34. self.player.x -= 1.0;
  35. }
  36. }
  37. fn draw(&self) {
  38. clear_background(DARKBLUE);
  39. draw_rectangle(
  40. self.player.x,
  41. self.player.y,
  42. self.player.w,
  43. self.player.h,
  44. PINK,
  45. );
  46. }
  47. }