Advertisement
Guest User

Arduboy

a guest
Jan 24th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.42 KB | None | 0 0
  1. #define MAX_LEVELS 2
  2.  
  3. #include <Arduboy2.h>
  4. #include <bitmaps.h>
  5.  
  6. Arduboy2 arduboy;
  7.  
  8. int level = 1;
  9. byte animToggle;
  10.  
  11. byte platforms[] = {
  12.         2,3,3,9,2,2,11,5,4,
  13.         4,2,2,2,5,4,9,3,3
  14. };
  15.  
  16. struct objects
  17. {
  18.  byte type;
  19.  byte x;
  20.  byte y;
  21.  float xRate;
  22.  float yRate;
  23.  boolean direction;
  24.  byte state;
  25. } ;
  26.  
  27. struct objects gameObjects[2][10];
  28.  
  29. struct gameObjects[0][0] = { 1,24,48,0,0,1,0};
  30.  
  31. void setup()
  32. {
  33.         Serial.begin(115200);
  34.         arduboy.boot(); // raw hardware
  35.         arduboy.blank(); // blank the display
  36.         arduboy.flashlight(); // light the RGB LED and screen if UP button is being held.
  37.         arduboy.systemButtons();
  38.         //arduboy.bootLogo();
  39.         arduboy.audio.begin();
  40.         arduboy.clear();
  41.  
  42.         randomSeed(analogRead(0));
  43.         arduboy.setFrameRate(60);
  44. }
  45.  
  46. void drawThings()
  47. {
  48.         for (int index=0; index<10; index++)
  49.         {
  50.               byte type = gameObjects[level-1][index].type;
  51.               byte x = gameObjects[level-1][index].x;
  52.               byte y = gameObjects[level-1][index].y;
  53.               boolean direction = gameObjects[level-1][index].direction;
  54.               byte state = gameObjects[level-1][index].state;
  55.  
  56.               if (type==1) drawJetMan(x, y, direction, state);
  57.         }
  58. }
  59.  
  60. void drawJetMan(byte x, byte y, boolean direction, byte state)
  61. {
  62.         if (direction)
  63.         {
  64.                 if (state==0)
  65.                 {
  66.                         arduboy.drawBitmap(x,y, JETMANRIGHTHEAD, 8, 8);
  67.                         arduboy.drawBitmap(x, y, JETMANRIGHT1, 8, 8);
  68.                 }
  69.                 else
  70.                 {
  71.                         arduboy.drawBitmap(x, y, JETMANLEFTHEAD, 8, 8);
  72.                         arduboy.drawBitmap(x, y, JETMANLEFT1, 8, 8);
  73.                 }
  74.  
  75.         }
  76. }
  77.  
  78. void drawPlatforms()
  79. {
  80.         for (byte index = level*9; index<(level*9)+9; index=index+3)
  81.         {
  82.                 for (byte row = 0; row < platforms[index+2]; row++)
  83.                 {
  84.                         arduboy.drawBitmap((platforms[index]*8)+(row*8), platforms[index+1]*8, PLATFORM, 8, 8);
  85.                 }
  86.         }
  87. }
  88.  
  89. void loop() {
  90.         if (!arduboy.nextFrame()) return;  // Keep frame rate at 60fps
  91.  
  92.         arduboy.drawFastHLine(0, 63, 128); // ground
  93.         drawPlatforms();
  94.         drawThings();
  95.  
  96.         Serial.write(arduboy.getBuffer(), 128 * 64 / 8);
  97.         arduboy.display();
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement