MMBC

Square movement

Aug 28th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1. #include <stdbool.h>
  2. #include <stddef.h>
  3. #include <stdint.h>
  4. #include <tice.h>
  5.  
  6. #include <math.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. #include <graphx.h>
  12. #include <keypadc.h>
  13.  
  14. void main(void) {
  15.     uint16_t x = 0;
  16.     uint8_t y = 0;
  17.     uint8_t key;
  18.     bool running = true;
  19.     prgm_CleanUp();
  20.     gfx_Begin();
  21.     gfx_SetDrawBuffer();
  22.     gfx_ZeroScreen();
  23.     gfx_SetColor(255);
  24.     gfx_FillRectangle(x, y, 20, 20);
  25.     gfx_BlitBuffer();
  26.     while(running) {
  27.         key = kb_ScanGroup(kb_group_6);
  28.         if (key == kb_Clear) running = false;
  29.         key = kb_ScanGroup(kb_group_7);
  30.         switch(key) {
  31.             case kb_Up:
  32.                 y--;
  33.                 break;
  34.             case kb_Down:
  35.                 y++;
  36.                 break;
  37.             case kb_Left:
  38.                 x--;
  39.                 break;
  40.             case kb_Right:
  41.                 x++;
  42.                 break;
  43.         }
  44.         if (key) {
  45.             gfx_ZeroScreen();
  46.             gfx_SetColor(255);
  47.             gfx_FillRectangle(x, y, 20, 20);
  48.             gfx_BlitBuffer();
  49.         }
  50.     }
  51.     gfx_End();
  52. }
Advertisement
Add Comment
Please, Sign In to add comment