test 1 doc

Dependencies:   mbed Gamepad2

Committer:
joebarhouch
Date:
Fri May 22 01:26:24 2020 +0000
Revision:
5:928c2eee4109
Parent:
4:cf5088ace087
Child:
7:530ca713d2b2
Platform classes for map design;

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 4:cf5088ace087 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 3:e4e1cbf750b6 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
joebarhouch 3:e4e1cbf750b6 33
joebarhouch 3:e4e1cbf750b6 34 // function prototypes
joebarhouch 2:f22cb01c43bc 35 void init();
joebarhouch 3:e4e1cbf750b6 36 void display();
joebarhouch 2:f22cb01c43bc 37
joebarhouch 5:928c2eee4109 38
joebarhouch 5:928c2eee4109 39
joebarhouch 3:e4e1cbf750b6 40 int main()
joebarhouch 3:e4e1cbf750b6 41 {
joebarhouch 3:e4e1cbf750b6 42
joebarhouch 2:f22cb01c43bc 43
joebarhouch 2:f22cb01c43bc 44 init();
joebarhouch 3:e4e1cbf750b6 45
joebarhouch 3:e4e1cbf750b6 46 int fps = 10; // frames per second
joebarhouch 3:e4e1cbf750b6 47 display(); // first draw the initial frame
joebarhouch 3:e4e1cbf750b6 48 wait(1.0f/fps); // and wait for one frame period
joebarhouch 5:928c2eee4109 49 // game loop
joebarhouch 3:e4e1cbf750b6 50 while (1) {
joebarhouch 5:928c2eee4109 51 lcd.setContrast( pad.read_pot1()); //contrast set by pot1
joebarhouch 5:928c2eee4109 52 engine.read_input(pad); //reads input from pad
joebarhouch 5:928c2eee4109 53 engine.update(pad); //update physics and calculations
joebarhouch 5:928c2eee4109 54 display(); //display on screen
joebarhouch 5:928c2eee4109 55 wait(1.0f/fps); //wait for fps
joebarhouch 5:928c2eee4109 56 }
eencae 0:b7f1f47bb26a 57 }
eencae 0:b7f1f47bb26a 58
joebarhouch 5:928c2eee4109 59 //initialisation
joebarhouch 3:e4e1cbf750b6 60 void init()
joebarhouch 3:e4e1cbf750b6 61 {
joebarhouch 2:f22cb01c43bc 62 lcd.init();
joebarhouch 2:f22cb01c43bc 63 pad.init();
joebarhouch 3:e4e1cbf750b6 64 engine.init();
joebarhouch 3:e4e1cbf750b6 65 }
joebarhouch 2:f22cb01c43bc 66
joebarhouch 5:928c2eee4109 67 //display function by clearing, updating and refreshing
joebarhouch 3:e4e1cbf750b6 68 void display()
joebarhouch 3:e4e1cbf750b6 69 {
joebarhouch 3:e4e1cbf750b6 70 lcd.clear();
joebarhouch 3:e4e1cbf750b6 71 engine.draw(lcd);
joebarhouch 3:e4e1cbf750b6 72 lcd.refresh();
joebarhouch 3:e4e1cbf750b6 73 }
joebarhouch 3:e4e1cbf750b6 74
joebarhouch 3:e4e1cbf750b6 75