![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
test 1 doc
main.cpp@7:530ca713d2b2, 2020-05-26 (annotated)
- Committer:
- joebarhouch
- Date:
- Tue May 26 01:45:20 2020 +0000
- Revision:
- 7:530ca713d2b2
- Parent:
- 5:928c2eee4109
- Child:
- 11:b3024ab59fa5
Fully functional game physics with floor collision and jumps
Who changed what in which revision?
User | Revision | Line number | New 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 | // function prototypes |
joebarhouch | 2:f22cb01c43bc | 33 | void init(); |
joebarhouch | 3:e4e1cbf750b6 | 34 | void display(); |
joebarhouch | 2:f22cb01c43bc | 35 | |
joebarhouch | 5:928c2eee4109 | 36 | |
joebarhouch | 5:928c2eee4109 | 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 | 5:928c2eee4109 | 47 | // game loop |
joebarhouch | 3:e4e1cbf750b6 | 48 | while (1) { |
joebarhouch | 5:928c2eee4109 | 49 | lcd.setContrast( pad.read_pot1()); //contrast set by pot1 |
joebarhouch | 5:928c2eee4109 | 50 | engine.read_input(pad); //reads input from pad |
joebarhouch | 5:928c2eee4109 | 51 | engine.update(pad); //update physics and calculations |
joebarhouch | 5:928c2eee4109 | 52 | display(); //display on screen |
joebarhouch | 5:928c2eee4109 | 53 | wait(1.0f/fps); //wait for fps |
joebarhouch | 5:928c2eee4109 | 54 | } |
eencae | 0:b7f1f47bb26a | 55 | } |
eencae | 0:b7f1f47bb26a | 56 | |
joebarhouch | 5:928c2eee4109 | 57 | //initialisation |
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 | 5:928c2eee4109 | 65 | //display function by clearing, updating and refreshing |
joebarhouch | 3:e4e1cbf750b6 | 66 | void display() |
joebarhouch | 3:e4e1cbf750b6 | 67 | { |
joebarhouch | 3:e4e1cbf750b6 | 68 | lcd.clear(); |
joebarhouch | 3:e4e1cbf750b6 | 69 | engine.draw(lcd); |
joebarhouch | 3:e4e1cbf750b6 | 70 | lcd.refresh(); |
joebarhouch | 3:e4e1cbf750b6 | 71 | } |
joebarhouch | 3:e4e1cbf750b6 | 72 | |
joebarhouch | 3:e4e1cbf750b6 | 73 |