test 1 doc

Dependencies:   mbed Gamepad2

Committer:
joebarhouch
Date:
Wed May 27 04:22:47 2020 +0000
Revision:
12:eb8d30593e95
Parent:
11:b3024ab59fa5
Child:
14:58887d7e1072
dying scenarios

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
eencae 0:b7f1f47bb26a 20 // objects
eencae 0:b7f1f47bb26a 21 Gamepad pad;
eencae 0:b7f1f47bb26a 22 N5110 lcd;
joebarhouch 3:e4e1cbf750b6 23 Player player;
joebarhouch 3:e4e1cbf750b6 24 Engine engine;
eencae 0:b7f1f47bb26a 25
joebarhouch 11:b3024ab59fa5 26 // input
joebarhouch 3:e4e1cbf750b6 27 struct UserInput {
joebarhouch 3:e4e1cbf750b6 28 Direction d;
joebarhouch 3:e4e1cbf750b6 29 float mag;
joebarhouch 3:e4e1cbf750b6 30 };
joebarhouch 3:e4e1cbf750b6 31
joebarhouch 3:e4e1cbf750b6 32 // function prototypes
joebarhouch 2:f22cb01c43bc 33 void init();
joebarhouch 3:e4e1cbf750b6 34 void display();
joebarhouch 2:f22cb01c43bc 35
joebarhouch 11:b3024ab59fa5 36 // variables
joebarhouch 11:b3024ab59fa5 37 bool gameState = 0;
joebarhouch 5:928c2eee4109 38
joebarhouch 3:e4e1cbf750b6 39 int main()
joebarhouch 3:e4e1cbf750b6 40 {
joebarhouch 3:e4e1cbf750b6 41
joebarhouch 2:f22cb01c43bc 42
joebarhouch 2:f22cb01c43bc 43 init();
joebarhouch 3:e4e1cbf750b6 44
joebarhouch 3:e4e1cbf750b6 45 int fps = 10; // frames per second
joebarhouch 3:e4e1cbf750b6 46 display(); // first draw the initial frame
joebarhouch 3:e4e1cbf750b6 47 wait(1.0f/fps); // and wait for one frame period
joebarhouch 11:b3024ab59fa5 48 // game loop
joebarhouch 11:b3024ab59fa5 49 while (gameState == 0) {
joebarhouch 5:928c2eee4109 50 lcd.setContrast( pad.read_pot1()); //contrast set by pot1
joebarhouch 5:928c2eee4109 51 engine.read_input(pad); //reads input from pad
joebarhouch 5:928c2eee4109 52 engine.update(pad); //update physics and calculations
joebarhouch 5:928c2eee4109 53 display(); //display on screen
joebarhouch 5:928c2eee4109 54 wait(1.0f/fps); //wait for fps
joebarhouch 12:eb8d30593e95 55 gameState = engine.koed();
joebarhouch 11:b3024ab59fa5 56 }
joebarhouch 12:eb8d30593e95 57 while( player.get_pos().y < HEIGHT){
joebarhouch 11:b3024ab59fa5 58 engine.gameOver(lcd);
joebarhouch 11:b3024ab59fa5 59 lcd.refresh();
eencae 0:b7f1f47bb26a 60 }
joebarhouch 12:eb8d30593e95 61 }
eencae 0:b7f1f47bb26a 62
joebarhouch 5:928c2eee4109 63 //initialisation
joebarhouch 3:e4e1cbf750b6 64 void init()
joebarhouch 3:e4e1cbf750b6 65 {
joebarhouch 2:f22cb01c43bc 66 lcd.init();
joebarhouch 2:f22cb01c43bc 67 pad.init();
joebarhouch 3:e4e1cbf750b6 68 engine.init();
joebarhouch 3:e4e1cbf750b6 69 }
joebarhouch 2:f22cb01c43bc 70
joebarhouch 5:928c2eee4109 71 //display function by clearing, updating and refreshing
joebarhouch 3:e4e1cbf750b6 72 void display()
joebarhouch 3:e4e1cbf750b6 73 {
joebarhouch 3:e4e1cbf750b6 74 lcd.clear();
joebarhouch 3:e4e1cbf750b6 75 engine.draw(lcd);
joebarhouch 3:e4e1cbf750b6 76 lcd.refresh();
joebarhouch 3:e4e1cbf750b6 77 }
joebarhouch 3:e4e1cbf750b6 78
joebarhouch 3:e4e1cbf750b6 79