test 1 doc

Dependencies:   mbed Gamepad2

Committer:
joebarhouch
Date:
Wed May 27 07:48:27 2020 +0000
Revision:
14:58887d7e1072
Parent:
12:eb8d30593e95
Child:
15:9ea5269b4cd4
final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joebarhouch 3:e4e1cbf750b6 1 /*
eencae 0:b7f1f47bb26a 2 ELEC2645 Embedded Systems Project
eencae 0:b7f1f47bb26a 3 School of Electronic & Electrical Engineering
eencae 0:b7f1f47bb26a 4 University of Leeds
eencae 0:b7f1f47bb26a 5 2019/20
eencae 0:b7f1f47bb26a 6
joebarhouch 1:7fe71d8e48da 7 Name: Joe Barhouch
joebarhouch 1:7fe71d8e48da 8 Username: el18jb
joebarhouch 1:7fe71d8e48da 9 Student ID Number: 201291584
eencae 0:b7f1f47bb26a 10 */
eencae 0:b7f1f47bb26a 11
eencae 0:b7f1f47bb26a 12 // includes
eencae 0:b7f1f47bb26a 13 #include "mbed.h"
eencae 0:b7f1f47bb26a 14 #include "Gamepad.h"
eencae 0:b7f1f47bb26a 15 #include "N5110.h"
joebarhouch 2:f22cb01c43bc 16 #include "Bitmap.h"
joebarhouch 3:e4e1cbf750b6 17 #include "Player.h"
joebarhouch 3:e4e1cbf750b6 18 #include "Engine.h"
joebarhouch 11:b3024ab59fa5 19
joebarhouch 14:58887d7e1072 20 int intro[] = {
joebarhouch 14:58887d7e1072 21 1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,
joebarhouch 14:58887d7e1072 22 1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,
joebarhouch 14:58887d7e1072 23 1,1,1,0,1,0,1,0,0,0,0,1,0,1,0,1,1,1,
joebarhouch 14:58887d7e1072 24 1,1,1,0,1,0,1,1,1,1,1,1,0,1,0,1,1,1,
joebarhouch 14:58887d7e1072 25 1,1,1,0,1,0,1,1,0,0,1,1,0,1,0,1,1,1,
joebarhouch 14:58887d7e1072 26 1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,
joebarhouch 14:58887d7e1072 27 0,1,1,0,1,1,0,0,0,0,0,0,1,1,0,1,1,0,
joebarhouch 14:58887d7e1072 28 0,1,1,0,1,1,0,0,0,0,0,0,1,1,0,1,1,0,
joebarhouch 14:58887d7e1072 29 1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,
joebarhouch 14:58887d7e1072 30 1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,
joebarhouch 14:58887d7e1072 31 1,1,1,0,1,0,1,0,0,0,0,1,0,1,0,1,1,1,
joebarhouch 14:58887d7e1072 32 1,1,1,0,1,0,1,1,1,1,1,1,0,1,0,1,1,1,
joebarhouch 14:58887d7e1072 33 1,1,1,0,1,0,1,1,0,0,1,1,0,1,0,1,1,1,
joebarhouch 14:58887d7e1072 34 1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,
joebarhouch 14:58887d7e1072 35 0,1,1,0,1,1,0,0,0,0,0,0,1,1,0,1,1,0,
joebarhouch 14:58887d7e1072 36 0,1,1,0,1,1,0,0,0,0,0,0,1,1,0,1,1,0,
joebarhouch 14:58887d7e1072 37 };
joebarhouch 14:58887d7e1072 38 Bitmap introo(intro, 16,18);
eencae 0:b7f1f47bb26a 39 // objects
eencae 0:b7f1f47bb26a 40 Gamepad pad;
eencae 0:b7f1f47bb26a 41 N5110 lcd;
joebarhouch 3:e4e1cbf750b6 42 Player player;
joebarhouch 3:e4e1cbf750b6 43 Engine engine;
eencae 0:b7f1f47bb26a 44
joebarhouch 11:b3024ab59fa5 45 // input
joebarhouch 3:e4e1cbf750b6 46 struct UserInput {
joebarhouch 3:e4e1cbf750b6 47 Direction d;
joebarhouch 3:e4e1cbf750b6 48 float mag;
joebarhouch 3:e4e1cbf750b6 49 };
joebarhouch 3:e4e1cbf750b6 50
joebarhouch 3:e4e1cbf750b6 51 // function prototypes
joebarhouch 2:f22cb01c43bc 52 void init();
joebarhouch 3:e4e1cbf750b6 53 void display();
joebarhouch 2:f22cb01c43bc 54
joebarhouch 11:b3024ab59fa5 55 // variables
joebarhouch 11:b3024ab59fa5 56 bool gameState = 0;
joebarhouch 14:58887d7e1072 57 Timer T;
joebarhouch 14:58887d7e1072 58 bool pause = 1;
joebarhouch 14:58887d7e1072 59 bool i=0;
joebarhouch 14:58887d7e1072 60 int fps;
joebarhouch 5:928c2eee4109 61
joebarhouch 3:e4e1cbf750b6 62 int main()
joebarhouch 3:e4e1cbf750b6 63 {
joebarhouch 3:e4e1cbf750b6 64
joebarhouch 2:f22cb01c43bc 65
joebarhouch 2:f22cb01c43bc 66 init();
joebarhouch 14:58887d7e1072 67 char buffer[14];
joebarhouch 3:e4e1cbf750b6 68 int fps = 10; // frames per second
joebarhouch 14:58887d7e1072 69 while(pause == 1 ) {
joebarhouch 14:58887d7e1072 70 lcd.clear();
joebarhouch 14:58887d7e1072 71 if(i == 0) {
joebarhouch 14:58887d7e1072 72 lcd.normalMode();
joebarhouch 14:58887d7e1072 73 lcd.clear();
joebarhouch 14:58887d7e1072 74 introo.render(lcd, 33,16);
joebarhouch 14:58887d7e1072 75 sprintf(buffer,"A for Hard, B for Easy");
joebarhouch 14:58887d7e1072 76 lcd.printString(buffer,10,40);
joebarhouch 14:58887d7e1072 77 lcd.refresh();
joebarhouch 14:58887d7e1072 78 if( pad.A_pressed() ){
joebarhouch 14:58887d7e1072 79 pause =0;
joebarhouch 14:58887d7e1072 80 fps = 13;
joebarhouch 14:58887d7e1072 81 } else if(pad.B_pressed() ){
joebarhouch 14:58887d7e1072 82 pause =0;
joebarhouch 14:58887d7e1072 83 fps = 10;
joebarhouch 14:58887d7e1072 84 }
joebarhouch 14:58887d7e1072 85 }
joebarhouch 11:b3024ab59fa5 86 }
joebarhouch 14:58887d7e1072 87 display(); // first draw the initial frame
joebarhouch 14:58887d7e1072 88 wait(1.0f/fps); // and wait for one frame period
joebarhouch 14:58887d7e1072 89 // game loop
eencae 0:b7f1f47bb26a 90
joebarhouch 14:58887d7e1072 91 while (gameState == 0) {
joebarhouch 14:58887d7e1072 92 T.start();
joebarhouch 14:58887d7e1072 93 srand(T);
joebarhouch 14:58887d7e1072 94 lcd.setContrast( pad.read_pot1()); //contrast set by pot1
joebarhouch 14:58887d7e1072 95 engine.read_input(pad); //reads input from pad
joebarhouch 14:58887d7e1072 96 engine.update(pad); //update physics and calculations
joebarhouch 14:58887d7e1072 97 display(); //display on screen
joebarhouch 14:58887d7e1072 98 wait(1.0f/fps); //wait for fps
joebarhouch 14:58887d7e1072 99 gameState = engine.koed();
joebarhouch 14:58887d7e1072 100 }
joebarhouch 14:58887d7e1072 101 engine.gameOver(lcd);
joebarhouch 14:58887d7e1072 102 lcd.clear();
joebarhouch 14:58887d7e1072 103 int Score = engine.getScore();
joebarhouch 14:58887d7e1072 104 lcd.normalMode();
joebarhouch 14:58887d7e1072 105 sprintf(buffer,"Your score is: %i", Score);
joebarhouch 14:58887d7e1072 106 lcd.printString(buffer,10,40);
joebarhouch 14:58887d7e1072 107 lcd.refresh();
joebarhouch 14:58887d7e1072 108
joebarhouch 14:58887d7e1072 109 if(pad.A_pressed() || pad.B_pressed() || pad.X_pressed() || pad.Y_pressed() ||pad.start_pressed()){
joebarhouch 14:58887d7e1072 110 gameState=1;
joebarhouch 14:58887d7e1072 111 }
joebarhouch 14:58887d7e1072 112 }
joebarhouch 5:928c2eee4109 113 //initialisation
joebarhouch 14:58887d7e1072 114 void init() {
joebarhouch 14:58887d7e1072 115 lcd.init();
joebarhouch 14:58887d7e1072 116 pad.init();
joebarhouch 14:58887d7e1072 117 engine.init();
joebarhouch 14:58887d7e1072 118 }
joebarhouch 2:f22cb01c43bc 119
joebarhouch 5:928c2eee4109 120 //display function by clearing, updating and refreshing
joebarhouch 14:58887d7e1072 121 void display() {
joebarhouch 14:58887d7e1072 122 lcd.clear();
joebarhouch 14:58887d7e1072 123 engine.draw(lcd);
joebarhouch 14:58887d7e1072 124 lcd.refresh();
joebarhouch 14:58887d7e1072 125 }
joebarhouch 3:e4e1cbf750b6 126
joebarhouch 3:e4e1cbf750b6 127