//// ////
//// LOOK OVER HERE!!!!!!! ////
//// 🠋🠋🠋 ////
//// Do the konami code to unlock a secret menu ////
//// ////
//// + + - - ≪ ≫ ≪ ≫ C 0 ////
//// ////
//// ////
//// scroll using + & - ////
//// ////
//// :) ////
//// ////
//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "IRLremote.h"
#include <EEPROM.h>
// Choose a valid PinInterrupt or PinChangeInterrupt* pin of your Arduino board
#define pinIR 2
const int buzzerPin = 8;
// Choose the IR protocol of your remote. See the other example for this.
CNec IRLremote;
#define pinLed LED_BUILTIN
#if defined(ARDUINO) && ARDUINO >= 100
#define printByte(args) write(args);
#else
#define printByte(args) print(args,BYTE);
#endif
int f = 0;
float jumpstart = 0;
bool isJumping = false;
int i = 0;
int cactusPos[5] = {16, 23, 31, 40, 50};
bool cactusOrBird[5] = {0, 1, 0, 1, 0};
byte cactusCursor = 0;
int inputs[20] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
byte inputCursor = 0;
//the bigger the number the slower: (frame/speed)
long musicStartPoint = 0;
long jumpSFX = 0;
float masterSpeed = 1;
float speed = 6.123456789123456789;
float normalSpeed = 6;
float speedWhenJumping = 3;
float speedf = 16;
bool die = true;
bool invincibility = false;
int highScore = 0;
int highScore2 = 0;
byte mode = 0;
bool dim = true;
bool skipDeath = false;
bool music = false;
int musicCursor = 0;
//death invisible methode
byte menuScroll = 0;
int eepromtest = 0;
//int score = 0;
//notes and timing for music
int melody[] = {
262, 330, 392, 523, 659, 784, 523, 392,
440, 523, 659, 440, 523, 330, 440, 330,
349, 440, 523, 698, 440, 523, 349, 523,
392, 492, 587, 784, 587, 492, 392, 262,
262, 392, 262, 392, 330, 492, 330, 492,
262, 330, 392, 523, 659, 784, 659, 523
};
int noteDurations[] = {
150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150,
140, 140, 140, 140, 140, 140, 140, 140,
140, 140, 140, 140, 140, 140, 140, 140,
130, 130, 130, 130, 130, 130, 130, 130,
120, 120, 120, 120, 120, 120, 150, 150
};
uint8_t dino[24]
{
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00111,
B00101,
B00111,
B10110,
B10111,
B11110,
B01110,
B01010,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
uint8_t animateDino1[8]
{
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
uint8_t animateDino2[8]
{
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
uint8_t cactus[8] = {
B00100,
B10101,
B10101,
B11101,
B00101,
B00111,
B00100,
B00100
};
uint8_t bird[8] = {
B00000,
B00010,
B00011,
B01011,
B11111,
B00110,
B00011,
B00000
};
uint8_t bird2[8] = {
B00000,
B00000,
B00000,
B01000,
B11111,
B00111,
B00011,
B00000
};
uint8_t blank[8] = {
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
uint8_t amogus[8] = {
B00000,
B01110,
B00010,
B01111,
B01111,
B01110,
B01010,
B00000
};
uint8_t heart[8] = {0x0, 0xa, 0x1f, 0x1f, 0xe, 0x4, 0x0};
uint8_t duck[8] = {0x0, 0xc, 0x1d, 0xf, 0xf, 0x6, 0x0};
uint8_t check[8] = {0x0, 0x1, 0x3, 0x16, 0x1c, 0x8, 0x0};
uint8_t cross[8] = {0x0, 0x1b, 0xe, 0x4, 0xe, 0x1b, 0x0};
uint8_t retarrow[8] = { 0x1, 0x1, 0x5, 0x9, 0x1f, 0x8, 0x4};
uint8_t checkerboard[16] {0x15, 0xa, 0x15, 0xa, 0x15, 0xa, 0x15, 0xa,
0xa, 0x15, 0xa, 0x15, 0xa, 0x15, 0xa, 0x15
};
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
Serial.begin(9600);
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.createChar(0, blank);
lcd.createChar(1, cactus);
lcd.createChar(4, bird);
lcd.createChar(5, amogus);
lcd.createChar(6, bird2);
pinMode(pinLed, OUTPUT);
pinMode(buzzerPin, OUTPUT);
if (!IRLremote.begin(pinIR))
{
Serial.println(F("You did not choose a valid pin."));
}
//display dino characters at start
lcd.setCursor(0, 0);
lcd.printByte(2);
lcd.setCursor(0, 1);
lcd.printByte(3);
//fix problem with the predetermined cactus positions
cactusPos[0] = cactusPos[0] * speed;
cactusPos[1] = cactusPos[1] * speed;
cactusPos[2] = cactusPos[2] * speed;
cactusPos[3] = cactusPos[3] * speed;
cactusPos[4] = cactusPos[4] * speed;
//create dino characters at start
animateDino1[0] = dino[0];
animateDino1[1] = dino[1];
animateDino1[2] = dino[2];
animateDino1[3] = dino[3];
animateDino1[4] = dino[4];
animateDino1[5] = dino[5];
animateDino1[6] = dino[6];
animateDino1[7] = dino[7];
lcd.createChar(2, animateDino1);
animateDino2[0] = dino[8];
animateDino2[1] = dino[9];
animateDino2[2] = dino[10];
animateDino2[3] = dino[11];
animateDino2[4] = dino[12];
animateDino2[5] = dino[13];
animateDino2[6] = dino[14];
animateDino2[7] = dino[15];
lcd.createChar(3, animateDino2);
menu();
}
void menu()
{
noTone(buzzerPin);
if (i > 0)
{
lcd.setCursor(4, 0);
if (skipDeath == false)
{
delay(400);
tone(buzzerPin, 440);
lcd.print("Y"); delay(100); lcd.print("O"); delay(100); lcd.print("U"); delay(100);
noTone(buzzerPin);
lcd.print(" "); delay(100);
tone(buzzerPin, 349);
lcd.print("D"); delay(100); lcd.print("I"); delay(100);lcd.print("E");delay(100); lcd.print("D");
noTone(buzzerPin);
delay(100);
tone(buzzerPin, 294); // D4 note
delay(300);
noTone(buzzerPin);
delay(100);
tone(buzzerPin, 220); // A3 note
delay(600); // Longer final note
noTone(buzzerPin);
tone(buzzerPin, 440); // D4 note
delay(40);
noTone(buzzerPin);
delay(10);
lcd.clear();
delay(500);
}
lcd.setCursor(0, 0); lcd.print("SCORE "); lcd.print(int(i));
if (mode == 0)
{
lcd.setCursor(0, 1); lcd.print("HIGH "); lcd.print(int(highScore));
} else if (mode == 1)
{
lcd.setCursor(0, 1); lcd.print("HIGH "); lcd.print(int(highScore2));
}
}
inputCursor = -1;
for (int a = 0; a < 20; a++)
{
inputs[a] = -1;
}
while (die == true)
{
/*
2
2
152
152
224
144
224
144
176
104
48
24
122
90
56
16
66
74
82
*/
if ((inputCursor < 10 || inputCursor == 255) && i < 1)
{
lcd.setCursor(0, 0);
lcd.printByte(2);
lcd.setCursor(0, 1);
lcd.printByte(3);
lcd.setCursor(2, 0);
lcd.print("PRESS ANY KEY");
//IRLremote.read();
}
delay(100);
while(IRLremote.available()) {
IRLremote.read();
delay(10);
}
// Now wait for a fresh button press
while(!IRLremote.available()) {
delay(10);
}
// static unsigned long lastPressTime = 0;
//if(IRLremote.available() && (millis() - lastPressTime > 300)) {
// lastPressTime = millis();}
if (IRLremote.available()) //if it receive a code
{
auto data = IRLremote.read(); //this gets the code that was sent
Serial.println(data.command); //prints the code of the button that was pressed (data.command is the code received)
if (data.command != 0)
{
if ((data.command == 2 || data.command == 152 || data.command == 70 || data.command == 21) && inputCursor > 9) //12,24,94,8,28,90,66,82,74
{
Serial.println("scroll");
if (inputCursor > 9 && inputCursor != 255 && (data.command == 2 || data.command == 70))
{
menuScroll--;
if (menuScroll <= 0 || menuScroll == 255 )
{
menuScroll = 0;
}
} else if (inputCursor > 9 && inputCursor != 255 && (data.command == 152 || data.command == 21))
{
menuScroll++;
if (menuScroll >= 3)
{
menuScroll--;
}
}
}
if ((data.command == 2 || data.command == 70 ) && inputCursor == 255) {
inputCursor = 0;
//Serial.println(inputCursor);
}
/*
70
70
21
21
68
67
68
67
9
7
*/
Serial.println(inputCursor);
inputs[inputCursor] = data.command;
//Serial.println(inputs[11]);
if ((inputs[0] == -1 || inputs[0] == 2 || inputs[0] == 70) &&
(inputs[1] == -1 || inputs[1] == 2 || inputs[1] == 70) &&
(inputs[2] == -1 || inputs[2] == 152 || inputs[2] == 21) &&
(inputs[3] == -1 || inputs[3] == 152 || inputs[3] == 21) &&
(inputs[4] == -1 || inputs[4] == 224 || inputs[4] == 68) &&
(inputs[5] == -1 || inputs[5] == 144 || inputs[5] == 67) &&
(inputs[6] == -1 || inputs[6] == 224 || inputs[6] == 68) &&
(inputs[7] == -1 || inputs[7] == 144 || inputs[7] == 67) &&
(inputs[8] == -1 || inputs[8] == 176 || inputs[8] == 9) &&
(inputs[9] == -1 || inputs[9] == 104 || inputs[9] == 7))
{
inputCursor++;
if (inputCursor >= 10)
{
Serial.println("KONAMI CODE!!!");
inputCursor = 15;
for (int a = 0; a < 8; a++)
{
animateDino1[a] = checkerboard[a];
animateDino2[a] = checkerboard[a + 8];
}
lcd.createChar(2, animateDino1);
lcd.createChar(3, animateDino2);
for (int b = 0; b < 8; b++)
{
lcd.setCursor(0, 0);
for (int a = 0; a < 16; a++)
{
lcd.printByte(2);
}
lcd.setCursor(0, 1);
for (int a = 0; a < 16; a++)
{
lcd.printByte(2);
}
delay(10);
lcd.setCursor(0, 0);
for (int a = 0; a < 16; a++)
{
lcd.printByte(3);
}
lcd.setCursor(0, 1);
for (int a = 0; a < 16; a++)
{
lcd.printByte(3);
}
}
if (menuScroll == 0)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.printByte(2);
lcd.print("1 NORMAL");
lcd.setCursor(15, 0);
lcd.printByte(2);
lcd.setCursor(0, 1);
lcd.printByte(2);
lcd.print("2 IMPOSSIBLE");
lcd.setCursor(15, 1);
lcd.printByte(2);
} else if (menuScroll == 1)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.printByte(2);
lcd.print("2 IMPOSSIBLE");
lcd.setCursor(15, 0);
lcd.printByte(2);
if (menuScroll == 1 || menuScroll == 0)
{
lcd.setCursor(0, 1);
} else if (menuScroll == 2)
{
lcd.setCursor(0, 0);
}
lcd.printByte(2);
if (dim == true)
{
lcd.print("3 INVINC OFF");
} else if (dim == false)
{
lcd.print("3 INVINC ON");
}
if (menuScroll == 1 || menuScroll == 0)
{
lcd.setCursor(15, 1);
} else if (menuScroll == 2)
{
lcd.setCursor(15, 0);
}
lcd.printByte(2);
} else if (menuScroll == 2)
{
lcd.clear();
if (menuScroll == 2)
{
lcd.setCursor(0, 0);
} else if (menuScroll == 3)
{
lcd.setCursor(0, 0);
}
lcd.printByte(2);
if (dim == true)
{
lcd.print("3 INVINC OFF");
} else if (dim == false)
{
lcd.print("3 INVINC ON");
}
if (menuScroll == 2)
{
lcd.setCursor(15, 0);
} else if (menuScroll == 3)
{
lcd.setCursor(15, 0);
}
lcd.printByte(2);
lcd.setCursor(0, 1);
lcd.printByte(2);
if (skipDeath == true)
{
lcd.print("4 SKIP ON");
} else if (skipDeath == false)
{
lcd.print("4 SKIP OFF");
}
lcd.setCursor(15, 1);
lcd.printByte(2);
//lcd.setCursor(0,1);
//lcd.printByte(2);
//lcd.print("4 adsfjkl");
//lcd.setCursor(15,1);
//lcd.printByte(2);
}
}
} else if (inputCursor <= 10)
{
Serial.println("NO");
inputCursor = -1;
for (byte d = 0; d < 20; d++)
{
inputs[d] = -1;
}
}
if ((data.command == 48 || data.command == 24 || data.command == 122 || data.command == 16 || data.command == 56 || data.command == 90 || data.command == 82 || data.command == 74 || data.command == 66 || data.command == 12 || data.command == 24 || data.command == 94 || data.command == 8 || data.command == 28 || data.command == 90 || data.command == 66 || data.command == 82 || data.command == 74) && data.command != 2 && data.command != 152)
{
if (inputCursor > 10 && inputCursor != 255 && data.command == 24)
{
mode = 1;
} else if (inputCursor > 10 && inputCursor != 255 && (data.command == 48 || data.command == 12))
{
mode = 0;
}
if (inputCursor > 10 && inputCursor != 255 && (data.command == 122 || data.command == 94) && menuScroll >= 0)
{
dim = !dim;
if (menuScroll == 1 || menuScroll == 0)
{
lcd.setCursor(0, 1);
} else if (menuScroll == 2)
{
lcd.setCursor(0, 0);
}
lcd.printByte(2);
if (dim == true)
{
lcd.print("3 INVINC OFF");
} else if (dim == false)
{
lcd.print("3 INVINC ON");
}
if (menuScroll == 1 || menuScroll == 0)
{
lcd.setCursor(15, 1);
} else if (menuScroll == 2)
{
lcd.setCursor(15, 0);
}
lcd.printByte(2);
} else if (inputCursor > 10 && inputCursor != 255 && (data.command == 16 || data.command == 8) && menuScroll >= 0)
{
skipDeath = !skipDeath;
lcd.setCursor(0, 1);
lcd.printByte(2);
if (skipDeath == true)
{
lcd.print("4 SKIP ON");
} else if (skipDeath == false)
{
lcd.print("4 SKIP OFF");
}
lcd.setCursor(15, 1);
lcd.printByte(2);
} else
{
lcd.clear();
Serial.println("BUTTON!!!");
die = false;
i = 0;
}
}
if (inputCursor == 255)
{
inputCursor = 0;
}
}
if (die == true) {
//delay(1000);
//delay(1000);
//lcd.setCursor(1,0);
//lcd.print(" ");
}
//lcd.clear();
// speed = 6;
}
}
i=0;
normalSpeed = 6;
speedWhenJumping = 3;
speedf = 16;
cactusPos[0] = 16;
cactusPos[1] = 23;
cactusPos[2] = 31;
cactusPos[3] = 40;
cactusPos[4] = 50;
//fix problem with the predetermined cactus positions
cactusPos[0] = cactusPos[0] * speed;
cactusPos[1] = cactusPos[1] * speed;
cactusPos[2] = cactusPos[2] * speed;
cactusPos[3] = cactusPos[3] * speed;
cactusPos[4] = cactusPos[4] * speed;
f = 0;
isJumping == false;
//create dino characters at start
animateDino1[0] = dino[0];
animateDino1[1] = dino[1];
animateDino1[2] = dino[2];
animateDino1[3] = dino[3];
animateDino1[4] = dino[4];
animateDino1[5] = dino[5];
animateDino1[6] = dino[6];
animateDino1[7] = dino[7];
lcd.createChar(2, animateDino1);
animateDino2[0] = dino[8];
animateDino2[1] = dino[9];
animateDino2[2] = dino[10];
animateDino2[3] = dino[11];
animateDino2[4] = dino[12];
animateDino2[5] = dino[13];
animateDino2[6] = dino[14];
animateDino2[7] = dino[15];
lcd.createChar(3, animateDino2);
delay(1000);
}
void loop()
{
i++;//i is the internal timer for EVERYTING it is time
//speed of the game{
//Serial.println(speed);
//Serial.println(speed);
//Serial.println(masterSpeed);
//Serial.println(floor(cactusPos[0]/round(speed)));
if (mode == false)
{
masterSpeed = ((0.00041379310344) * (i)) + 1;
} else
{
masterSpeed = 4;
}
//speed = 6;//masterSpeed; //cactus & bird
normalSpeed = 6 / (masterSpeed); //cactus & bird when player isn't jumping
speedWhenJumping = 3 / (masterSpeed); //cactus & bird when player is jumping
speedf = 16 / (masterSpeed); //jump speed
if (i > 3000)
{
lcd.setCursor(0, 0); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5);
lcd.setCursor(0, 1); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5); lcd.printByte(5);
}
if (isJumping == false)
{
//Serial.println("0");
speed = normalSpeed;
} else
{
//Serial.println("1");
speed = speedWhenJumping;
}
//Serial.println(16/speed);
//}
//detect player input via remote
if (IRLremote.available()) //if it receive a code
{
auto data = IRLremote.read(); //this gets the code that was sent
//Serial.println(data.command); //prints the code of the button that was pressed (data.command is the code received)
if ((data.command == 104 || data.command == 176 || data.command == 48 || data.command == 24 || data.command == 122 || data.command == 16 || data.command == 56 || data.command == 90 || data.command == 82 || data.command == 74 || data.command == 66) && i >= 2) // the code 25 is for the key EQ
{
//Serial.println("JUMP");
if (isJumping == false)
{
jumpstart = i;
isJumping = true;
jumpSFX = millis();
//Serial.println(millis());
}
}
if (data.command == 162)
{
die = true;
}
}
//Music
if(music == true)
{
if(musicCursor >= 48)
{
musicStartPoint = millis();
}
int totalNotes = sizeof(melody) / sizeof(melody[0]);
//Serial.print("Playing melody with ");
//Serial.print(totalNotes);
//Serial.println(" notes...");
//Serial.println(floor((millis() - musicStartPoint)/50));//Should be the state of the music (note timing) 1 2 3 should be note and 4 the time in between notes
musicCursor = floor((millis() - musicStartPoint)/200);
//Serial.println(floor((millis() - musicStartPoint)/200));
//for (int d = 0; d < 48; d++) {
//if(musicCursor == d)
//{
// Play the note
//if()
//{
// Serial.println();
tone(buzzerPin, melody[musicCursor]);
//}
//}//else if(musicCursor =)
//{
// noTone(buzzerPin);
//}
//}
}
//Jump animation & jump sound
if (isJumping == true)
{
//Serial.println(millis());
//Play jump sound
if(millis() >= jumpSFX + 150) //add the delay from the start
{
noTone(buzzerPin);
}else if(millis() >= jumpSFX + 50) //add the delay from the start
{
tone(buzzerPin, 640); // A3 note
}else if(millis() >= jumpSFX + 40) //add the delay from the start
{
noTone(buzzerPin);
}else if(millis() >= jumpSFX + 0 ) //add the delay from the start
{
tone(buzzerPin, 440); // D4 note
}
f = round((-8 / pow(speedf / 2, 2)) * (pow(((i - jumpstart + 1) - (speedf / 2)), 2)) + 8);
//Serial.println((-8/pow(speedf/2,2)) * (pow(((i-jumpstart+1) - (speedf/2)),2))+8);
if (f <= 0)
{
f = 0;
//Serial.println(i-jumpstart);
//Serial.println(f);
isJumping = false;
}
//if(!((2*floor((i-jumpstart)/2))-(i-jumpstart)))
{
animateDino1[0] = dino[0 + f];
animateDino1[1] = dino[1 + f];
animateDino1[2] = dino[2 + f];
animateDino1[3] = dino[3 + f];
animateDino1[4] = dino[4 + f];
animateDino1[5] = dino[5 + f];
animateDino1[6] = dino[6 + f];
animateDino1[7] = dino[7 + f];
lcd.createChar(2, animateDino1);
animateDino2[0] = dino[8 + f];
animateDino2[1] = dino[9 + f];
animateDino2[2] = dino[10 + f];
animateDino2[3] = dino[11 + f];
animateDino2[4] = dino[12 + f];
animateDino2[5] = dino[13 + f];
animateDino2[6] = dino[14 + f];
animateDino2[7] = dino[15 + f];
lcd.createChar(3, animateDino2);
}
}
// - Deal with moving cactus positions:
// - Update pos (move them) and aply the speed logic
// - Randomly generate cactus (random length from one an other (between [insert number here] and [insert number here] ))
//Update cactus and bird
{
cactusPos[0] = cactusPos[0] - 1;
if (cactusPos[0] < 0) {
cactusPos[0] = -100;
cactusPos[0] = cactusPos[4] + random(7, 14) * speed;
cactusOrBird[0] = random(0, 2);
}
cactusPos[1] = cactusPos[1] - 1;
if (cactusPos[1] < 0) {
cactusPos[1] = -100;
cactusPos[1] = cactusPos[0] + random(7, 14) * speed;
cactusOrBird[1] = random(0, 2);
}
cactusPos[2] = cactusPos[2] - 1;
if (cactusPos[2] < 0) {
cactusPos[2] = -100;
cactusPos[2] = cactusPos[1] + random(7, 14) * speed;
cactusOrBird[2] = random(0, 2);
}
cactusPos[3] = cactusPos[3] - 1;
if (cactusPos[3] < 0) {
cactusPos[3] = -100;
cactusPos[3] = cactusPos[2] + random(7, 14) * speed;
cactusOrBird[3] = random(0, 2);
}
cactusPos[4] = cactusPos[4] - 1;
if (cactusPos[4] < 0) {
cactusPos[4] = -100;
cactusPos[4] = cactusPos[3] + random(7, 14) * speed;
cactusOrBird[4] = random(0, 2);
}
//Serial.println(random(0,2));
//Serial.println();
//Serial.print(" Cactus Position:");
//Serial.println(floor(cactusPos[0]/6));
//Serial.print(" i:");
//Serial.println(i);
}
if (isJumping == true)
{
if (speed != speedWhenJumping)
{
cactusPos[0] = cactusPos[0] / normalSpeed * speedWhenJumping;
cactusPos[1] = cactusPos[1] / normalSpeed * speedWhenJumping;
cactusPos[2] = cactusPos[2] / normalSpeed * speedWhenJumping;
cactusPos[3] = cactusPos[3] / normalSpeed * speedWhenJumping;
cactusPos[4] = cactusPos[4] / normalSpeed * speedWhenJumping;
}
speed = speedWhenJumping;
} else if (isJumping == false)
{
//Serial.println(speed != normalSpeed);
if (speed != normalSpeed)
{
cactusPos[0] = cactusPos[0] / speedWhenJumping * normalSpeed;
cactusPos[1] = cactusPos[1] / speedWhenJumping * normalSpeed;
cactusPos[2] = cactusPos[2] / speedWhenJumping * normalSpeed;
cactusPos[3] = cactusPos[3] / speedWhenJumping * normalSpeed;
cactusPos[4] = cactusPos[4] / speedWhenJumping * normalSpeed;
}
speed = normalSpeed;
}
//display cactus
for (int c = 0; c < 5; c++)
{
if (cactusOrBird[c] == 0)
{
if ((0 <= floor(cactusPos[c] / speed)) &&
(floor(cactusPos[c] / speed) <= 16))
{
lcd.setCursor(floor(cactusPos[c] / speed), 1);
lcd.printByte(1);
lcd.printByte(0);
lcd.printByte(0);
}
} else
{
if ((0 <= floor(cactusPos[c] / speed)) &&
(floor(cactusPos[c] / speed) <= 16))
{
lcd.setCursor(floor(cactusPos[c] / speed), 0);
//Serial.println((floor(i/(speed*3)) - floor(floor(i/(speed*3))/2)*2));
if ((floor(i / (normalSpeed * 5)) - floor(floor(i / (normalSpeed * 5)) / 2) * 2))
{
lcd.printByte(6);
} else
{
lcd.printByte(4);
}
lcd.printByte(0);
lcd.printByte(0);
}
}
}
//if((0 <= floor(cactusPos[1]/speed))&&(floor(cactusPos[1]/speed) <= 16)) {lcd.setCursor(floor(cactusPos[1]/speed), 1); lcd.printByte(1);lcd.printByte(0);}
//if((0 <= floor(cactusPos[2]/speed))&&(floor(cactusPos[2]/speed) <= 16)) {lcd.setCursor(floor(cactusPos[2]/speed), 1); lcd.printByte(1);lcd.printByte(0);}
//if((0 <= floor(cactusPos[3]/speed))&&(floor(cactusPos[3]/speed) <= 16)) {lcd.setCursor(floor(cactusPos[3]/speed), 1); lcd.printByte(1);lcd.printByte(0);}
//if((0 <= floor(cactusPos[4]/speed))&&(floor(cactusPos[4]/speed) <= 16)) {lcd.setCursor(floor(cactusPos[4]/speed), 1); lcd.printByte(1);lcd.printByte(0);}
//Display player
for (int i2 = 1; i2 <= 16; i2++)
{
if (i2 == 2)
{
if ((floor(cactusPos[0] / speed) != 0 || cactusOrBird[0] != 1) &&
(floor(cactusPos[1] / speed) != 0 || cactusOrBird[1] != 1) &&
(floor(cactusPos[2] / speed) != 0 || cactusOrBird[2] != 1) &&
(floor(cactusPos[3] / speed) != 0 || cactusOrBird[3] != 1) &&
(floor(cactusPos[4] / speed) != 0 || cactusOrBird[4] != 1))
{
lcd.setCursor(0, 0);
lcd.printByte(2);
}
if ((floor(cactusPos[0] / speed) != 0 || cactusOrBird[0] != 0) &&
(floor(cactusPos[1] / speed) != 0 || cactusOrBird[1] != 0) &&
(floor(cactusPos[2] / speed) != 0 || cactusOrBird[2] != 0) &&
(floor(cactusPos[3] / speed) != 0 || cactusOrBird[3] != 0) &&
(floor(cactusPos[4] / speed) != 0 || cactusOrBird[4] != 0))
{
lcd.setCursor(0, 1);
lcd.printByte(3);
}
}//else
//{
//lcd.setCursor(0, 1);
//lcd.printByte(0);
//}
}
for (int a = 0; a <= 4; a++)
{
//Serial.print("Pos #1:"); Serial.println(floor(cactusPos[0]/speed));
//Serial.print("Pos #2:"); Serial.println(floor(cactusPos[1]/speed));
//Serial.print("Pos #3:"); Serial.println(floor(cactusPos[2]/speed));
//Serial.print("Pos #4:"); Serial.println(floor(cactusPos[3]/speed));
//Serial.print("Pos #5:"); Serial.println(floor(cactusPos[4]/speed));
}
//Check for death
for (int a = 0; a <= 4; a++)
{
if (((floor(cactusPos[a] / speed) == 0 && f <= 4 && cactusOrBird[a] == 0 || floor(cactusPos[a] / speed) == 0 && f >= 5 && cactusOrBird[a] == 1) && dim == true)||die == true)
{
if (mode == 0 && die == false)
{
EEPROM.get(1, eepromtest);
if (eepromtest > highScore)
{
highScore = eepromtest;
}
if (i > highScore)
{
highScore = i;
}
if (eepromtest != highScore)
{
Serial.println("EEPROM - 2");
EEPROM.put(1, highScore);
}
} else if (mode == 1 && die == false)
{
EEPROM.get(16, eepromtest);
if (eepromtest > highScore2)
{
highScore2 = eepromtest;
}
if (i > highScore2)
{
highScore2 = i;
}
if (eepromtest != highScore2)
{
Serial.println("EEPROM - 2");
EEPROM.put(16, highScore2);
}
}
Serial.println("DEATH!!!");
die = true;
lcd.clear();
menu();
// //detect player input via remote
//
// /*
// if (IRLremote.available()) //if it receive a code
// {
// auto data = IRLremote.read(); //this gets the code that was sent
// //Serial.println(data.command); //prints the code of the button that was pressed (data.command is the code received)
// if(data.command == 104 || data.command == 176 || data.command == 48 || data.command == 24 || data.command == 122 || data.command == 16 || data.command == 56 || data.command == 90 || data.command == 82 || data.command == 74 || data.command == 66) // the code 25 is for the key EQ
// {
// die == false;
// }
// }
//
// lcd.setCursor(4,0);
// delay(500);
// lcd.print("Y"); delay(100); lcd.print("O"); delay(100); lcd.print("U"); delay(100); lcd.print(" "); delay(100); lcd.print("D"); delay(100); lcd.print("I"); delay(100); lcd.print("E"); delay(100); lcd.print("D");
// delay(500);
// lcd.clear();
// delay(500);
// lcd.setCursor(0,0);lcd.print("SCORE ");lcd.print(int(i));
// lcd.setCursor(0,1);lcd.print("HIGH ");lcd.print(int(highScore));
//
///*
// if (IRLremote.available()) //if it receive a code
// {
// auto data = IRLremote.read(); //this gets the code that was sent
// //Serial.println(data.command); //prints the code of the button that was pressed (data.command is the code received)
// if(data.command == 104 || data.command == 176 || data.command == 48 || data.command == 24 || data.command == 122 || data.command == 16 || data.command == 56 || data.command == 90 || data.command == 82 || data.command == 74 || data.command == 66) // the code 25 is for the key EQ
// {
// Serial.println("BUTTON!!!");
// die = false;
// i = 0;
// }
// }
//
// if(die == true)
// {
// delay(1000);
// lcd.clear();
// delay(1000);
// lcd.setCursor(1,0);
// lcd.print("P");
// delay(100);
// lcd.print("R");
// delay(100);
// lcd.print("E");
// delay(100);
// lcd.print("S");
// delay(100);
// lcd.print("S");
// delay(100);
//
// if (IRLremote.available()) //if it receive a code
// {
// auto data = IRLremote.read(); //this gets the code that was sent
// //Serial.println(data.command); //prints the code of the button that was pressed (data.command is the code received)
// if(data.command == 104 || data.command == 176 || data.command == 48 || data.command == 24 || data.command == 122 || data.command == 16 || data.command == 56 || data.command == 90 || data.command == 82 || data.command == 74 || data.command == 66) // the code 25 is for the key EQ
// {
// Serial.println("BUTTON!!!");
// die = false;
// i = 0;
// }
// }
// if(die == true)
// {
// lcd.print(" ");
// delay(100);
// lcd.print("A");
// delay(100);
// lcd.print("N");
// delay(100);
// lcd.print("Y");
//
// if (IRLremote.available()) //if it receive a code
// {
// auto data = IRLremote.read(); //this gets the code that was sent
// //Serial.println(data.command); //prints the code of the button that was pressed (data.command is the code received)
// if(data.command == 104 || data.command == 176 || data.command == 48 || data.command == 24 || data.command == 122 || data.command == 16 || data.command == 56 || data.command == 90 || data.command == 82 || data.command == 74 || data.command == 66) // the code 25 is for the key EQ
// {
// Serial.println("BUTTON!!!");
// die = false;
// i = 0;
// }
// }
//
// if(die == true)
// {
// delay(100);
// lcd.print(" ");
// delay(100);
// lcd.print("K");
// delay(100);
// lcd.print("E");
// delay(100);
// lcd.print("Y");
// delay(100);
// if (IRLremote.available()) //if it receive a code
// {
// auto data = IRLremote.read(); //this gets the code that was sent
// //Serial.println(data.command); //prints the code of the button that was pressed (data.command is the code received)
// if(data.command == 104 || data.command == 176 || data.command == 48 || data.command == 24 || data.command == 122 || data.command == 16 || data.command == 56 || data.command == 90 || data.command == 82 || data.command == 74 || data.command == 66) // the code 25 is for the key EQ
// {
// Serial.println("BUTTON!!!");
// die = false;
// i = 0;
// }
// }
// if(die == true)
// {
// lcd.setCursor(3,1);
// lcd.print("T");
// delay(100);
// lcd.print("O");
// delay(100);
// lcd.print(" ");
// delay(100);
// lcd.print("R");
// delay(100);
// lcd.print("E");
// delay(100);
// lcd.print("S");
// delay(100);
// lcd.print("T");
// delay(100);
// lcd.print("A");
// delay(100);
// lcd.print("R");
// delay(100);
// lcd.print("T");
// Serial.println(die);*/
// while(die == true)
// {
// if (IRLremote.available()) //if it receive a code
// {
// auto data = IRLremote.read(); //this gets the code that was sent
// //Serial.println(data.command); //prints the code of the button that was pressed (data.command is the code received)
// if(data.command == 104 || data.command == 176 || data.command == 48 || data.command == 24 || data.command == 122 || data.command == 16 || data.command == 56 || data.command == 90 || data.command == 82 || data.command == 74 || data.command == 66) // the code 25 is for the key EQ
// {
// Serial.println("BUTTON!!!");
// die = false;
// i = 0;
// }
// }
// }
// //}
// //}
// //}
// //}
// Serial.println("RESTART");
//
// speed = 6;
// normalSpeed = 6;
// speedWhenJumping = 3;
// speedf = 16;
//
// cactusPos[0] = 16;
// cactusPos[1] = 23;
// cactusPos[2] = 31;
// cactusPos[3] = 40;
// cactusPos[4] = 50;
//
// lcd.clear();
// //create dino characters at start
// animateDino1[0] = dino[0];
// animateDino1[1] = dino[1];
// animateDino1[2] = dino[2];
// animateDino1[3] = dino[3];
// animateDino1[4] = dino[4];
// animateDino1[5] = dino[5];
// animateDino1[6] = dino[6];
// animateDino1[7] = dino[7];
// lcd.createChar(2,animateDino1);
// animateDino2[0] = dino[8];
// animateDino2[1] = dino[9];
// animateDino2[2] = dino[10];
// animateDino2[3] = dino[11];
// animateDino2[4] = dino[12];
// animateDino2[5] = dino[13];
// animateDino2[6] = dino[14];
// animateDino2[7] = dino[15];
// lcd.createChar(3,animateDino2);
// //display dino characters at start
// lcd.setCursor(0, 0);
// lcd.printByte(2);
// lcd.setCursor(0, 1);
// lcd.printByte(3);
//
// //fix problem with the predetermined cactus positions
// cactusPos[0] = cactusPos[0]*speed;
// cactusPos[1] = cactusPos[1]*speed;
// cactusPos[2] = cactusPos[2]*speed;
// cactusPos[3] = cactusPos[3]*speed;
// cactusPos[4] = cactusPos[4]*speed;
//
// f = 0;
// isJumping == false;
// delay(1000);
}
}
delay(5);
}
// - Deal with moving cactus positions:
// - Update pos (move them) and aply the speed logic
// - Randomly generate cactus (random length from one an other (between [insert number here] and [insert number here] ))
//
// - Deal with printing of cactus:
// - Check if pos is out of screen if it is then ignore it (dont print)
// - If the pos is good then display it
// - Repeat process with all of the cactus pos