Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 2:dc75e15229ee, committed 2016-05-07
- Comitter:
- el14kb
- Date:
- Sat May 07 14:36:03 2016 +0000
- Parent:
- 1:7da5b36d5f50
- Commit message:
- Game doesn't work entirely, but it's a 'form' of Tetris.
Changed in this revision
diff -r 7da5b36d5f50 -r dc75e15229ee Main.cpp --- a/Main.cpp Thu Apr 28 14:33:28 2016 +0000 +++ b/Main.cpp Sat May 07 14:36:03 2016 +0000 @@ -1,5 +1,8 @@ #include "mbed.h" #include "N5110.h" +#include "Pieces.h" +#include <vector> + //Tetris by Kristian Bridges @@ -9,11 +12,17 @@ AnalogIn potX(PTB2); AnalogIn potY(PTB3); DigitalIn joyButton(PTB11); +DigitalIn buttonA(PTB18); +DigitalIn buttonB(PTB19); +InterruptIn A(PTB18); +InterruptIn B(PTB19); -#define tolerance 0.05f -#define down_tolerance -0.05f +#define tolerance 0.1f +#define down_tolerance -0.1f +#define right_tolerance -0.1f Ticker checkJoy; +Ticker gameCheck; enum direction_t { UP, //0 @@ -29,25 +38,51 @@ float current_x,current_y; int button; direction_t direction; + int buttonA; + int buttonB; } joystick; joystick joy; +joystick rotate_buttons; -volatile int g_bank_index = 0; -volatile int index1 = g_bank_index; +struct Tetris { + int xP; //current x position + int yP; //current y position + int next_xP; //next potential x position + int next_yP; //next potential y position + int level; + int line_check; + int total_lines; + int current_shape; + int piece_in_play; + int orientation; + int score; + int game_over; + int orientation_copy; + int currentPiece[10][10]; +} tetris; + +int g_bank_index = 0; +int g_bank_index_copy = 4; volatile int g_joyFlag = 0; -char buffer[14]; -char buffer2[14]; -int xlcd; -int ylcd; +volatile int g_rotate_clock_flag = 0; +volatile int g_rotate_anticlock_flag = 0; +int currentState[45][40]; +volatile int g_call_game_Flag = 0; +float timer = 1.0; void menu(); -void joyCal(); +void cal(); void joyUpdate(); -void selection(); void game(); -void achievements(); void options(); +void orientation(); +void draw_piece(); +void array_checker(); +void piece_generator(); +void anticlockwise(); +void clockwise(); +void gameCheck_isr(); int main() { @@ -59,21 +94,19 @@ lcd.printString("SID: 200859491",0,5); wait(2); lcd.clear(); - joyCal(); + cal(); checkJoy.attach(&joyUpdate,0.01); menu(); - } -void menu() +void drawPiece() { +} +void menu() +{ int x,y; - lcd.printString("New Game",18,1); - lcd.printString("Achievements",6,2); - lcd.printString("Options",21,3); - while(joy.button == 0) { if(g_joyFlag) { g_joyFlag = 0; @@ -92,69 +125,88 @@ } else g_bank_index++; } - if(g_bank_index == 0) { - - lcd.clear(); - lcd.printString("New Game",18,1); - lcd.printString("Achievements",6,2); - lcd.printString("Options",21,3); - - for(x=0; x<WIDTH; x++) { - for(y=7; y<15; y++) { - if(lcd.getPixel(x,y)) { - lcd.clearPixel(x,y); - } else { - lcd.setPixel(x,y); + + if(g_bank_index_copy != g_bank_index) { + g_bank_index_copy = g_bank_index; + + if(g_bank_index == 0) { + + lcd.clear(); + lcd.printString("New Game",18,1); + lcd.printString("Achievements",6,2); + lcd.printString("Options",21,3); + + for(x=0; x<WIDTH; x++) { + for(y=7; y<16; y++) { + if(lcd.getPixel(x,y)) { + lcd.clearPixel(x,y); + } else { + lcd.setPixel(x,y); + } } } } - } - if(g_bank_index == 1) { - - lcd.clear(); - lcd.printString("New Game",18,1); - lcd.printString("Achievements",6,2); - lcd.printString("Options",21,3); - - for(x=0; x<WIDTH; x++) { - for(y=14; y<22; y++) { - if(lcd.getPixel(x,y)) { - lcd.clearPixel(x,y); - } else { - lcd.setPixel(x,y); + if(g_bank_index == 1) { + + lcd.clear(); + lcd.printString("New Game",18,1); + lcd.printString("Achievements",6,2); + lcd.printString("Options",21,3); + + for(x=0; x<WIDTH; x++) { + for(y=15; y<24; y++) { + if(lcd.getPixel(x,y)) { + lcd.clearPixel(x,y); + } else { + lcd.setPixel(x,y); + } } } } - } - if(g_bank_index == 2) { - - lcd.clear(); - lcd.printString("New Game",18,1); - lcd.printString("Achievements",6,2); - lcd.printString("Options",21,3); - - for(x=0; x<WIDTH; x++) { - for(y=21; y<29; y++) { - if(lcd.getPixel(x,y)) { - lcd.clearPixel(x,y); - } else { - lcd.setPixel(x,y); + if(g_bank_index == 2) { + + lcd.clear(); + lcd.printString("New Game",18,1); + lcd.printString("Achievements",6,2); + lcd.printString("Options",21,3); + + for(x=0; x<WIDTH; x++) { + for(y=23; y<32; y++) { + if(lcd.getPixel(x,y)) { + lcd.clearPixel(x,y); + } else { + lcd.setPixel(x,y); + } } } } + lcd.refresh(); + } else if(g_bank_index_copy == g_bank_index) { + sleep(); } - lcd.refresh(); } - sleep(); }//end of while loop + if(g_bank_index == 0) { + lcd.clear(); + game(); + } else if(g_bank_index == 1) { + lcd.clear(); + } else if(g_bank_index == 2) { + lcd.clear(); + options(); + } }//end of function -void joyCal() +void cal() { joy.initial_x = potX; joy.initial_y = potY; joyButton.mode(PullDown); + buttonA.mode(PullDown); //1 if pressed + buttonB.mode(PullDown); //1 if pressed + A.fall(&anticlockwise); + B.fall(&clockwise); } void joyUpdate() @@ -162,6 +214,8 @@ joy.current_x = potX - joy.initial_x; //current x-position joy.current_y = potY - joy.initial_y; //current y-position joy.button = joyButton; //current button state + rotate_buttons.buttonA = buttonA; //current anti-clockwise state + rotate_buttons.buttonB = buttonB; //current clockwise state if((joy.current_y) > tolerance && fabs(joy.current_x) < tolerance) { //fabs returns an absolute value joy.direction = UP; @@ -169,7 +223,7 @@ joy.direction = DOWN; } else if((joy.current_x) > tolerance && fabs(joy.current_y) < tolerance) { joy.direction = LEFT; - } else if((joy.current_x) < tolerance && fabs(joy.current_y) < tolerance) { + } else if((joy.current_x) < right_tolerance && fabs(joy.current_y) < tolerance) { joy.direction = RIGHT; } else if(fabs(joy.current_x) < tolerance && fabs(joy.current_y) < tolerance) { joy.direction = CENTRE; @@ -177,26 +231,410 @@ joy.direction = UNKNOWN; g_joyFlag = 1; } - -void selection() +void piece_generator() { - if(g_bank_index == 0) { - game(); - } else if(g_bank_index == 1) { - achievements(); - } else if(g_bank_index == 2) { - options(); + + if(tetris.piece_in_play == 0) { //initialisation of a piece in play + tetris.current_shape = rand() %7; + tetris.xP = rand() % 39 + 0; //39 is the least significant x position (xP is the current position of the piece) + tetris.yP = -5; //change if collision rules check out (yP is the current position of the piece) + tetris.orientation = 0; + tetris.piece_in_play = 1; //defines whether a piece is in play } } void game() { -} + tetris.orientation_copy = 5; + tetris.game_over = 0; + lcd.printString("Score:",0,1); + lcd.printString("Lines:",0,4); + lcd.drawRect(38,0,42,47,0); + srand(time(NULL)); + for(int y = 0; y<45; y++) { + for(int x = 0; x<40; x++) { + if(y == 44) { + currentState[y][x] = 1; + } else + currentState[y][x] = 0; + } + } + + gameCheck.attach(&gameCheck_isr,timer); + while(tetris.game_over == 0) { + if(joy.direction == UP) { + timer = 0.01; + } else timer = 0.1; -void achievements() -{ + if(g_call_game_Flag == 1) { + piece_generator(); + orientation(); + draw_piece(); + for(int y=0; y<45; y++) { + for(int x=0; x<40; x++) { + if(currentState[y][x] == 1) { + lcd.setPixel(x+39,y+1); + } else + lcd.clearPixel(x+39,y+1); + } + } + + for(int m = 0; m<10; m++) { + for(int n = 0; n<10; n++) { + if(tetris.currentPiece[m][n] == 1) { + lcd.setPixel(tetris.xP+n+39,tetris.yP+m+1); + } + } + } + + lcd.refresh(); + array_checker(); + } + sleep(); + } + gameCheck.detach(); + lcd.clear(); + lcd.printString("Game Over",15,2); + wait(1); + lcd.clear(); + menu(); } void options() { + float brightness = 0.5; + + lcd.printString("UP = +",24,0); + lcd.printString("DOWN = -",18,1); + lcd.printString("Press B",24,2); + lcd.printString("to exit",21,3); + + while(joy.button == 0) { + if(joy.direction == UP) { + brightness += 0.1f; + lcd.setBrightness(brightness); + } else if(joy.direction == DOWN) { + brightness -= 0.1f; + lcd.setBrightness(brightness); + } + } + lcd.clear(); + menu(); } + + +void orientation() +{ + + + if(g_rotate_clock_flag == 1) { + g_rotate_clock_flag = 0; + if(tetris.orientation == 3) { + tetris.orientation = 0; + } else if(tetris.orientation == 0) { + tetris.orientation++; + } + } + + if(g_rotate_anticlock_flag == 1) { + g_rotate_anticlock_flag = 0; + if(tetris.orientation == 0) { + tetris.orientation = 3; + } else if(tetris.orientation == 3) { + tetris.orientation--; + } + } + if(tetris.orientation_copy != tetris.orientation) { + tetris.orientation_copy = tetris.orientation; + + if(tetris.current_shape == 0) { //Square + if(tetris.orientation == 0 || 1 || 2 || 3) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = O[m][n]; + } + } + } + } + + if(tetris.current_shape == 1) { //I + if(tetris.orientation == 0) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = I0[m][n]; + } + } + } + if(tetris.orientation == 1) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = I90[m][n]; + } + } + } + if(tetris.orientation == 2) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = I180[m][n]; + } + } + } + if(tetris.orientation == 3) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = I270[m][n]; + } + } + } + } + + if(tetris.current_shape == 2) { //L + if(tetris.orientation == 0) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = L0[m][n]; + } + } + } + if(tetris.orientation == 1) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = L90[m][n]; + } + } + } + if(tetris.orientation == 2) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = L180[m][n]; + } + } + } + if(tetris.orientation == 3) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = L270[m][n]; + } + } + } + } + + if(tetris.current_shape == 3) { //J + if(tetris.orientation == 0) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = J0[m][n]; + } + } + } + if(tetris.orientation == 1) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = J90[m][n]; + } + } + } + if(tetris.orientation == 2) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = J180[m][n]; + } + } + } + if(tetris.orientation == 3) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = J270[m][n]; + } + } + } + } + + if(tetris.current_shape == 4) { //Z + if(tetris.orientation == 0) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = Z0[m][n]; + } + } + } + if(tetris.orientation == 1) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = Z90[m][n]; + } + } + } + if(tetris.orientation == 2) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = Z180[m][n]; + } + } + } + if(tetris.orientation == 3) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = Z270[m][n]; + } + } + } + } + + if(tetris.current_shape == 5) { //S + if(tetris.orientation == 0) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = S0[m][n]; + } + } + } + if(tetris.orientation == 1) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = S90[m][n]; + } + } + } + if(tetris.orientation == 2) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = S180[m][n]; + } + } + } + if(tetris.orientation == 3) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = S270[m][n]; + } + } + } + } + + if(tetris.current_shape == 6) { //T + if(tetris.orientation == 0) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = T0[m][n]; + } + } + } + if(tetris.orientation == 1) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = T90[m][n]; + } + } + } + if(tetris.orientation == 2) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = T180[m][n]; + } + } + } + if(tetris.orientation == 3) { + for(int m = 0; m < 10; m++) { + for(int n = 0; n < 10; n++) { + tetris.currentPiece[m][n] = T270[m][n]; + } + } + } + } + } +} +bool GetcurrentState(int y,int x){ + +if (y<0||y>45||x<0||x>40) return false; + +return currentState[y][x]; +} + +void SetcurrentState(int y,int x,bool state){ + +if (y<0||y>45||x<0||x>40) return; + +currentState[y][x] = state; +} +void draw_piece() +{ + + if(joy.direction == LEFT) { + tetris.next_xP = tetris.xP-1; + } else if(joy.direction == RIGHT) { + tetris.next_xP = tetris.xP+1; + } else { + + tetris.next_xP = tetris.xP; + + } + + if (tetris.next_xP+10>42) { + tetris.next_xP = 42-10; + } + if (tetris.next_xP<0) { + tetris.next_xP = 0; + } + bool piece_collided_x = false; + for(int y = 0; y < 10; y++) { + for(int x = 0; x < 10; x++) { + if((tetris.currentPiece[y][x] == 1) && (GetcurrentState(tetris.yP + y,tetris.next_xP + x) == 1)) { + piece_collided_x = true; + } + } + } + if(piece_collided_x == false) { + tetris.xP = tetris.next_xP; + } + tetris.next_yP = tetris.yP+1; + + bool piece_collided_y = false; + for(int y = 0; y < 10; y++) { + for(int x = 0; x < 10; x++) { + if((tetris.currentPiece[y][x] == 1) && (GetcurrentState(tetris.next_yP + y,tetris.xP + x) == 1)) { + piece_collided_y = true; + } + } + } + + if(piece_collided_y == false) { + tetris.yP = tetris.next_yP; + } else { + for(int y = 0; y < 10; y++) { + for(int x = 0; x < 10; x++) { + if((tetris.currentPiece[y][x] == 1)) { + SetcurrentState(tetris.yP + y,tetris.xP + x,1); + } + } + tetris.piece_in_play = 0; + } + } + + +} + +void array_checker() +{ + for(int x = 0; x<40; x++) { + + if(currentState[0][x] == 1) { + printf("boop: %d",x); + tetris.game_over = 1; + } + } +} + + +void clockwise() +{ + g_rotate_clock_flag = 1; +} +void anticlockwise() +{ + g_rotate_anticlock_flag = 1; +} +void gameCheck_isr() +{ + g_call_game_Flag = 1; +}
diff -r 7da5b36d5f50 -r dc75e15229ee N5110.lib --- a/N5110.lib Thu Apr 28 14:33:28 2016 +0000 +++ b/N5110.lib Sat May 07 14:36:03 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/eencae/code/N5110/#c1400fcb2f61 +https://developer.mbed.org/users/el14kb/code/N5110/#accb0cd314d2
diff -r 7da5b36d5f50 -r dc75e15229ee Pieces.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Pieces.cpp Sat May 07 14:36:03 2016 +0000 @@ -0,0 +1,302 @@ +#include "Pieces.h" +int O[10][10] = { + {0,0,0,1,1,1,1,0,0,0}, + {0,0,0,1,1,1,1,0,0,0}, + {0,0,0,1,1,1,1,0,0,0}, + {0,0,0,1,1,1,1,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int I0[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,1,1,1,1,1,1,1,1}, + {0,0,1,1,1,1,1,1,1,1}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; + +int I90[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0} + }; +int I180[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {1,1,1,1,1,1,1,1,0,0}, + {1,1,1,1,1,1,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int I270[10][10] = { + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int L0[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int L90[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,1,1,1,1,1,1,0,0}, + {0,0,1,1,1,1,1,1,0,0}, + {0,0,1,1,0,0,0,0,0,0}, + {0,0,1,1,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int L180[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int L270[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,1,1,0,0}, + {0,0,0,0,0,0,1,1,0,0}, + {0,0,1,1,1,1,1,1,0,0}, + {0,0,1,1,1,1,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int J0[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int J90[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,1,1,0,0,0,0,0,0}, + {0,0,1,1,0,0,0,0,0,0}, + {0,0,1,1,1,1,1,1,0,0}, + {0,0,1,1,1,1,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int J180[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int J270[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,1,1,1,1,1,1,0,0}, + {0,0,1,1,1,1,1,1,0,0}, + {0,0,0,0,0,0,1,1,0,0}, + {0,0,0,0,0,0,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int Z0[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,1,1,0,0}, + {0,0,0,0,0,0,1,1,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int Z90[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int Z180[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,1,1,0,0,0,0,0,0}, + {0,0,1,1,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int Z270[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int S0[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,0,0,1,1,0,0}, + {0,0,0,0,0,0,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int S90[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int S180[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,1,1,0,0,0,0,0,0}, + {0,0,1,1,0,0,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int S270[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int T0[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,1,1,1,1,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int T90[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,1,1,1,1,1,1,0,0}, + {0,0,1,1,1,1,1,1,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int T180[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,1,1,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; +int T270[10][10] = { + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,1,1,0,0,0,0}, + {0,0,1,1,1,1,1,1,0,0}, + {0,0,1,1,1,1,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0} + }; \ No newline at end of file
diff -r 7da5b36d5f50 -r dc75e15229ee Pieces.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Pieces.h Sat May 07 14:36:03 2016 +0000 @@ -0,0 +1,25 @@ +extern int O[10][10]; +extern int I0[10][10]; +extern int I90[10][10]; +extern int I180[10][10]; +extern int I270[10][10]; +extern int L0[10][10]; +extern int L90[10][10]; +extern int L180[10][10]; +extern int L270[10][10]; +extern int J0[10][10]; +extern int J90[10][10]; +extern int J180[10][10]; +extern int J270[10][10]; +extern int Z0[10][10]; +extern int Z90[10][10]; +extern int Z180[10][10]; +extern int Z270[10][10]; +extern int S0[10][10]; +extern int S90[10][10]; +extern int S180[10][10]; +extern int S270[10][10]; +extern int T0[10][10]; +extern int T90[10][10]; +extern int T180[10][10]; +extern int T270[10][10]; \ No newline at end of file
diff -r 7da5b36d5f50 -r dc75e15229ee main.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Sat May 07 14:36:03 2016 +0000 @@ -0,0 +1,227 @@ +/** + +@file main.h + +@Header file to denote the various functions, global variables, and definitions. + + +@Author: Kristian Bridges +@SID:200859491 + +@brief: University of Leeds Elec2645 (Embedded systems project) + +@Date: May 2016 + +*/ + +#ifndef MAIN_H + +#define MAIN_H + +#include "mbed.h" + +#include "Pieces.h" + +#include "N5110.h" + +// --------------- Peripherals - Input -------------- + +/** + +@namespace joystick + +@brief joystick that allows me to move in the x and y direction. Two potentiometers allow this functionality, as well as a button, which allows additional +functionality. + +*/ + +AnalogIn potX(PTB2); +AnalogIn potY(PTB3); +DigitalIn joyButton(PTB11); + +/** + +@namespace Button A + +@brief DigitalIn button that calls an interrupt to rotate the tetris piece anticlockwise. + +*/ + +DigitalIn buttonA(PTB18); + +/** + +@namespace Button B + +@brief DigitalIn button that calls an interrupt to rotate the tetris piece clockwise. + +*/ + +DigitalIn buttonB(PTB19); + +// -------------- Peripherals - Output -------------- + +/** + +@namespace Nokia 5110 LCD + +@brief 84*48 black and white pixel display. +@brief VCC, GND, SCE, RST, D/C, MOSI, SCLK, LED + +*/ + +N5110 lcd (PTE26 , PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3); + +// -------------- Variables -------------- + +int g_bank_index = 0; /*!<Index for the menu */ +int g_bank_index_copy = 4; /*!<Backup index to ensure the menu doesn't continuously refresh the pixels on the screen */ +volatile int g_joyFlag = 0; /*!<Interrupt for the joystick */ +volatile int g_rotate_clock_flag = 0; /*!<Interrupt for the B button */ +volatile int g_rotate_anticlock_flag = 0; /*!<Interrupt for the A button */ +int currentState[45][40]; /*!<Array to store the current playfield state */ +volatile int g_call_game_Flag = 0; /*!<Interrupt to call the game functions */ +float timer = 1.0; /*!<Value for the game ticker */ +int xP; /*!<Current x position */ +int yP; /*!<Current y position */ +int next_xP; /*!<Next x position */ +int next_yP; /*!<Next y position */ +int level; /*!<Stores the level */ +int line_check; /*!<Checks whether 10 lines have been cleared */ +int total_lines; /*!<Total lines cleared */ +int current_shape; /*!<Current shape in play */ +int piece_in_play; /*!<States whether there's a piece in play */ +int orientation; /*!<Stores the orientation of the piece */ +int score; /*!<Stores the score */ +int game_over; /*!<States whether the game is over */ +int orientation_copy; /*!<Keeps track of whether a rotation has occured */ +int currentPiece[10][10]; /*!<Current piece in play */ +float initial_x,initial_y; /*!<Initial x and y position of the joystick */ +float current_x,current_y; /*!<Current x and y position of the joystick */ +int button; /*!<State of the joystick button */ +int buttonA; /*!<State of the anticlockwise button */ +int buttonB; /*!<State of the clockwise button */ + +// -------------- Functions -------------- + +/** + +@namespace Menu + +@brief Renders the menu based on the direction of the joystick. +@brief An index keeps track of which menu item is currently selected. +@brief Index also allows the appropriate function to be called. + +*/ +void menu(); + +/** + +@namespace cal + +@brief Calibrates the joystick, as well as the other input peripherals. + +*/ +void cal(); + +/** + +@namespace joyUpdate + +@brief Updates the direction of the joystick based on tolerances. + +*/ +void joyUpdate(); + +/** + +@namespace game + +@brief Carries out the necessary functions to render and update the game of tetris, although, the actual game doesn't work correctly. + +*/ +void game(); + +/** + +@namespace options + +@brief Allows the user to change the led brightness. More functions can be implemented if needed, such as options to change the parameter +@brief of the game.e + +*/ +void options(); + +/** + +@namespace orientation + +@brief Changes the orientation of the piece in play if either of the rotation interrupts are called. + +*/ +void orientation(); + +/** + +@namspace draw_piece + +@brief Checks the current piece array with the currentState array for any collisions at the next x,y-position. If a collision has been detected, +@brief the piece will be saved to the currentState array, and the next piece will be spawned. + +@brief If a collision hasn't been detected, then the piece will be rendered onto the playfield. + +*/ +void draw_piece(); + +/** + +@namespace array_checker + +@brief Checks the currentState array for any elements that are 'on' throughout the top row. +@brief If there are any elements 'on', then the game finishes and returns back to the main menu. +@brief Some features are missing, such as the complete line checker, but the overall feature didn't work; this can be improved upon for a fully working +@brief game of tetris. + +*/ +void array_checker(); + +/** + +@namespace piece_generator + +@brief Generates the next tetris piece, as well as the initial piece orientation, and the initial x and y coordinates. +@brief Spawning of random shapes doesn't entirely work. Not sure whether it is the location of the seed, but further investigation into the issue is needed. + +*/ +void piece_generator(); + +/** + +@namespace anticlockwise + +@brief An ISR that sets a global variable to 1, and calls the piece to be rotated anticlockwise. + +*/ +void anticlockwise(); + +/** + +@namespace clockwise + +@brief An ISR that sets a global variable to 1, and calls the piece to be rotated clockwise. + +*/ +void clockwise(); + +/** + +@namespace gameCheck_isr + +@brief An ISR that sets a global variable to 1, and calls several functions from within the game function. + +*/ +void gameCheck_isr(); + + + +#endif \ No newline at end of file