ELEC2645 (2019/20)
/
ELEC2645_Project_el18jb
test 1 doc
Diff: main.cpp
- Revision:
- 14:58887d7e1072
- Parent:
- 12:eb8d30593e95
- Child:
- 15:9ea5269b4cd4
diff -r cb5ed2f0cbd5 -r 58887d7e1072 main.cpp --- a/main.cpp Wed May 27 04:36:22 2020 +0000 +++ b/main.cpp Wed May 27 07:48:27 2020 +0000 @@ -17,6 +17,25 @@ #include "Player.h" #include "Engine.h" +int intro[] = { + 1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1, + 1,1,1,0,1,0,1,0,0,0,0,1,0,1,0,1,1,1, + 1,1,1,0,1,0,1,1,1,1,1,1,0,1,0,1,1,1, + 1,1,1,0,1,0,1,1,0,0,1,1,0,1,0,1,1,1, + 1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1, + 0,1,1,0,1,1,0,0,0,0,0,0,1,1,0,1,1,0, + 0,1,1,0,1,1,0,0,0,0,0,0,1,1,0,1,1,0, + 1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1, + 1,1,1,0,1,0,1,0,0,0,0,1,0,1,0,1,1,1, + 1,1,1,0,1,0,1,1,1,1,1,1,0,1,0,1,1,1, + 1,1,1,0,1,0,1,1,0,0,1,1,0,1,0,1,1,1, + 1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1, + 0,1,1,0,1,1,0,0,0,0,0,0,1,1,0,1,1,0, + 0,1,1,0,1,1,0,0,0,0,0,0,1,1,0,1,1,0, +}; +Bitmap introo(intro, 16,18); // objects Gamepad pad; N5110 lcd; @@ -35,45 +54,74 @@ // variables bool gameState = 0; +Timer T; +bool pause = 1; +bool i=0; +int fps; int main() { init(); - + char buffer[14]; int fps = 10; // frames per second - display(); // first draw the initial frame - wait(1.0f/fps); // and wait for one frame period - // game loop - while (gameState == 0) { - lcd.setContrast( pad.read_pot1()); //contrast set by pot1 - engine.read_input(pad); //reads input from pad - engine.update(pad); //update physics and calculations - display(); //display on screen - wait(1.0f/fps); //wait for fps - gameState = engine.koed(); + while(pause == 1 ) { + lcd.clear(); + if(i == 0) { + lcd.normalMode(); + lcd.clear(); + introo.render(lcd, 33,16); + sprintf(buffer,"A for Hard, B for Easy"); + lcd.printString(buffer,10,40); + lcd.refresh(); + if( pad.A_pressed() ){ + pause =0; + fps = 13; + } else if(pad.B_pressed() ){ + pause =0; + fps = 10; + } + } } - while( player.get_pos().y < HEIGHT){ - engine.gameOver(lcd); - lcd.refresh(); -} -} + display(); // first draw the initial frame + wait(1.0f/fps); // and wait for one frame period + // game loop + while (gameState == 0) { + T.start(); + srand(T); + lcd.setContrast( pad.read_pot1()); //contrast set by pot1 + engine.read_input(pad); //reads input from pad + engine.update(pad); //update physics and calculations + display(); //display on screen + wait(1.0f/fps); //wait for fps + gameState = engine.koed(); + } + engine.gameOver(lcd); + lcd.clear(); + int Score = engine.getScore(); + lcd.normalMode(); + sprintf(buffer,"Your score is: %i", Score); + lcd.printString(buffer,10,40); + lcd.refresh(); + + if(pad.A_pressed() || pad.B_pressed() || pad.X_pressed() || pad.Y_pressed() ||pad.start_pressed()){ + gameState=1; + } + } //initialisation -void init() -{ - lcd.init(); - pad.init(); - engine.init(); -} + void init() { + lcd.init(); + pad.init(); + engine.init(); + } //display function by clearing, updating and refreshing -void display() -{ - lcd.clear(); - engine.draw(lcd); - lcd.refresh(); -} + void display() { + lcd.clear(); + engine.draw(lcd); + lcd.refresh(); + }