A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.
Dependencies: ConfigFile N5110 PowerControl beep mbed
Diff: main.cpp
- Revision:
- 57:bd8e064020fc
- Parent:
- 56:7c2a4f2a6d70
- Child:
- 58:1111619f7cf3
--- a/main.cpp Sat May 02 01:00:25 2015 +0000 +++ b/main.cpp Sat May 02 02:14:58 2015 +0000 @@ -25,7 +25,8 @@ } //read file -void read(){ +void read() +{ char *key = "Open";//check key matches //check file-if read unsuccessful print error message @@ -212,6 +213,14 @@ wait(0.6); } +//initial head movement values +int h1 = a3-1; +int h2 = a3-3; +int h3 = a3+4; +int h4 = a3+3; +int h5 = a3+2; +int h6 = a3+1; + //pixel ninja character void drawNinja() { @@ -221,12 +230,6 @@ lcd.drawRect(a2,39,0,7,1); //centre stick lcd.drawRect(a3,37,0,7,1); - //back of the head - lcd.drawRect(a1,33,0,4,1); - //top of the head - lcd.drawRect(a1,33,4,0,1); - //jaw - lcd.drawRect(a2,38,2,0,1); //right shoulder lcd.drawRect(a4,40,1,0,1); //left shoulder @@ -235,16 +238,23 @@ lcd.drawRect(a5,41,0,1,1); //right arm lcd.drawRect(a6,41,0,1,1); + //right eye - lcd.drawRect(a6,35,0,0,1); + lcd.drawRect(h1,35,0,0,1); //mouth piece - lcd.drawRect(a6,37,0,0,1); + lcd.drawRect(h2,37,0,0,1); //left eye - lcd.drawRect(a2,35,0,0,1); + lcd.drawRect(h2,35,0,0,1); //sword handle - lcd.drawRect(a7,36,0,0,1); - lcd.drawRect(a5,37,0,0,1); - lcd.drawRect(a8,38,0,0,1); + lcd.drawRect(h3,36,0,0,1); + lcd.drawRect(h4,37,0,0,1); + lcd.drawRect(h5,38,0,0,1); + //back of the head + lcd.drawRect(h6,33,0,4,1); + //top of the head + lcd.drawRect(h2,33,4,0,1); + //jaw + lcd.drawRect(h2,38,2,0,1); lcd.refresh(); } @@ -262,12 +272,12 @@ a3 = 76; if(a1 > 75) a1 = 75; - if(a8 > 74) - a8 = 74; + // if(a8 > 74) +// a8 = 74; if(a5 > 73) a5 = 73; - if(a7 > 72) - a7 = 72; +// if(a7 > 72) +// a7 = 72; if(a6 < 11 ) a6 = 11; @@ -279,12 +289,12 @@ a3 = 8; if(a1 < 7) a1 = 7; - if(a8 < 6) - a8 = 6; + //if(a8 < 6) +// a8 = 6; if(a5 < 5) a5 = 5; - if(a7 < 4) - a7 = 4; + // if(a7 < 4) +// a7 = 4; } //resets variables initial values when game ends or is exited @@ -298,8 +308,8 @@ a4 = 25; a5 = 20; a6 = 26; - a7 = 19; - a8 = 21; +// a7 = 19; +// a8 = 21; //in this case the X values are given a //new random variable each time the player @@ -965,8 +975,34 @@ a4 = a4-=2; a5 = a5-=2; a6 = a6-=2; - a7 = a7-=2; - a8 = a8-=2; + + h1 = a3-1; + h2 = a3-3; + h3 = a3+4; + h4 = a3+3; + h5 = a3+2; + h6 = a3+1; + + // a7 = a7-=2; +// a8 = a8-=2; + +// //right eye +// lcd.drawRect((a3-1),35,0,0,1); +// //mouth piece +// lcd.drawRect((a3-3),37,0,0,1); +// //left eye +// lcd.drawRect((a3-3),35,0,0,1); +// //sword handle +// lcd.drawRect((a3+4),36,0,0,1); +// lcd.drawRect((a3+3),37,0,0,1); +// lcd.drawRect((a3+2),38,0,0,1); +// //back of the head +// lcd.drawRect((a3+1),33,0,4,1); +// //top of the head +// lcd.drawRect((a3-3),33,4,0,1); +// //jaw +// lcd.drawRect((a3-3),38,2,0,1); + ninjaBoundaries(); } if (joystick.direction == RIGHT) { @@ -977,8 +1013,34 @@ a4 = a4+=2; a5 = a5+=2; a6 = a6+=2; - a7 = a7+=2; - a8 = a8+=2; + + h1 = a3-1; + h2 = a3-3; + h3 = a3+4; + h4 = a3+3; + h5 = a3+2; + h6 = a3+1; + + // a7 = a7+=2; +// a8 = a8+=2; + +// //right eye +// lcd.drawRect((a3+3),35,0,0,1); +// //mouth piece +// lcd.drawRect((a3+3),37,0,0,1); +// //left eye +// lcd.drawRect((a3+1),35,0,0,1); +// //sword handle +// lcd.drawRect((a3-4),36,0,0,1); +// lcd.drawRect((a3-3),37,0,0,1); +// lcd.drawRect((a3-2),38,0,0,1); +// //back of the head +// lcd.drawRect((a3-1),33,0,4,1); +// //top of the head +// lcd.drawRect((a3-1),33,4,0,1); +// //jaw +// lcd.drawRect((a3+1),38,2,0,1); + ninjaBoundaries(); } if (joystick.direction == CENTRE) @@ -995,7 +1057,7 @@ contactPoint++; if(lcd.getPixel((a1),32)) contactPoint++; - if(lcd.getPixel((a7),32)) + if(lcd.getPixel((a3-3),32)) contactPoint++; //if contact point is not zero @@ -1021,7 +1083,6 @@ resetGame();//reset values break; } - wait(500); lcd.refresh();//refresh screen startrek();//clears unset pixels, keeps set pixels @@ -1222,7 +1283,7 @@ timerA.attach(&timerExpiredA, 0.1);//checks state of buttonA timerB.attach(&timerExpiredB, 0.1);//checks state of buttonB - + while(1) { drawMainMenu();//draws main menu mainMenu(mainOption);//presents main menu options