Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int ledH[] = {2,3,4,5,6,7,8,9};
- const int ledV[] = {10,11,12,13,A0,A1,A2,A3};
- const int button[] = {A4,A5};
- int dataVar[] = {0,0,0,0,0,0,0,0};
- int counter = 0;
- int buttonVar[] = {0,0};
- int buttonLock[] = {0,0};
- int game = -1;
- int score = 0;
- int storageVar = 0;
- int death = 0;
- int sped = 500;
- int pipes[] = {9,13};
- int pipeSpace[] = {0,0};
- int playerY = -1;
- int paddle = 0;
- int ballX = 0;
- int ballY = 0;
- int ballDir = 0;
- int headX = 0;
- int headY = 0;
- int headDir = 0;
- int tailX = 0;
- int tailY = 0;
- int tailDir = 0;
- int eat = 0;
- int snakeMap0[] = {0,0,0,0,0,0,0,0};
- int snakeMap1[] = {0,0,0,0,0,0,0,0};
- int snakeMap2[] = {0,0,0,0,0,0,0,0};
- int snakeMap3[] = {0,0,0,0,0,0,0,0};
- int snakeMap4[] = {0,0,0,0,0,0,0,0};
- int snakeMap5[] = {0,0,0,0,0,0,0,0};
- int snakeMap6[] = {0,0,0,0,0,0,0,0};
- int snakeMap7[] = {0,0,0,0,0,0,0,0};
- int snakeMap = 0;
- int foodPos[] = {0,0};
- int foodBlink = 0;
- int test = 0;
- void setup() {
- for(int i = 0; i < 8; i++) {
- pinMode(ledV[i], OUTPUT);
- pinMode(ledH[i], OUTPUT);
- }
- pinMode(button[0], INPUT);
- pinMode(button[1], INPUT);
- digitalWrite(button[0], HIGH);
- digitalWrite(button[1], HIGH);
- randomSeed(1);
- }
- void loop() {
- playerY = -1;
- if(game == 0) {
- dataVar[0] = 24;
- dataVar[1] = 36;
- dataVar[2] = 66;
- dataVar[3] = 255;
- dataVar[4] = 66;
- dataVar[5] = 66;
- dataVar[6] = 66;
- dataVar[7] = 126;
- }
- if(game == 1) {
- dataVar[0] = 96;
- dataVar[1] = 0;
- dataVar[2] = 0;
- dataVar[3] = 6;
- dataVar[4] = 102;
- dataVar[5] = 96;
- dataVar[6] = 96;
- dataVar[7] = 96;
- }
- if(game == 2) {
- dataVar[0] = 0;
- dataVar[1] = 96;
- dataVar[2] = 96;
- dataVar[3] = 0;
- dataVar[4] = 0;
- dataVar[5] = 62;
- dataVar[6] = 62;
- dataVar[7] = 0;
- }
- if(game == 3) {
- dataVar[0] = 0;
- dataVar[1] = 126;
- dataVar[2] = 66;
- dataVar[3] = 66;
- dataVar[4] = 18;
- dataVar[5] = 2;
- dataVar[6] = 2;
- dataVar[7] = 2;
- }
- buttonVar[0] = digitalRead(button[0]);
- if(buttonVar[0] == HIGH) {
- if(buttonLock[0] == 0) {
- if(game == 3) {
- game = 0;
- } else {
- game = game + 1;
- }
- buttonLock[0] = 1;
- }
- } else {
- buttonLock[0] = 0;
- }
- buttonVar[1] = digitalRead(button[1]);
- if(buttonVar[1] == HIGH) {
- if(buttonLock[1] == 0) {
- for(int a = 0; a < 8; a++) {
- dataVar[a] = 0;
- }
- Game();
- buttonLock[1] = 1;
- }
- } else {
- buttonLock[1] = 0;
- }
- counter = 0;
- for(int a = 0; a < 8; a++) {
- display();
- }
- }
- void display() {
- for(int i = 0; i < 8; i++) {
- if(counter == foodPos[1] && i == foodPos[0] && test == 1) {
- if(foodBlink == 1) {
- digitalWrite(ledV[i], LOW);
- } else {
- digitalWrite(ledV[i], HIGH);
- }
- } else {
- if(bitRead(dataVar[counter], i) == 0) {
- digitalWrite(ledV[i], HIGH);
- } else {
- digitalWrite(ledV[i], LOW);
- }
- }
- }
- if(counter == playerY) {
- if(bitRead(dataVar[counter], 1) == 1) {
- death = 1;
- } else {
- digitalWrite(ledV[1], LOW);
- }
- }
- digitalWrite(ledH[counter], HIGH);
- digitalWrite(ledH[counter], LOW);
- counter = counter + 1;
- }
- void Death() {
- dataVar[0] = 165;
- dataVar[1] = 66;
- dataVar[2] = 165;
- dataVar[3] = 0;
- dataVar[4] = 60;
- dataVar[5] = 66;
- dataVar[6] = 0;
- playerY = -1;
- for(int l = 0; l < 1700; l++) {
- counter = 0;
- for(int a = 0; a < 8; a++) {
- display();
- }
- }
- for(int l = 0; l < 6; l++) {
- dataVar[l] = 0;
- }
- storageVar = floor((score - 1) / 10);
- testA();
- storageVar = (score - 1) % 10;
- testB();
- for(int l = 0; l < 1; l+= 0) {
- counter = 0;
- for(int a = 0; a < 8; a++) {
- display();
- }
- buttonVar[0] = digitalRead(button[0]);
- if(buttonVar[0] == HIGH) {
- if(buttonLock[0] == 0) {
- Game();
- buttonLock[0] = 1;
- }
- } else {
- buttonLock[0] = 0;
- }
- buttonVar[1] = digitalRead(button[1]);
- if(buttonVar[1] == HIGH) {
- if(buttonLock[1] == 0) {
- game = 0;
- l = 1;
- buttonLock[1] = 1;
- }
- } else {
- buttonLock[1] = 0;
- }
- }
- }
- void Game() {
- if(game == 1) {
- Pipes();
- }
- if(game == 2) {
- Pong();
- }
- if(game == 3) {
- Snake();
- }
- }
- void testA() {
- if(storageVar == 0) {
- for(int a = 1; a < 6; a++) {
- dataVar[a] = dataVar[a] + 5;
- }
- dataVar[1] = dataVar[1] + 2;
- dataVar[5] = dataVar[5] + 2;
- }
- if(storageVar == 1) {
- for(int a = 1; a < 6; a++) {
- dataVar[a] = dataVar[a] + 4;
- }
- }
- if(storageVar == 2) {
- barsA();
- dataVar[2] = dataVar[2] + 4;
- dataVar[4] = dataVar[4] + 1;
- }
- if(storageVar == 3) {
- barsA();
- dataVar[2] = dataVar[2] + 4;
- dataVar[4] = dataVar[4] + 4;
- }
- if(storageVar == 4) {
- dataVar[1] = dataVar[1] + 5;
- dataVar[2] = dataVar[2] + 5;
- dataVar[3] = dataVar[3] + 7;
- dataVar[4] = dataVar[4] + 4;
- dataVar[5] = dataVar[5] + 4;
- }
- if(storageVar == 5) {
- barsA();
- dataVar[2] = dataVar[2] + 1;
- dataVar[4] = dataVar[4] + 4;
- }
- if(storageVar == 6) {
- barsA();
- dataVar[2] = dataVar[2] + 1;
- dataVar[4] = dataVar[4] + 5;
- }
- if(storageVar == 7) {
- dataVar[1] = dataVar[1] + 7;
- for(int a = 2; a < 6; a++) {
- dataVar[a] = dataVar[a] + 4;
- }
- }
- if(storageVar == 8) {
- barsA();
- dataVar[2] = dataVar[2] + 5;
- dataVar[4] = dataVar[4] + 5;
- }
- if(storageVar == 9) {
- dataVar[1] = dataVar[1] + 7;
- dataVar[2] = dataVar[2] + 5;
- dataVar[3] = dataVar[3] + 7;
- dataVar[4] = dataVar[4] + 4;
- dataVar[5] = dataVar[5] + 4;
- }
- }
- void barsA() {
- for(int a = 1; a < 6; a+= 2) {
- dataVar[a] = dataVar[a] + 7;
- }
- }
- void testB() {
- if(storageVar == 0) {
- for(int a = 1; a < 6; a++) {
- dataVar[a] = dataVar[a] + 80;
- }
- dataVar[1] = dataVar[1] + 32;
- dataVar[5] = dataVar[5] + 32;
- }
- if(storageVar == 1) {
- for(int a = 1; a < 6; a++) {
- dataVar[a] = dataVar[a] + 64;
- }
- }
- if(storageVar == 2) {
- barsB();
- dataVar[2] = dataVar[2] + 64;
- dataVar[4] = dataVar[4] + 16;
- }
- if(storageVar == 3) {
- barsB();
- dataVar[2] = dataVar[2] + 64;
- dataVar[4] = dataVar[4] + 64;
- }
- if(storageVar == 4) {
- dataVar[1] = dataVar[1] + 80;
- dataVar[2] = dataVar[2] + 80;
- dataVar[3] = dataVar[3] + 112;
- dataVar[4] = dataVar[4] + 64;
- dataVar[5] = dataVar[5] + 64;
- }
- if(storageVar == 5) {
- barsB();
- dataVar[2] = dataVar[2] + 16;
- dataVar[4] = dataVar[4] + 64;
- }
- if(storageVar == 6) {
- barsB();
- dataVar[2] = dataVar[2] + 16;
- dataVar[4] = dataVar[4] + 80;
- }
- if(storageVar == 7) {
- dataVar[1] = dataVar[1] + 112;
- for(int a = 2; a < 6; a++) {
- dataVar[a] = dataVar[a] + 64;
- }
- }
- if(storageVar == 8) {
- barsB();
- dataVar[2] = dataVar[2] + 80;
- dataVar[4] = dataVar[4] + 80;
- }
- if(storageVar == 9) {
- dataVar[1] = dataVar[1] + 112;
- dataVar[2] = dataVar[2] + 80;
- dataVar[3] = dataVar[3] + 112;
- dataVar[4] = dataVar[4] + 64;
- dataVar[5] = dataVar[5] + 64;
- }
- }
- void barsB() {
- for(int a = 1; a < 6; a+= 2) {
- dataVar[a] = dataVar[a] + 112;
- }
- }
- void Pipes() {
- sped = 500;
- playerY = 0;
- score = 0;
- pipes[0] = 9;
- pipes[1] = 13;
- for(death = 0; death == 0;) {
- for(int a = 0; a < 4; a++) {
- if(pipes[0] == 0) {
- pipes[0] = 7;
- pipeSpace[0] = random(0,3);
- } else {
- pipes[0] = pipes[0] - 1;
- }
- if(pipes[1] == 0) {
- pipes[1] = 7;
- pipeSpace[1] = random(1,4);
- } else {
- pipes[1] = pipes[1] - 1;
- }
- for(int l = 0; l < 6; l++) {
- dataVar[l] = pow(2,pipes[0]) + pow(2,pipes[1]) + 1;
- }
- dataVar[pipeSpace[0]] = dataVar[pipeSpace[0]] - pow(2,pipes[0]);
- dataVar[pipeSpace[0] + 1] = dataVar[pipeSpace[0] + 1] - pow(2,pipes[0]);
- dataVar[pipeSpace[1]] = dataVar[pipeSpace[1]] - pow(2,pipes[1]);
- dataVar[pipeSpace[1] + 1] = dataVar[pipeSpace[1] + 1] - pow(2,pipes[1]);
- dataVar[7] = score;
- for(int j = 0; j < sped; j++) {
- buttonVar[0] = digitalRead(button[0]);
- if(buttonVar[0] == HIGH) {
- if(buttonLock[0] == 0) {
- if(playerY < 5) {
- playerY = playerY + 1;
- buttonLock[0] = 1;
- }
- }
- } else {
- buttonLock[0] = 0;
- }
- buttonVar[1] = digitalRead(button[1]);
- if(buttonVar[1] == HIGH) {
- if(buttonLock[1] == 0) {
- if(playerY > 0) {
- playerY = playerY - 1;
- buttonLock[1] = 1;
- }
- }
- } else {
- buttonLock[1] = 0;
- }
- counter = 0;
- for(int a = 0; a < 8; a++) {
- display();
- }
- }
- }
- score = score + 1;
- sped = sped - 5;
- }
- Death();
- }
- void Pong() {
- sped = 400;
- score = 0;
- ballX = 8;
- ballY = 3;
- ballDir = 2;
- paddle = 8;
- for(death = 0; death == 0;) {
- for(int a = 0; a < 8; a++) {
- if(ballX == 128) {
- ballDir = ballDir + 2;
- }
- if(ballY == 0) {
- ballDir = ballDir + 1;
- }
- if(ballX == 1) {
- ballDir = ballDir - 2;
- }
- if(ballY == 5) {
- if(ballX == paddle || ballX == paddle / 2 || ballX == paddle * 2) {
- ballDir = ballDir - 1;
- }
- if(ballDir == 1 && ballX * 2 == paddle / 2) {
- ballDir = 2;
- }
- if(ballDir == 3 && ballX / 2 == paddle * 2) {
- ballDir = 0;
- }
- }
- if(ballY == 7) {
- death = 1;
- a = 8;
- }
- if(ballDir == 0) {
- ballX = ballX * 2;
- ballY = ballY - 1;
- }
- if(ballDir == 1) {
- ballX = ballX * 2;
- ballY = ballY + 1;
- }
- if(ballDir == 2) {
- ballX = ballX / 2;
- ballY = ballY - 1;
- }
- if(ballDir == 3) {
- ballX = ballX / 2;
- ballY = ballY + 1;
- }
- for(int l = 0; l < 6; l++) {
- dataVar[l] = 0;
- }
- dataVar[ballY] = ballX;
- dataVar[7] = score;
- for(int j = 0; j < sped; j++) {
- buttonVar[0] = digitalRead(button[0]);
- if(buttonVar[0] == HIGH) {
- if(buttonLock[0] == 0) {
- if(paddle < 64) {
- paddle = paddle * 2;
- buttonLock[0] = 1;
- }
- }
- } else {
- buttonLock[0] = 0;
- }
- buttonVar[1] = digitalRead(button[1]);
- if(buttonVar[1] == HIGH) {
- if(buttonLock[1] == 0) {
- if(paddle > 2) {
- paddle = paddle / 2;
- buttonLock[1] = 1;
- }
- }
- } else {
- buttonLock[1] = 0;
- }
- dataVar[6] = paddle + paddle / 2 + paddle * 2;
- if(ballY == 6) {
- if(ballX == paddle || ballX == paddle / 2 || ballX == paddle * 2) {
- } else {
- dataVar[6] = dataVar[6] + ballX;
- }
- }
- counter = 0;
- for(int a = 0; a < 8; a++) {
- display();
- }
- }
- }
- score = score + 1;
- sped = sped - 10;
- }
- Death();
- }
- void Snake() {
- score = 1;
- eat = 1;
- test = 1;
- headX = 4;
- headY = 1;
- headDir = 2;
- tailX = 2;
- tailY = 1;
- tailDir = 0;
- FoodPos();
- for(int j = 0; j < 8; j++) {
- dataVar[j] = 0;
- snakeMap0[j] = 0;
- snakeMap1[j] = 0;
- snakeMap2[j] = 0;
- snakeMap3[j] = 0;
- snakeMap4[j] = 0;
- snakeMap5[j] = 0;
- snakeMap6[j] = 0;
- snakeMap7[j] = 0;
- }
- for(death = 0; death == 0;) {
- storageVar = log(headX) / log(2);
- if(storageVar == foodPos[0] && headY == foodPos[1]) {
- FoodPos();
- eat = 1;
- score = score + 1;
- }
- storageVar = log(tailX) / log(2);
- if(eat < 1) {
- if(tailDir == 1) {
- tailY = tailY - 1;
- }
- if(tailDir == 2) {
- tailX = tailX / 2;
- }
- if(tailDir == 3) {
- tailY = tailY + 1;
- }
- if(tailDir == 4) {
- tailX = tailX * 2;
- }
- dataVar[tailY] = dataVar[tailY] - tailX;
- }
- eat = eat - 1;
- SnakeMap(headX, headY, headDir);
- SnakeMap(tailX, tailY, 5);
- if(!snakeMap == 0) {
- tailDir = snakeMap;
- }
- SnakeMap(tailX, tailY, 0);
- if(headDir == 1) {
- headY = headY - 1;
- }
- if(headDir == 2) {
- headX = headX / 2;
- }
- if(headDir == 3) {
- headY = headY + 1;
- }
- if(headDir == 4) {
- headX = headX * 2;
- }
- storageVar = log(headX) / log(2);
- if(bitRead(dataVar[headY], storageVar) == 1 || headX == 256 || headY == -1 || headX == 256 || headY == 8) {
- death = 1;
- } else {
- dataVar[headY] = dataVar[headY] + headX;
- }
- for(int j = 0; j < 5; j++) {
- for(int k = 0; k < 75; k++) {
- buttonVar[0] = digitalRead(button[0]);
- if(buttonVar[0] == HIGH) {
- if(buttonLock[0] == 0) {
- if(headDir == 1) {
- headDir = 4;
- } else {
- headDir = headDir - 1;
- }
- buttonLock[0] = 1;
- }
- } else {
- buttonLock[0] = 0;
- }
- buttonVar[1] = digitalRead(button[1]);
- if(buttonVar[1] == HIGH) {
- if(buttonLock[1] == 0) {
- if(headDir == 4) {
- headDir = 1;
- } else {
- headDir = headDir + 1;
- }
- buttonLock[1] = 1;
- }
- } else {
- buttonLock[1] = 0;
- }
- counter = 0;
- for(int a = 0; a < 8; a++) {
- display();
- }
- }
- if(foodBlink == 1){
- foodBlink = 0;
- } else {
- foodBlink = 1;
- }
- }
- }
- test = 0;
- dataVar[7] = 0;
- Death();
- }
- void SnakeMap(int x, int y, int m) {
- storageVar = log(x) / log(2);
- if(m == 5) {
- if(y == 0) {
- snakeMap = snakeMap0[storageVar];
- }
- if(y == 1) {
- snakeMap = snakeMap1[storageVar];
- }
- if(y == 2) {
- snakeMap = snakeMap2[storageVar];
- }
- if(y == 3) {
- snakeMap = snakeMap3[storageVar];
- }
- if(y == 4) {
- snakeMap = snakeMap4[storageVar];
- }
- if(y == 5) {
- snakeMap = snakeMap5[storageVar];
- }
- if(y == 6) {
- snakeMap = snakeMap6[storageVar];
- }
- if(y == 7) {
- snakeMap = snakeMap7[storageVar];
- }
- } else {
- if(y == 0) {
- snakeMap0[storageVar] = m;
- }
- if(y == 1) {
- snakeMap1[storageVar] = m;
- }
- if(y == 2) {
- snakeMap2[storageVar] = m;
- }
- if(y == 3) {
- snakeMap3[storageVar] = m;
- }
- if(y == 4) {
- snakeMap4[storageVar] = m;
- }
- if(y == 5) {
- snakeMap5[storageVar] = m;
- }
- if(y == 6) {
- snakeMap6[storageVar] = m;
- }
- if(y == 7) {
- snakeMap7[storageVar] = m;
- }
- }
- }
- void FoodPos() {
- for(int b = 0; b == 0; b+= 0) {
- foodPos[0] = random(0,7);
- foodPos[1] = random(0,7);
- if(!bitRead(dataVar[foodPos[1]], foodPos[0]) == 1) {
- b = 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement