Advertisement
Guest User

Code for drawing map on GB

a guest
Oct 6th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.18 KB | None | 0 0
  1. #include <Backlight.h>
  2. #include <Battery.h>
  3. #include <Buttons.h>
  4. #include <Display.h>
  5. #include <Gamebuino.h>
  6. #include <Sound.h>
  7. #include <SPI.h>
  8.  
  9. Gamebuino gb;
  10.  
  11. const PROGMEM byte Empty[] = //ID: 0
  12. {
  13.   8,8,
  14.   B00000000,
  15.   B00000000,
  16.   B00000000,
  17.   B00000000,
  18.   B00000000,
  19.   B00000000,
  20.   B00000000,
  21.   B00000000,
  22. };
  23.  
  24. const PROGMEM byte Brick[] = //ID: 1
  25. {
  26.   8,8,
  27.   B11111111,
  28.   B00100001,
  29.   B11111111,
  30.   B10001000,
  31.   B11111111,
  32.   B00100001,
  33.   B11111111,
  34.   B10001000,
  35. };
  36.  
  37. const PROGMEM byte SharpBrick[]= //ID: 2
  38. {
  39.   8,8,
  40.   B11111111,
  41.   B11000011,
  42.   B10100101,
  43.   B10011001,
  44.   B10011001,
  45.   B10100101,
  46.   B11000011,
  47.   B11111111,
  48. };
  49. const PROGMEM byte TowerBrick[]= //ID: 3
  50. {
  51.   8,8,
  52.   B10101101,
  53.   B10110101,
  54.   B10101101,
  55.   B10110101,
  56.   B10101101,
  57.   B10110101,
  58.   B10101101,
  59.   B10110101,
  60. };
  61.  
  62. const PROGMEM byte Piston[]= //ID: 4
  63. {
  64.   8,8,
  65.   B00000000,
  66.   B01111110,
  67.   B00100100,
  68.   B00100100,
  69.   B01000010,
  70.   B00011000,
  71.   B01111110,
  72.   B00000000,
  73. };
  74.  
  75. const PROGMEM byte Holder[]= //ID: 5
  76. {
  77.   8,8,
  78.   B11111111,
  79.   B10100101,
  80.   B11111111,
  81.   B00000000,
  82.   B00000000,
  83.   B00000000,
  84.   B00000000,
  85.   B00000000,
  86. };
  87.  
  88. const PROGMEM byte  Teleporter1[]= //ID: 6
  89. {
  90.   8,8,
  91.   B11111111,
  92.   B10101011,
  93.   B11010110,
  94.   B10101100,
  95.   B10101100,
  96.   B11010110,
  97.   B10101011,
  98.   B11111111,
  99. };
  100.  
  101. const PROGMEM byte Teleporter0[]= //ID: 7
  102. {
  103.   8,8,
  104.   B11111111,
  105.   B11010101,
  106.   B01101011,
  107.   B00110101,
  108.   B00110101,
  109.   B01101011,
  110.   B11010101,
  111.   B11111111,
  112. };
  113.  
  114. const PROGMEM byte Wall[]= //ID: 8
  115. {
  116.   8,8,
  117.   B11110000,
  118.   B10010000,
  119.   B10010000,
  120.   B10010000,
  121.   B10010000,
  122.   B10010000,
  123.   B10010000,
  124.   B11110000,
  125. };
  126.  
  127. const PROGMEM byte Ennemie[]= //ID: 8
  128. {
  129.   8,8,
  130.   B11111111,
  131.   B10000001,
  132.   B10010011,
  133.   B10010011,
  134.   B10000001,
  135.   B10000001,
  136.   B10000001,
  137.   B11111111,
  138. };
  139.  
  140. const byte Map[] PROGMEM = {13,9,
  141. 8,8,
  142.  
  143. 0,0,0,0,0,0,0,0,0,0,0,0,2,
  144. 2,1,2,5,5,8,0,0,0,0,0,0,7,
  145. 3,0,0,0,0,8,0,0,0,0,0,0,2,
  146. 3,0,0,0,0,0,4,5,2,0,0,0,3,
  147. 2,0,2,0,0,0,0,0,0,0,0,0,3,
  148. 3,0,3,0,0,0,0,0,0,0,0,0,3,
  149. 3,0,3,0,0,0,2,5,5,0,5,5,2,
  150. 3,0,3,0,9,0,3,0,9,0,0,0,7,
  151. 2,0,2,1,1,1,2,1,1,1,1,1,2,
  152. };
  153.  
  154. const byte* sprites[10] = {
  155.   Empty,
  156.   Brick,
  157.   SharpBrick,
  158.   TowerBrick,
  159.   Piston,
  160.   Holder,
  161.   Teleporter0,
  162.   Teleporter1,
  163.   Wall,
  164.   Ennemie
  165. };
  166.  
  167. byte getTile(byte x, byte y){
  168.   /*if(x & 1)//odd
  169.     return pgm_read_byte(Map + y*(13) + x/2) & B00001111;
  170.   else //even
  171.     return (pgm_read_byte(Map + y*(9) + x/2) >> 4);*/
  172.     return pgm_read_byte(Map + (x+y*13));
  173. }
  174.  
  175. int CPosX = 0;
  176. int CPosY = 0;
  177.  
  178. void setup() {
  179.   // put your setup code here, to run once:
  180.   gb.begin();
  181.   gb.titleScreen(F("BIGBLACKBOX Testing"));
  182. }
  183.  
  184. void loop() {
  185.   // put your main code here, to run repeatedly:
  186.   if(gb.update()) {
  187.       if(gb.buttons.pressed(BTN_UP))
  188.         CPosY++;
  189.       if(gb.buttons.pressed(BTN_DOWN))
  190.         CPosY--;
  191.       if(gb.buttons.pressed(BTN_RIGHT))
  192.         CPosX--;
  193.       if(gb.buttons.pressed(BTN_LEFT))
  194.         CPosX++;
  195.      
  196.       for(byte x = 0; x < 13; x++) {
  197.         for(byte y = 0; y < 9; y++) {
  198.           byte Id;
  199.           Id = getTile(x,y);
  200.           gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, sprites[Id]);
  201.         }
  202.       }
  203.   }
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement