///Created: Kim Bely
#include <LiquidCrystal.h>
#include "JnRpreset.h"
LiquidCrystal lcd(10, 9, 8, 7, 6, 5);
int Tick = 100;
int sound1 = 1000;
int rarity = 1.5;
void setup() {
pinMode(SoundEnable, INPUT_PULLUP);
pinMode(tast, INPUT_PULLUP);
pinMode(buzz, OUTPUT);
pinMode(life1, OUTPUT);
pinMode(life2, OUTPUT);
pinMode(life3, OUTPUT);
lcd.begin(2, 16);
lcd.createChar(0, clr);
lcd.createChar(1, Man0);
lcd.createChar(2, Man1);
lcd.createChar(3, Man2);
lcd.createChar(4, Man3);
lcd.createChar(5, Heart);
Serial.begin(9600);
randomSeed(analogRead(A0));
lcd.clear();
intro();
}
/////////////////////////////////////////////////////////////////////////////
void loop() {
lcd.setCursor(1, 1);
lcd.write(2);
delay(200);
releaseGATE(tast);
x = 1;
while (x == 1) {
mys = random(1, 3);
AnimationAndJump();
BGBpos();
BGTpos();
BGshift();
death();
BGspawn(1, 5, 1, 3);
sound();
jumpsound();
difficulty();
Boost();
deBoost();
brk();
mystery();
Life();
bonus();
steps++;
}
gameover();
}
/////////////////////////////////////////////////////////////////////////////
void man(int xpos, int ypos, char zeichen) {
lcd.setCursor(xpos, ypos);
lcd.write(byte(zeichen));
}
/////////////////////////////////////////////////////////////////////////////
void frames() {
if (b > 3) {
b = 1;
}
else {
b++;
}
}
/////////////////////////////////////////////////////////////////////////////
void AnimationAndJump() {
if (digitalRead(tast) == LOW) {
a = 0;
}
else {
a = 1;
}
man(1, a, b);
frames();
}
/////////////////////////////////////////////////////////////////////////////
void BGshift() {
for (int i = 0; i < 16; i++) {
BG[1][i] = BG[1][i + 1];
BG[0][i] = BG[0][i + 1];
}
}
/////////////////////////////////////////////////////////////////////////////
void BGBpos() {
for (int i = 0; i < 16; i++) {
if (i == 1 && a == 1 && BG[1][i] == 0) {
}
else {
lcd.setCursor(i, 1);
lcd.write(BG[1][i]);
}
}
}
/////////////////////////////////////////////////////////////////////////////
void BGTpos() {
for (int i = 0; i < 16; i++) {
if (i == 1 && a == 0 && BG[0][i] == 0) {
}
else {
lcd.setCursor(i, 0);
lcd.write(BG[0][i]);
}
}
}
/////////////////////////////////////////////////////////////////////////////
void death() {
if (a == 0 && BG[0][1] == 0xFF) {
if (lifevar < 1) {
x = 0;
}
if (lifevar > 0) {
revive();
lifevar--;
}
}
if (a == 1 && BG[1][1] == 0xFF) {
if (lifevar < 1) {
x = 0;
}
if (lifevar > 0) {
revive();
lifevar--;
}
}
}
void reset() {
for (int i = 0; i < 16; i++) {
BG[0][i] = 0;
BG[1][i] = 0;
}
}
/////////////////////////////////////////////////////////////////////////////
void gameover() {
lcd.clear();
reset();
lcd.setCursor(3, 0);
lcd.print("GAME");
lcd.setCursor(3, 1);
lcd.print("OVER");
lcd.setCursor(9, 0);
lcd.print("SCORE:");
lcd.setCursor(9, 1);
lcd.print(steps);
Serial.print("SCORE:");
Serial.println(steps);
Tick = 100;
steps = 0;
deboostcd = 0;
boostcd = 0;
if (digitalRead(SoundEnable) == HIGH) {
tone(buzz, 523.25);
delay(300);
tone(buzz, 493.88);
delay(300);
tone(buzz, 466.16);
delay(300);
tone(buzz, 440.00);
delay(300 - 5);
noTone(buzz);
}
}
/////////////////////////////////////////////////////////////////////////////
void BGspawn(int BGmin, int BGmax, int Pmin, int Pmax) {
if (P == 0) {
if (BGcnt > BGrand) {
BGrand = random(BGmin, BGmax);
BGcnt = 0;
P = 1;
}
else {
BG[lane][15] = 0xFF;
BGcnt++;
}
}
else {
if (Pcnt >= Prand) {
Prand = random(Pmin, Pmax);
Pcnt = 0;
P = 0;
lane = random(2);
}
else {
Pcnt++;
}
}
}
/////////////////////////////////////////////////////////////////////////////
void sound() {
if (digitalRead(SoundEnable) == HIGH) {
if (Snd == 0) {
beep((sound1) + (steps / 2), 4);
Snd = 1;
}
else {
beep((sound1 / 2) + (steps / 2), 4);
Snd = 0;
}
}
}
/////////////////////////////////////////////////////////////////////////////
void difficulty() {
diffi++;
if (diffi > 14) {
Tick = Tick - 0.05;
diffi = 0;
}
delay(Tick);
}
/////////////////////////////////////////////////////////////////////////////
void beep(int freq, int t) {
if (digitalRead(SoundEnable) == HIGH) {
tone(11, freq);
delay(t);
noTone(11);
}
}
/////////////////////////////////////////////////////////////////////////////
void Boost() {
if (boostcd > (300 / rarity) && P == 1 && Pcnt == 2 && Tick > 50) {
boostcd = 0;
BG[lane][15] = 0x3E;
lane = random(2);
}
if (a == 0 && BG[0][1] == 0x3E) {
Tick = Tick - 23;
beep(1500, 10);
}
if (a == 1 && BG[1][1] == 0x3E) {
Tick = Tick - 23;
beep(1500, 10);
}
boostcd++;
}
/////////////////////////////////////////////////////////////////////////////
void deBoost() {
if (deboostcd > (650 / rarity) && P == 1 && Pcnt == 1) {
deboostcd = 0;
BG[lane][15] = 0x3C;
lane = random(2);
}
if (a == 0 && BG[0][1] == 0x3C) {
Tick = Tick + 15;
beep(1200, 20);
}
if (a == 1 && BG[1][1] == 0x3C) {
Tick = Tick + 15;
beep(1200, 20);
}
deboostcd++;
}
/////////////////////////////////////////////////////////////////////////////
void brk() {
if (a == 0 && BG[0][1] == 0x2A) {
Tick = Tick + 5;
reset();
beep(1500, 10);
beep(1100, 10);
beep(1500, 10);
beep(1100, 10);
}
if (a == 1 && BG[1][1] == 0x2A) {
Tick = Tick + 5;
reset();
beep(1500, 10);
beep(1100, 10);
beep(1500, 10);
beep(1100, 10);
}
if (brkcd > (475 / rarity) && P == 1 && Pcnt == 1) {
brkcd = 0;
BG[lane][15] = 0x2A;
lane = random(2);
}
brkcd++;
}
/////////////////////////////////////////////////////////////////////////////
void mystery() {
if (myscd > (573 / rarity) && P == 1 && Pcnt == 2) {
myscd = 0;
BG[lane][15] = 0x3F;
lane = random(2);
}
if (a == 0 && BG[0][1] == 0x3F) {
Tick = Tick + 1;
randomfunct();
beep(1500, 10);
beep(1700, 10);
beep(2100, 10);
beep(1000, 10);
}
if (a == 1 && BG[1][1] == 0x3F) {
Tick = Tick + 1;
randomfunct();
beep(1500, 10);
beep(1700, 10);
beep(2100, 10);
beep(1000, 10);
}
myscd++;
}
/////////////////////////////////////////////////////////////////////////////
void randomfunct() {
mys = random(1, 4);
if (mys == 1) {
Tick = Tick + 2;
reset();
beep(1500, 10);
beep(1100, 10);
beep(1500, 10);
beep(1100, 10);
}
if (mys == 2) {
Tick = Tick + 15;
beep(1200, 20);
}
if (mys == 3) {
Tick = Tick - 23;
beep(1500, 10);
}
}
/////////////////////////////////////////////////////////////////////////////
void Life() {
if (lifecd > (1056 / rarity) && P == 1 && Pcnt == 2 && lifevar < 3) {
lifecd = 0;
BG[lane][15] = 5;
lane = random(2);
}
if (lifevar == 0) {
digitalWrite(life1, LOW);
digitalWrite(life2, LOW);
digitalWrite(life3, LOW);
}
if (lifevar == 1) {
digitalWrite(life1, HIGH);
digitalWrite(life2, LOW);
digitalWrite(life3, LOW);
}
if (lifevar == 2) {
digitalWrite(life1, HIGH);
digitalWrite(life2, HIGH);
digitalWrite(life3, LOW);
}
if (lifevar == 3) {
digitalWrite(life1, HIGH);
digitalWrite(life2, HIGH);
digitalWrite(life3, HIGH);
}
if (a == 0 && BG[0][1] == 5) {
lifevar++;
beep(500, 20);
beep(500, 20);
beep(500, 20);
beep(2000, 20);
beep(2000, 20);
beep(2000, 20);
}
if (a == 1 && BG[1][1] == 5) {
lifevar++;
beep(500, 20);
beep(500, 20);
beep(500, 20);
beep(2000, 20);
beep(2000, 20);
beep(2000, 20);
}
lifecd++;
}
/////////////////////////////////////////////////////////////////////////////
void revive() {
reset();
beep(500, 20);
beep(300, 20);
beep(100, 20);
beep(2000, 20);
beep(1500, 20);
beep(1000, 20);
Tick = Tick + 8;
}
void bonus() {
if (bonuscd > 500 && P == 1 && Pcnt == 2) {
bonuscd = 0;
BG[lane][15] = 0x24;
lane = random(2);
}
if (a == 0 && BG[0][1] == 0x24) {
steps = steps + 200;
beep(900, 10);
beep(1000, 10);
beep(1200, 10);
beep(2100, 10);
beep(2700, 10);
}
if (a == 1 && BG[1][1] == 0x24) {
steps = steps + 200;
beep(900, 10);
beep(1000, 10);
beep(1200, 10);
beep(2100, 10);
beep(2700, 10);
}
bonuscd++;
}
void intro() {
lcd.clear();
lcd.setCursor(1, 1);
lcd.write(2);
for (int i = 5; i < 15; i++) {
beep(i * 25, 100);
beep(i * 30, 100);
beep(i * 45, 100);
}
lcd.setCursor(3, 0);
lcd.print("JUMP");
beep(523.251, 300);
lcd.setCursor(8, 0);
lcd.print("or");
beep(554.365, 300);
lcd.setCursor(11, 0);
lcd.print("DIE");
beep(587.330, 300);
lcd.setCursor(3, 1);
lcd.print("By.Kim Bely");
beep(622.254, 1200);
}
void releaseGATE(int PIN) {
while (digitalRead(PIN) == HIGH) {
delay(5);
}
while (digitalRead(PIN) == LOW) {
delay(5);
}
}
void HIGHFLANK(int PIN) {
//if (digitalRead(2) == LOW && T1 == 1) { //LOWFLANK
//}
if (digitalRead(PIN) == LOW) {
T1 = 0;
}
if (digitalRead(PIN) == HIGH) {
T1 = 1;
}
}
void LOWFLANK(int PIN) {
//if (digitalRead(2) == HIGH && T1 == 1) { //LOWFLANK
//}
if (digitalRead(PIN) == HIGH) {
T2 = 0;
}
if (digitalRead(PIN) == LOW) {
T2 = 1;
}
}
void jumpsound(){
if (digitalRead(2) == LOW && T1 == 1) { //HIGHFLANK
sign_ana(11, 5, 1000+steps/2, 1500+steps/2, 1750+steps/2, 1820+steps/2);
}
HIGHFLANK(2);
if (digitalRead(2) == HIGH && T2 == 1) { //LOWFLANK
sign_ana(11, 5, 2000+steps/2, 1000+steps/2, 500+steps/2, 250+steps/2);
}
LOWFLANK(2);
}
void sign_ana(int PIN, int t_TEMP, int a_TEMP, int b_TEMP, int c_TEMP, int d_TEMP) {
tone(PIN, a_TEMP);
delay(t_TEMP);
tone(PIN, b_TEMP);
delay(t_TEMP);
tone(PIN, c_TEMP);
delay(t_TEMP);
tone(PIN, d_TEMP);
delay(t_TEMP);
noTone(PIN);
}
//by daniel b