
Game doesn't work properly, but it's a 'form' of Tetris.
Main.cpp
- Committer:
- el14kb
- Date:
- 2016-04-28
- Revision:
- 1:7da5b36d5f50
- Child:
- 2:dc75e15229ee
File content as of revision 1:7da5b36d5f50:
#include "mbed.h" #include "N5110.h" //Tetris by Kristian Bridges // VCC, SCE, RST, D/C, MOSI, SCLK, LED N5110 lcd (PTE26 , PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3); AnalogIn potX(PTB2); AnalogIn potY(PTB3); DigitalIn joyButton(PTB11); #define tolerance 0.05f #define down_tolerance -0.05f Ticker checkJoy; enum direction_t { UP, //0 DOWN, //1 LEFT, //2 RIGHT, //3 CENTRE, //4 UNKNOWN //5 }; typedef struct { float initial_x,initial_y; float current_x,current_y; int button; direction_t direction; } joystick; joystick joy; volatile int g_bank_index = 0; volatile int index1 = g_bank_index; volatile int g_joyFlag = 0; char buffer[14]; char buffer2[14]; int xlcd; int ylcd; void menu(); void joyCal(); void joyUpdate(); void selection(); void game(); void achievements(); void options(); int main() { lcd.init(); lcd.clear(); lcd.printString("Tetris",24,1); lcd.printString("by",36,2); lcd.printString("K.Bridges",15,3); lcd.printString("SID: 200859491",0,5); wait(2); lcd.clear(); joyCal(); checkJoy.attach(&joyUpdate,0.01); menu(); } 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; switch(joy.direction) { case UP: if(g_bank_index == 0) { g_bank_index = 2; break; } else g_bank_index--; break; case DOWN: if(g_bank_index == 2) { g_bank_index = 0; } 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 == 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 == 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); } } } } lcd.refresh(); } sleep(); }//end of while loop }//end of function void joyCal() { joy.initial_x = potX; joy.initial_y = potY; joyButton.mode(PullDown); } void joyUpdate() { 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 if((joy.current_y) > tolerance && fabs(joy.current_x) < tolerance) { //fabs returns an absolute value joy.direction = UP; } else if((joy.current_y) < down_tolerance && fabs(joy.current_x) < tolerance) { 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) { joy.direction = RIGHT; } else if(fabs(joy.current_x) < tolerance && fabs(joy.current_y) < tolerance) { joy.direction = CENTRE; } else joy.direction = UNKNOWN; g_joyFlag = 1; } void selection() { if(g_bank_index == 0) { game(); } else if(g_bank_index == 1) { achievements(); } else if(g_bank_index == 2) { options(); } } void game() { } void achievements() { } void options() { }