Advertisement
Guest User

Pacman Arduboy

a guest
Jan 20th, 2017
134
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.30 KB | None
  1. #include <PGMWrap.h>
  2. #include <Arduboy2.h>
  3.  
  4. // http://community.arduboy.com/
  5. // https://emutyworks.github.io/BitmapEditor/demo/index.html
  6. // http://community.arduboy.com/t/reference-page-for-development/76/2
  7. // http://www.andrewlowndes.co.uk/blog/graphics/arduboy-image-converter
  8. // http://www.crait.net/tochars/
  9. // https://github.com/yyyc514/img2ard
  10. // https://github.com/andremichelle/platforms
  11. // http://fuopy.github.io/arduboy-image-converter/ !!!
  12. // arduboy.pressed(RIGHT_BUTTON)
  13. // http://playground.arduino.cc/Main/PROGMEM
  14. const unsigned char PlayFieldTiles[] PROGMEM  = {0xf0, 0x0c, 0x02, 0xe2, 0x11, 0x09, 0x09, 0x09,
  15.                                                  0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
  16.                                                  0x09, 0x09, 0x09, 0x11, 0xe1, 0x01, 0x01, 0x01,
  17.                                                  0x01, 0x01, 0x01, 0xe1, 0x11, 0x09, 0x09, 0x09,
  18.                                                  0x09, 0x09, 0x09, 0x11, 0xe2, 0x02, 0x0c, 0xf0,
  19.                                                  0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
  20.                                                  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  21.                                                  0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
  22.                                                  0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
  23.                                                  0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
  24.                                                  0x00, 0x00, 0x00, 0x00, 0xc0, 0x20, 0x10, 0x10,
  25.                                                  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
  26.                                                  0x10, 0x10, 0x20, 0xc0, 0x00, 0x00, 0x00, 0x00,
  27.                                                  0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x08, 0x08,
  28.                                                  0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
  29.                                                  0x08, 0x08, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00,
  30.                                                  0x08, 0x08, 0x08, 0x10, 0xe0, 0x00, 0x00, 0x00,
  31.                                                  0x00, 0x00, 0x00, 0xe0, 0x10, 0x08, 0x08, 0x08,
  32.                                                  0x0f, 0x30, 0x40, 0x47, 0x88, 0x90, 0x90, 0x90,
  33.                                                  0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
  34.                                                  0x00, 0x00, 0x00, 0x07, 0x08, 0x10, 0x10, 0x10,
  35.                                                  0x10, 0x10, 0x10, 0x08, 0x07, 0x00, 0x00, 0x00,
  36.                                                  0x90, 0x90, 0x90, 0x88, 0x47, 0x40, 0x30, 0x0f,
  37.                                                  0x00, 0x00, 0x00, 0x00, 0xf0, 0x10, 0x10, 0x90,
  38.                                                  0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0xf0,
  39.                                                  0x40, 0x20, 0x40, 0x20, 0x40, 0x20, 0x40, 0x20,
  40.                                                  0xf0, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
  41.                                                  0x90, 0x10, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00,
  42.                                                  0x00, 0x00, 0x00, 0x00, 0x0f, 0x08, 0x08, 0x09,
  43.                                                  0x09, 0x08, 0x08, 0x0f, 0x00, 0x00, 0x00, 0x00,
  44.                                                  0xff, 0x00, 0x00, 0x07, 0x08, 0x10, 0x10, 0x10,
  45.                                                  0x10, 0x10, 0x10, 0x08, 0x07, 0x00, 0x00, 0xff,
  46.                                                  0xff, 0x00, 0x00, 0xe0, 0x10, 0x08, 0x08, 0x08,
  47.                                                  0x08, 0x08, 0x08, 0x10, 0xe0, 0x00, 0x00, 0xff,
  48.                                                  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  49.                                                 };
  50. unsigned char PlayFieldMap[]  = {0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x04, 0x05, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x07, 0x08, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x09, 0x05, 0x46, 0x0A, 0x0B, 0x0B, 0x0C, 0x46, 0x0A, 0x0B, 0x0B, 0x0B, 0x0C, 0x46, 0x07, 0x08, 0x46, 0x0A, 0x0B, 0x0B, 0x0B, 0x0C, 0x46, 0x0A, 0x0B, 0x0B, 0x0C, 0x46, 0x09, 0x05, 0x86, 0x07, 0x06, 0x06, 0x08, 0x46, 0x07, 0x06, 0x06, 0x06, 0x08, 0x46, 0x07, 0x08, 0x46, 0x07, 0x06, 0x06, 0x06, 0x08, 0x46, 0x07, 0x06, 0x06, 0x08, 0x86, 0x09, 0x05, 0x46, 0x0D, 0x0E, 0x0E, 0x0F, 0x46, 0x0D, 0x0E, 0x0E, 0x0E, 0x0F, 0x46, 0x0D, 0x0F, 0x46, 0x0D, 0x0E, 0x0E, 0x0E, 0x0F, 0x46, 0x0D, 0x0E, 0x0E, 0x0F, 0x46, 0x09, 0x05, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x09, 0x05, 0x46, 0x0A, 0x0B, 0x0B, 0x0C, 0x46, 0x0A, 0x0C, 0x46, 0x0A, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0C, 0x46, 0x0A, 0x0C, 0x46, 0x0A, 0x0B, 0x0B, 0x0C, 0x46, 0x09, 0x05, 0x46, 0x0D, 0x0E, 0x0E, 0x0F, 0x46, 0x07, 0x08, 0x46, 0x0D, 0x0E, 0x0E, 0x10, 0x11, 0x0E, 0x0E, 0x0F, 0x46, 0x07, 0x08, 0x46, 0x0D, 0x0E, 0x0E, 0x0F, 0x46, 0x09, 0x05, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x07, 0x08, 0x46, 0x46, 0x46, 0x46, 0x07, 0x08, 0x46, 0x46, 0x46, 0x46, 0x07, 0x08, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x09, 0x12, 0x13, 0x13, 0x13, 0x13, 0x0C, 0x46, 0x07, 0x14, 0x0B, 0x0B, 0x0C, 0x06, 0x07, 0x08, 0x06, 0x0A, 0x0B, 0x0B, 0x15, 0x08, 0x46, 0x0A, 0x13, 0x13, 0x13, 0x13, 0x16, 0x06, 0x06, 0x06, 0x06, 0x06, 0x05, 0x46, 0x07, 0x11, 0x0E, 0x0E, 0x0F, 0x06, 0x0D, 0x0F, 0x06, 0x0D, 0x0E, 0x0E, 0x10, 0x08, 0x46, 0x09, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x05, 0x46, 0x07, 0x08, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x07, 0x08, 0x46, 0x09, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x05, 0x46, 0x07, 0x08, 0x06, 0x17, 0x13, 0x18, 0x19, 0x19, 0x1A, 0x13, 0x1B, 0x06, 0x07, 0x08, 0x46, 0x09, 0x06, 0x06, 0x06, 0x06, 0x06, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0F, 0x46, 0x0D, 0x0F, 0x06, 0x09, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x05, 0x06, 0x0D, 0x0F, 0x46, 0x0D, 0x01, 0x01, 0x01, 0x01, 0x01, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x46, 0x06, 0x06, 0x06, 0x09, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x05, 0x06, 0x06, 0x06, 0x46, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x13, 0x13, 0x13, 0x13, 0x13, 0x0C, 0x46, 0x0A, 0x0C, 0x06, 0x09, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x05, 0x06, 0x0A, 0x0C, 0x46, 0x0A, 0x13, 0x13, 0x13, 0x13, 0x13, 0x06, 0x06, 0x06, 0x06, 0x06, 0x05, 0x46, 0x07, 0x08, 0x06, 0x1C, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1D, 0x06, 0x07, 0x08, 0x46, 0x09, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x05, 0x46, 0x07, 0x08, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x07, 0x08, 0x46, 0x09, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x05, 0x46, 0x07, 0x08, 0x06, 0x0A, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0C, 0x06, 0x07, 0x08, 0x46, 0x09, 0x06, 0x06, 0x06, 0x06, 0x06, 0x00, 0x01, 0x01, 0x01, 0x01, 0x0F, 0x46, 0x0D, 0x0F, 0x06, 0x0D, 0x0E, 0x0E, 0x10, 0x11, 0x0E, 0x0E, 0x0F, 0x06, 0x0D, 0x0F, 0x46, 0x0D, 0x01, 0x01, 0x01, 0x01, 0x04, 0x05, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x07, 0x08, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x09, 0x05, 0x46, 0x0A, 0x0B, 0x0B, 0x0C, 0x46, 0x0A, 0x0B, 0x0B, 0x0B, 0x0C, 0x46, 0x07, 0x08, 0x46, 0x0A, 0x0B, 0x0B, 0x0B, 0x0C, 0x46, 0x0A, 0x0B, 0x0B, 0x0C, 0x46, 0x09, 0x05, 0x46, 0x0D, 0x0E, 0x10, 0x08, 0x46, 0x0D, 0x0E, 0x0E, 0x0E, 0x0F, 0x46, 0x0D, 0x0F, 0x46, 0x0D, 0x0E, 0x0E, 0x0E, 0x0F, 0x46, 0x07, 0x11, 0x0E, 0x0F, 0x46, 0x09, 0x05, 0x86, 0x46, 0x46, 0x07, 0x08, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x06, 0x06, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x07, 0x08, 0x46, 0x46, 0x86, 0x09, 0x1E, 0x0B, 0x0C, 0x46, 0x07, 0x08, 0x46, 0x0A, 0x0C, 0x46, 0x0A, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0C, 0x46, 0x0A, 0x0C, 0x46, 0x07, 0x08, 0x46, 0x0A, 0x0B, 0x1F, 0x20, 0x0E, 0x0F, 0x46, 0x0D, 0x0F, 0x46, 0x07, 0x08, 0x46, 0x0D, 0x0E, 0x0E, 0x10, 0x11, 0x0E, 0x0E, 0x0F, 0x46, 0x07, 0x08, 0x46, 0x0D, 0x0F, 0x46, 0x0D, 0x0E, 0x21, 0x05, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x07, 0x08, 0x46, 0x46, 0x46, 0x46, 0x07, 0x08, 0x46, 0x46, 0x46, 0x46, 0x07, 0x08, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x09, 0x05, 0x46, 0x0A, 0x0B, 0x0B, 0x0B, 0x0B, 0x15, 0x14, 0x0B, 0x0B, 0x0C, 0x46, 0x07, 0x08, 0x46, 0x0A, 0x0B, 0x0B, 0x15, 0x14, 0x0B, 0x0B, 0x0B, 0x0B, 0x0C, 0x46, 0x09, 0x05, 0x46, 0x0D, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x46, 0x0D, 0x0F, 0x46, 0x0D, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x46, 0x09, 0x05, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x09, 0x12, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x16};
  51.  
  52. const unsigned char TILE_FREE = 6;
  53. const unsigned char TILE_SIZE = 8;
  54. const unsigned int MAP_COLUMNS = 28;
  55.  
  56. const unsigned char IDLE = 0;
  57. const unsigned char UP = 1;
  58. const unsigned char LEFT = 2;
  59. const unsigned char RIGHT = 3;
  60. const unsigned char DOWN = 4;
  61.  
  62. Arduboy2 arduboy;
  63.  
  64. int heroX = 14 * TILE_SIZE - TILE_SIZE / 2;
  65. int heroY = 17 * TILE_SIZE;
  66. unsigned int pellets = 244;
  67. unsigned int heroSpeed = 2;
  68. unsigned char heroDirection = RIGHT;
  69. unsigned char desiredDirection = IDLE;
  70. boolean debug = true;
  71.  
  72. int scrollX = 0;
  73. int scrollY = 0;
  74.  
  75. void setup() {
  76.   arduboy.boot();
  77.   arduboy.flashlight();
  78.   arduboy.setFrameRate(30);
  79.   arduboy.audio.begin();
  80. }
  81.  
  82. void loop() {
  83.   if (!(arduboy.nextFrame())) {
  84.     return;
  85.   }
  86.  
  87.   // Game Logic
  88.   processButtons();
  89.   moveHero();
  90.   positionPlayField();
  91.  
  92.   // Display Logic
  93.   arduboy.clear();
  94.   drawPlayField();
  95.   drawHero();
  96.  
  97.   if ( debug = !debug ) {
  98.     arduboy.fillRect( 1, 1, 1, 1, 1 );
  99.   }
  100.   arduboy.display();
  101. }
  102.  
  103. void processButtons() {
  104.   if ( arduboy.pressed(RIGHT_BUTTON) ) {
  105.     requestDirection( RIGHT, LEFT );
  106.   }
  107.   if ( arduboy.pressed(LEFT_BUTTON) ) {
  108.     requestDirection( LEFT, RIGHT );
  109.   }
  110.   if ( arduboy.pressed(DOWN_BUTTON) ) {
  111.     requestDirection( DOWN, UP );
  112.   }
  113.   if ( arduboy.pressed(UP_BUTTON) ) {
  114.     requestDirection( UP, DOWN );
  115.   }
  116. }
  117.  
  118. void requestDirection( const unsigned char direction, const unsigned char counterpart ) {
  119.   if ( heroDirection == counterpart ) {
  120.     heroDirection == direction;
  121.     desiredDirection = direction;
  122.   } else {
  123.     desiredDirection = direction;
  124.   }
  125. }
  126.  
  127. void moveHero() {
  128.   int remaining = heroSpeed;
  129.   while (0 < remaining ) {
  130.     int modX = heroX % TILE_SIZE;
  131.     int modY = heroY % TILE_SIZE;
  132.     if (0 == modX && 0 == modY ) {
  133.       const int tileX = heroX / TILE_SIZE;
  134.       const int tileY = heroY / TILE_SIZE;
  135.       const unsigned char food = evalFood(tileX, tileY);
  136.       if ( 0 < food ) {
  137.         beep();
  138.         if ( munchFood(tileX, tileY) ) {
  139.           heroDirection = IDLE;
  140.           desiredDirection = IDLE;
  141.         }
  142.       }
  143.       checkHeroDirection(tileX, tileY);
  144.       switch ( heroDirection ) {
  145.         case IDLE: {
  146.             return;
  147.           }
  148.         case UP: {
  149.             if ( TILE_FREE == evalMap( tileX, tileY - 1 ) ) {
  150.               heroY -= remaining;
  151.             } else {
  152.               heroDirection = IDLE;
  153.               desiredDirection = IDLE;
  154.             }
  155.             return;
  156.           }
  157.         case LEFT: {
  158.             if ( -1 == tileX ) {
  159.               heroX = MAP_COLUMNS * TILE_SIZE;
  160.               onTeleport();
  161.               continue;
  162.             }
  163.             if ( TILE_FREE == evalMap( tileX - 1, tileY ) ) {
  164.               heroX -= remaining;
  165.             } else {
  166.               heroDirection = IDLE;
  167.               desiredDirection = IDLE;
  168.             }
  169.             return;
  170.           }
  171.         case RIGHT: {
  172.             if ( MAP_COLUMNS == tileX ) {
  173.               heroX = -TILE_SIZE;
  174.               onTeleport();
  175.               continue;
  176.             }
  177.             if ( TILE_FREE == evalMap( tileX + 1, tileY ) ) {
  178.               heroX += remaining;
  179.             } else {
  180.               heroDirection = IDLE;
  181.               desiredDirection = IDLE;
  182.             }
  183.             return;
  184.           }
  185.         case DOWN: {
  186.             if ( TILE_FREE == evalMap( tileX, tileY + 1 ) ) {
  187.               heroY += remaining;
  188.             } else {
  189.               heroDirection = IDLE;
  190.               desiredDirection = IDLE;
  191.             }
  192.             return;
  193.           }
  194.       }
  195.     }
  196.     switch ( heroDirection ) {
  197.       case UP: {
  198.           if ( remaining < modY ) {
  199.             heroY -= remaining;
  200.             return;
  201.           } else {
  202.             heroY -= modY;
  203.             remaining -= modY;
  204.           }
  205.           break;
  206.         }
  207.       case LEFT: {
  208.           if ( remaining < modX ) {
  209.             heroX -= remaining;
  210.             return;
  211.           } else {
  212.             heroX -= modX;
  213.             remaining -= modX;
  214.           }
  215.           break;
  216.         }
  217.       case RIGHT: {
  218.           modX = TILE_SIZE - modX;
  219.           if ( remaining < modX ) {
  220.             heroX += remaining;
  221.             return;
  222.           } else {
  223.             heroX += modX;
  224.             remaining -= modX;
  225.           }
  226.           break;
  227.         }
  228.       case DOWN: {
  229.           modY = TILE_SIZE - modY;
  230.           if ( remaining < modY ) {
  231.             heroY += remaining;
  232.             return;
  233.           } else {
  234.             heroY += modY;
  235.             remaining -= modY;
  236.           }
  237.           break;
  238.         }
  239.     }
  240.   }
  241. }
  242.  
  243. void checkHeroDirection( const int tileX, const int tileY ) {
  244.   switch ( desiredDirection ) {
  245.     case UP: {
  246.         if ( TILE_FREE == evalMap( tileX, tileY - 1 ) ) {
  247.           heroDirection = UP;
  248.           desiredDirection = IDLE;
  249.         }
  250.         return;
  251.       }
  252.     case LEFT: {
  253.         if ( TILE_FREE == evalMap( tileX - 1, tileY ) ) {
  254.           heroDirection = LEFT;
  255.           desiredDirection = IDLE;
  256.         }
  257.         return;
  258.       }
  259.     case RIGHT: {
  260.         if ( TILE_FREE == evalMap( tileX + 1, tileY ) ) {
  261.           heroDirection = RIGHT;
  262.           desiredDirection = IDLE;
  263.         }
  264.         return;
  265.       }
  266.     case DOWN: {
  267.         if ( TILE_FREE == evalMap( tileX, tileY + 1 ) ) {
  268.           heroDirection = DOWN;
  269.           desiredDirection = IDLE;
  270.         }
  271.         return;
  272.       }
  273.   }
  274. }
  275.  
  276. void positionPlayField() {
  277.   scrollX = heroX - 64;
  278.   scrollY = heroY - 32;
  279.   if ( scrollX < 0 ) {
  280.     scrollX = 0;
  281.   } else if ( scrollX > 96 ) {
  282.     scrollX = 96;
  283.   }
  284.   if ( scrollY < 0 ) {
  285.     scrollY = 0;
  286.   } else if ( scrollY > 184 ) {
  287.     scrollY = 184;
  288.   }
  289. }
  290.  
  291. void drawPlayField() {
  292.   const int tileX = scrollX / TILE_SIZE;
  293.   const int tileY = scrollY / TILE_SIZE;
  294.   const int modX = scrollX % TILE_SIZE;
  295.   const int modY = scrollY % TILE_SIZE;
  296.   for (int y = 0 ; y <= 8 ; y++ ) {
  297.     for (int x = 0 ; x <= 16 ; x++ ) {
  298.       const unsigned char mapX = x + tileX;
  299.       const unsigned char mapY = y + tileY;
  300.       const unsigned char tile = evalMap(mapX, mapY);
  301.       const unsigned int bitmapX = x * TILE_SIZE - modX;
  302.       const unsigned int bitmapY = y * TILE_SIZE - modY;
  303.       arduboy.drawBitmap(bitmapX, bitmapY, PlayFieldTiles + (tile << 3), TILE_SIZE, TILE_SIZE, 1);
  304.       const unsigned char food = evalFood(mapX, mapY);
  305.       if ( 0 < food ) {
  306.         arduboy.fillCircle( bitmapX + 4, bitmapY + 4, 1, 1 );
  307.       }
  308.     }
  309.   }
  310. }
  311.  
  312. void drawHero() {
  313.   arduboy.drawRect(heroX - scrollX, heroY - scrollY, TILE_SIZE + 1, TILE_SIZE + 1, 1);
  314. }
  315.  
  316. unsigned char evalMap( const int x, const int y ) {
  317.   // Allow to leave field
  318.   if ( 0 > x || x >= MAP_COLUMNS ) {
  319.     return TILE_FREE;
  320.   }
  321.   const unsigned int tile = y * MAP_COLUMNS + x;
  322.   return PlayFieldMap[tile] & 0x3F;
  323. }
  324.  
  325. unsigned char evalFood( const int x, const int y ) {
  326.   const unsigned int tile = y * MAP_COLUMNS + x;
  327.   return PlayFieldMap[tile] >> 5;
  328. }
  329.  
  330. bool munchFood( const int x, const int y ) {
  331.   const unsigned int tile = y * MAP_COLUMNS + x;
  332.   const unsigned char data = PlayFieldMap[tile] & 0x3F;
  333.   PlayFieldMap[tile] = data;
  334.   return 0 == --pellets;
  335. }
  336.  
  337. void onTeleport() {
  338.   tone(PIN_SPEAKER_2, 110, 200);
  339. }
  340.  
  341. void beep() {
  342.   tone(PIN_SPEAKER_1, 220, 20);
  343. }
Advertisement
RAW Paste Data Copied
Advertisement