24 #define ENT_OBSTACLE 1 38 const byte
LETTER_START [] = {2,1, 2,2, 5,1, 5,2, 1,4, 1,5, 2,6, 3,6, 4,6, 5,6, 6,5, 6,4 };
39 const byte
LETTER_0 [] = { 0,0, 0,1, 0,2, 0,3, 0,4, 1,0, 1,4, 2,0, 2,1, 2,2, 2,3, 2,4 };
40 const byte
LETTER_1 [] = { 1,0, 1,1, 1,2, 1,3, 1,4 };
41 const byte
LETTER_2 [] = { 1,0, 1,2, 1,3, 1,4, 2,0, 2,1, 2,2, 2,4 };
42 const byte
LETTER_3 [] = { 1,0, 1,2, 1,4, 2,0, 2,1, 2,2, 2,3, 2,4 };
43 const byte
LETTER_4 [] = { 1,0, 1,1, 1,2, 2,2, 2,3, 2,4 };
44 const byte
LETTER_5 [] = { 1,0, 1,1, 1,2, 1,4, 2,0, 2,2, 2,3, 2,4 };
45 const byte
LETTER_6 [] = { 0,0, 0,1, 0,2, 0,3, 0,4, 1,0, 1,2, 1,4, 2,0, 2,2, 2,3, 2,4 };
46 const byte
LETTER_7 [] = { 1,0, 2,0, 2,1, 2,2, 2,3, 2,4 };
47 const byte
LETTER_8 [] = { 0,0, 0,1, 0,2, 0,3, 0,4, 1,0, 1,2, 1,4, 2,0, 2,1, 2,2, 2,3, 2,4 };
48 const byte
LETTER_9 [] = { 0,0, 0,1, 0,2, 0,4, 1,0, 1,2, 1,4, 2,0, 2,1, 2,2, 2,3, 2,4 };
90 void lightPattern(
const byte letter[],
size_t letter_length, byte x, byte y,
char color);
91 void drawChar(
char c, byte x, byte y,
char color);
104 static uint8_t cols[] = {
120 for(
int i=0;i<10;i++){
127 Serial.begin(115200);
168 return (millis() -
g_time);
196 for (byte x =
MINX; x <=
MAXX; x++){
197 for (byte y =
MINY; y <=
MAXY; y++){
202 Serial.println(
"--GAME INITIALISED--");
210 bool pressed =
false;
217 for (
int i = 1; i <= 5; i++){
252 Serial.println(
"TOTAL SCORE: " + String(
g_score+1));
257 while (temp_score.length() < 4){
258 temp_score =
'0' + temp_score;
260 for (
int i = 0; i < temp_score.length(); i ++){
261 EEPROM.write(addr, (temp_score[i]));
262 Serial.println(
"--EEPROM WRITE: " + String(temp_score[i]) +
" AT " + String(addr));
282 Serial.println(
"[001] WARNING! INVALID GAME STATE DETECTED: "+ String(
g_state) +
" !");
315 Serial.println(
"[001] WARNING! INVALID GAME STATE DETECTED: "+ String(
g_state) +
" !");
323 String highscore =
"";
326 String temp_score =
"";
344 for (byte x =
MINX; x <=
MAXX; x++){
345 for (byte y =
MINY; y <=
MAXY; y++){
377 Serial.println(
"[001] WARNING! INVALID GAME STATE DETECTED: "+ String(
g_state) +
" !");
388 Serial.println(
".ControlSpeed(): speedlevel: " + String(
g_speedLevel) +
" | time / 20000: " + String(
g_ticks / 20000) +
" | speed: " + String(
g_speed));
399 byte chancePower = 25;
403 byte generator = random(100);
404 byte generator2 = random(100);
405 if (generator <= chanceAny){
406 if (generator2 <= chancePower){
422 }
else if ( i < 0 && g_player >
MINY){
439 for (byte x =
MINX; x <=
MAXX; x++){
440 for (byte y =
MINY; y <=
MAXY; y++){
474 Serial.println(
"[003] WARNING! WRONG ENT STATE AT (" + String(x) +
" , " + String(y) +
") !");
488 Serial.println(
"TOTAL SCORE: " + String(
g_score+1));
511 stringScore = String(score / 100);
512 }
else if (score >= 100){
514 stringScore = String(score / 10);
515 }
else if (score < 10){
517 stringScore =
"0" + String(score / 10);
520 stringScore = String(score);
523 for (byte i =
MINX; i <= ((stringScore.length()+1) * 3); i += 4){
530 void lightPattern(
const byte letter[],
size_t letter_length, byte x, byte y,
char color){
531 for (
int i = 0; i < letter_length; i += 2){
532 AberLED.
set(letter[i] + x, letter[i+1] + y, color);
533 #ifdef DEBUG //I use for loop to light up different LEDs which coordinates I get from arrays at the top 534 Serial.println(
"#DRAWLETTER: (" + String(i) +
", " + String(i+1) +
")");
578 String highscore =
"";
581 String temp_score =
"";
582 for (
int i = 0; i < 4; i ++){
583 character = EEPROM.read(addr);
584 highscore = highscore + String(character);
586 Serial.println(
"--EEPROMREAD: " + String(character) +
" AT " + String(addr));
590 if (highscore.toInt() <
g_score){
593 while (temp_score.length() < 4){
594 temp_score =
'0' + temp_score;
596 for (
int i = 0; i < temp_score.length(); i ++){
597 EEPROM.write(addr, (temp_score[i]));
598 Serial.println(
"--EEPROM WRITE: " + String(temp_score[i]) +
" AT " + String(addr));
603 Serial.println(
".EEPROMFUNC: highscore:" + String(highscore.toInt()) +
" | g_score: " + String(
g_score));
void clear()
Set all pixels in the back buffer to black.
void drawChar(char c, byte x, byte y, char color)
void begin(AberLEDFlags flags=AF_TFTDISPLAY, uint8_t *colourMap=NULL)
Initialises all pin modes, clears the buffers, starts the interrupt and begins to output data to the ...
void drawScore(int score)
unsigned long getLoopTime()
const int OBSTACLE_CHANGE_TIME
int getButtonDown(unsigned char c)
Return nonzero if the button has been pressed since the last swap(). It's better to use the UP...
AberLEDClass AberLED
this is the single instance of the LED class - for documentation see AberLEDClass.
void clearText()
clear the string which is written to the text area on a TFT display.
The declaration for the AberLED class. Many implementation details are inside the AberLED implementat...
void addTicks(unsigned long n)
const int SPEED_CHANGE_TIME
byte g_entities[MAXX+1][MAXY+1]
unsigned long getStateTime()
#define GREEN
the green colour for pixels, used in set()
#define YELLOW
the yellow colour for pixels, used in set()
#define RED
the red colour for pixels, used in set()
void moveEntity(byte x, byte y)
void addToText(const char *s)
Append a string to the text area on a TFT display. Does nothing if the display is not a TFT display...
const byte LETTER_START[]
void swap()
Call this code to finish drawing operations. It swaps the back and front buffer, so that the newly wr...
void gotoState(int state)
void lightPattern(const byte letter[], size_t letter_length, byte x, byte y, char color)
void set(int x, int y, unsigned char col)
This sets the given pixel in the back buffer to the given value. The pixel values are 0 (off)...
bool g_player_pause_blink