test 1 doc

Dependencies:   mbed Gamepad2

Committer:
joebarhouch
Date:
Mon May 18 16:06:27 2020 +0000
Revision:
3:e4e1cbf750b6
Parent:
2:f22cb01c43bc
Child:
4:cf5088ace087
Character movement with game engine

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"
eencae 0:b7f1f47bb26a 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 3:e4e1cbf750b6 38 int main()
joebarhouch 3:e4e1cbf750b6 39 {
joebarhouch 3:e4e1cbf750b6 40
joebarhouch 2:f22cb01c43bc 41
joebarhouch 2:f22cb01c43bc 42 init();
joebarhouch 3:e4e1cbf750b6 43
joebarhouch 3:e4e1cbf750b6 44 int fps = 10; // frames per second
joebarhouch 3:e4e1cbf750b6 45 display(); // first draw the initial frame
joebarhouch 3:e4e1cbf750b6 46 wait(1.0f/fps); // and wait for one frame period
joebarhouch 3:e4e1cbf750b6 47
joebarhouch 3:e4e1cbf750b6 48 // game loop - read input, update the game state and render the display
joebarhouch 3:e4e1cbf750b6 49 while (1) {
joebarhouch 3:e4e1cbf750b6 50 lcd.setContrast( pad.read_pot1());
joebarhouch 3:e4e1cbf750b6 51 engine.read_input(pad);
joebarhouch 3:e4e1cbf750b6 52 engine.update(pad);
joebarhouch 3:e4e1cbf750b6 53 display();
joebarhouch 3:e4e1cbf750b6 54 wait(1.0f/fps);
joebarhouch 2:f22cb01c43bc 55 }
eencae 0:b7f1f47bb26a 56 }
eencae 0:b7f1f47bb26a 57
joebarhouch 3:e4e1cbf750b6 58 void init()
joebarhouch 3:e4e1cbf750b6 59 {
joebarhouch 2:f22cb01c43bc 60 lcd.init();
joebarhouch 2:f22cb01c43bc 61 pad.init();
joebarhouch 3:e4e1cbf750b6 62 engine.init();
joebarhouch 3:e4e1cbf750b6 63 }
joebarhouch 2:f22cb01c43bc 64
joebarhouch 3:e4e1cbf750b6 65 void display()
joebarhouch 3:e4e1cbf750b6 66 {
joebarhouch 3:e4e1cbf750b6 67 lcd.clear();
joebarhouch 3:e4e1cbf750b6 68 engine.draw(lcd);
joebarhouch 3:e4e1cbf750b6 69 lcd.refresh();
joebarhouch 3:e4e1cbf750b6 70 }
joebarhouch 3:e4e1cbf750b6 71
joebarhouch 3:e4e1cbf750b6 72