A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.
Dependencies: ConfigFile N5110 PowerControl beep mbed
Revision 52:bb2acf0e248a, committed 2015-04-30
- Comitter:
- el13drt
- Date:
- Thu Apr 30 19:57:59 2015 +0000
- Parent:
- 51:df3bab1d6926
- Child:
- 53:a3077af736bb
- Commit message:
- this works 20:57 30/4/15
Changed in this revision
--- a/N5110.lib Thu Apr 30 15:55:43 2015 +0000 +++ b/N5110.lib Thu Apr 30 19:57:59 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/eencae/code/N5110/#c587a6eb16fc +http://mbed.org/users/eencae/code/N5110/#ba8addc061ea
--- a/main.cpp Thu Apr 30 15:55:43 2015 +0000 +++ b/main.cpp Thu Apr 30 19:57:59 2015 +0000 @@ -12,6 +12,7 @@ #include <ctime> #include <cstdlib> + int main() { ledP = 1;//power LED on @@ -20,8 +21,11 @@ pollJoystick.attach(&updateJoystick,1.0/10.0);//read joystick 10 times per second lcd.init();//initialise screen + drawWelcome();//welcome screen + lcd.clear();//clear pixels + buttonA.mode(PullDown);//pull down buttonA buttonB.mode(PullDown);//pull down buttonB @@ -35,7 +39,7 @@ while(1) { drawMainMenu();//draws main menu mainMenu(mainOption);//presents main menu options - actionButtons(); + actionButtons();//sound light when buttons pressed // if 'Play Game' selected if ((mainOption == 0)&&(buttonFlagA)) {
--- a/tower.h Thu Apr 30 15:55:43 2015 +0000 +++ b/tower.h Thu Apr 30 19:57:59 2015 +0000 @@ -82,12 +82,12 @@ int randX6; //global variable for hazard Y co-ordinates -int randY1 = 0; -int randY2 = 0; -int randY3 = 0; -int randY4 = 0; -int randY5 = 0; -int randY6 = 0; +int randY1 = 1; +int randY2 = 1; +int randY3 = 1; +int randY4 = 1; +int randY5 = 1; +int randY6 = 1; //integers for changing struct ouput states int state1 = 0; @@ -186,7 +186,7 @@ RIGHT, CENTRE, UNKNOWN - + }; //struct for Joystick @@ -242,26 +242,21 @@ { //x, y, w, h, fill - draw ground lcd.drawRect(0,47,84,0,1); - //x, y, w, h, fill - draw left wall lcd.drawRect(2,0,0,47,1); //left wall - brick line 1 - for(int x=0; x<47; x+=4) - lcd.drawLine(1,1,1,48,2); + lcd.drawLine(1,1,1,48,2); //left wall - brick line 2 - for(int x=0; x<47; x+=4) - lcd.drawLine(0,0,0,48,2); + lcd.drawLine(0,0,0,48,2); //x, y, w, h, fill - draw right wall lcd.drawRect(81,0,0,47,1); //right wall - brick line 1 - for(int x=0; x<WIDTH; x+=4) - lcd.drawLine(82,0,82,48,2); + lcd.drawLine(82,0,82,48,2); //right wall - brick line 2 - for(int x=0; x<WIDTH; x+=4) - lcd.drawLine(83,1,83,48,2); + lcd.drawLine(83,1,83,48,2); - //lcd.refresh(); + lcd.refresh(); } //intro screen @@ -269,20 +264,20 @@ { //bottom border lcd.drawRect(0,44,84,2,1); - //top border lcd.drawRect(0,1,84,2,1); + lcd.refresh(); //print initials 'DRT' - lcd.printChar('D',30,14); + lcd.printChar('D',30,2); wait(0.6); - lcd.printChar('R',37,14); + lcd.printChar('R',37,2); wait(0.6); - lcd.printChar('T',44,14); + lcd.printChar('T',44,2); wait(0.6); //print 'presents...' - lcd.printString("presents...",8,21); + lcd.printString("presents...",8,3); wait(1.0); //dramatic flashing @@ -343,6 +338,8 @@ lcd.drawRect(a7,36,0,0,1); lcd.drawRect(a5,37,0,0,1); lcd.drawRect(a8,38,0,0,1); + + lcd.refresh(); } //stops ninja going through walls @@ -427,7 +424,7 @@ lcd.drawCircle(randX5,randY5,2,1); lcd.drawCircle(randX6,randY6,2,1); - //lcd.refresh(); + lcd.refresh(); } //makes hazards fall - randomises X axis co-ordinates @@ -488,7 +485,7 @@ } else { lcd.clearPixel(i,j);//else remove the old ones } - //lcd.refresh(); + lcd.refresh(); } //clears old pixels and keeps set pixels @@ -594,10 +591,6 @@ //top border lcd.drawRect(0,0,84,2,1); - //print 'Xtreme Tower' - lcd.printString("Xtreme",4,25); - lcd.printString("Tower",44,25); - //title outline lcd.drawRect(3,6,77,10,0); @@ -652,6 +645,11 @@ lcd.drawRect(27,29,4,0,1); lcd.drawRect(28,28,2,0,1); lcd.drawRect(29,27,0,0,1); + + //print 'Xtreme Tower' + lcd.printString("Xtreme Tower",7,1); + + lcd.refresh(); } //presents exit menu options @@ -679,10 +677,10 @@ } //draws option cursor if(exitOption == 0) { - lcd.printString("YES",29,27); + lcd.printString("YES",33,3); } - if(exitOption == 1) { - lcd.printString(" NO",29,27); + else if(exitOption == 1) { + lcd.printString(" NO",33,3); } } @@ -691,19 +689,21 @@ { //set exit menu lcd.clear(); - lcd.drawRect(8,6,70,30,0);//title outline - lcd.printString("Exit Game?",10,25); drawBackground(); + lcd.printString("Exit Game?",14,1); + lcd.drawRect(8,3,70,30,0);//title outline //option arrow - right lcd.drawRect(55,25,0,4,1); lcd.drawRect(56,26,0,2,1); lcd.drawRect(57,27,0,0,1); - //option arrow - left + //option arrow - left// lcd.drawRect(27,25,0,4,1); lcd.drawRect(26,26,0,2,1); lcd.drawRect(25,27,0,0,1); + + lcd.refresh(); } //presents the options @@ -742,6 +742,8 @@ refreshCursor2(); } } + + lcd.refresh(); } //draws options menu @@ -752,17 +754,17 @@ lcd.drawRect(3,6,77,10,0);//title outline lcd.drawRect(0,47,84,0,1);//bottom border lcd.drawRect(0,0,84,2,1);//top border - lcd.printString("Options",20,7);//title - lcd.printString("Difficulty",3,9); - lcd.printString("Sound FX",3,10); + lcd.printString("Options",20,1);//title + lcd.printString("Difficulty",3,3); + lcd.printString("Sound FX",3,4); + + lcd.refresh(); } //present difficulty options void difficultyMenu(int& subOption) { actionButtons(); - //subOption = fall;//keeps cursor on selected -// //option even after exiting menu //joystick selection if (printFlag) {//if flag set, clear flag,print joystick values @@ -819,6 +821,8 @@ } } } + + lcd.refresh(); } //draw difficulty settings @@ -828,10 +832,11 @@ drawBackground(); lcd.drawRect(0,47,84,0,1);//bottom border lcd.drawRect(0,0,84,2,1);//top border - lcd.printString("*Difficulty*",5,7);//title - lcd.printString("Easy",5,8);//title - lcd.printString("Normal",5,9);//title - lcd.printString("Forget It",5,10);//title + lcd.refresh(); + lcd.printString("*Difficulty*",5,1);//title + lcd.printString("Easy",5,2);//title + lcd.printString("Normal",5,3);//title + lcd.printString("Forget It",5,4);//title } //present sound FX options @@ -885,6 +890,7 @@ serial.printf("FX = %d\n",FX); } } + lcd.refresh(); } //draw Sound FX settings @@ -894,9 +900,10 @@ drawBackground(); lcd.drawRect(0,47,84,0,1);//bottom border lcd.drawRect(0,0,84,2,1);//top border - lcd.printString("*Sound FX*",10,7);//title - lcd.printString("ON",35,9);//title - lcd.printString("OFF",33,10);//title + lcd.printString("*Sound FX*",10,1);//title + lcd.printString("ON",35,3);//title + lcd.printString("OFF",33,4);//title + lcd.refresh(); } //if any of the high scores are beaten, they are replaced. @@ -914,14 +921,14 @@ int n;//local variable used for storing temporary global variable int initial = 0;//used for isolating which initial is being selected char x,y,z; - + //print initial characters x=fsm[state1].output1; - lcd.printChar(x,25,26); + lcd.printChar(x,28,2); y=fsm[state2].output2; - lcd.printChar(y,37,26); + lcd.printChar(y,40,2); z=fsm[state3].output3; - lcd.printChar(z,49,26); + lcd.printChar(z,52,2); while(1) { @@ -972,17 +979,17 @@ //if initial 3 display selected character if (initial == 0) { x=fsm[state1].output1; - lcd.printChar(x,25,26); + lcd.printChar(x,28,2); } //if initial 1 display selected character if(initial == 1) { y=fsm[state2].output2; - lcd.printChar(y,37,26); + lcd.printChar(y,40,2); } //if initial 2 display selected character if(initial == 2) { z=fsm[state3].output3; - lcd.printChar(z,49,26); + lcd.printChar(z,52,2); } if(buttonFlagA) { actionButtons(); @@ -1038,7 +1045,8 @@ drawNinja();//set character drawHazards();//initiates hazards hazardFall();//increments hazards towards floor - + wait(0.1);//slow down objects + if (printFlag) { //if flag set, clear flag and print joystick values to serial port printFlag = 0; @@ -1104,10 +1112,10 @@ wait(0.5); lcd.normalMode(); newScore();//enter initial screen if previous scores are beaten - resetGame(); + resetGame();//reset values break; } - lcd.refresh(); + lcd.refresh();//refresh screen startrek();//clears unset pixels, keeps set pixels ///Exit Menu (Back button pressed)/// @@ -1119,7 +1127,7 @@ while(1) { exitMenu(exitOption);//presents exit options - + //'exit' option YES if((buttonFlagA)&&(exitOption == 0)) { //returns to menu exitOption = 1;//reset intial option value @@ -1135,7 +1143,6 @@ if((buttonFlagA)&&(exitOption == 1)) { buttonFlagA = 0;//resets flags buttonFlagB = 0; - break; } sleep();//put while to sleep @@ -1147,7 +1154,7 @@ break;//break to main menu } } - serial.printf("Score: %i \n",score); + serial.printf("Score: %i \n",score);//print Score for debug } } }