123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #ifndef _GAMEBOARD_H_
- #define _GAMEBOARD_H_
- #include <Arduino.h>
- #include <M5Stack.h>
- #define LCD_WIDTH 320
- #define LCD_HEIGHT 240
- #define BLOCK_SIZE 16
- #define BLOCK_STATUS_EMPTY 0x00
- #define BLOCK_STATUS_HEAD 0x01
- #define BLOCK_STATUS_CHERRY 0x200
- #define DIRECTION_UP 0x01
- #define DIRECTION_RIGHT 0x02
- #define DIRECTION_DOWN 0x03
- #define DIRECTION_LEFT 0x04
- class GameBoardClass {
- public:
-
- void begin(uint8_t game_cycles = 4);
-
- void refresh();
-
- void startSnake();
-
-
- bool moveSnake();
-
- void setDirection(uint8_t direction);
-
- void addCherry();
-
- uint16_t getMaxScore();
-
- private:
-
-
- uint8_t current_direction = 0x00;
- uint8_t current_head_x = 0x00;
- uint8_t current_head_y = 0x00;
-
- uint8_t max_game_cycles = 4;
- uint8_t current_game_cycle = 0;
-
-
- uint8_t board_width = LCD_WIDTH / BLOCK_SIZE;
- uint8_t board_height = LCD_HEIGHT / BLOCK_SIZE;
-
- uint16_t board_data[LCD_WIDTH / BLOCK_SIZE][LCD_HEIGHT / BLOCK_SIZE];
-
- uint8_t board_changes[LCD_WIDTH / BLOCK_SIZE][LCD_HEIGHT / BLOCK_SIZE];
-
-
- void setCell(uint8_t x, uint8_t y, uint16_t status);
-
- void drawChange(uint8_t x, uint8_t y);
-
- void removeTail();
- };
- extern GameBoardClass GameBoard;
- #endif
|