ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Committer:
el17m2h
Date:
Tue Apr 23 23:14:06 2019 +0000
Revision:
15:4efa04a6a376
Parent:
5:8814d6de77d0
Child:
19:5a7b0cdf013b
Changed the main function so that the back button takes the user back to the welcome menu.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17m2h 5:8814d6de77d0 1 /*
el17m2h 5:8814d6de77d0 2 ELEC2645 Embedded Systems Project
el17m2h 5:8814d6de77d0 3 School of Electronic & Electrical Engineering
el17m2h 5:8814d6de77d0 4 University of Leeds
el17m2h 5:8814d6de77d0 5 Name: Melissa Hartmann
el17m2h 5:8814d6de77d0 6 Username: el17m2h
el17m2h 5:8814d6de77d0 7 Student ID Number: 201176603
el17m2h 5:8814d6de77d0 8 Date: 11/04/2019
el17m2h 5:8814d6de77d0 9 */
el17m2h 5:8814d6de77d0 10
el17m2h 5:8814d6de77d0 11
el17m2h 1:0001cb3eb053 12 #include "mbed.h"
el17m2h 1:0001cb3eb053 13 #include "Gamepad.h"
el17m2h 1:0001cb3eb053 14 #include "N5110.h"
el17m2h 2:360a6c301a4e 15 #include "Engine.h"
el17m2h 1:0001cb3eb053 16
el17m2h 5:8814d6de77d0 17 #define FLOORS_WIDTH 13
el17m2h 3:116913e97fd7 18 #define FLOORS_HEIGHT 2
el17m2h 5:8814d6de77d0 19 #define DOODLER_RADIUS 2
el17m2h 5:8814d6de77d0 20
el17m2h 5:8814d6de77d0 21 //structs
el17m2h 5:8814d6de77d0 22 struct UserInput {
el17m2h 5:8814d6de77d0 23 Direction d;
el17m2h 5:8814d6de77d0 24 float mag;
el17m2h 5:8814d6de77d0 25 };
el17m2h 5:8814d6de77d0 26
el17m2h 1:0001cb3eb053 27
el17m2h 1:0001cb3eb053 28 // objects
el17m2h 1:0001cb3eb053 29 N5110 lcd(PTC5,PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // START, LCD SCE, LCD RST, LCD DC, LCD MOSI, LCD CLK, LCD Backlight
el17m2h 1:0001cb3eb053 30 Gamepad pad;
el17m2h 2:360a6c301a4e 31 Engine eng;
el17m2h 1:0001cb3eb053 32
el17m2h 1:0001cb3eb053 33 // prototypes
el17m2h 1:0001cb3eb053 34 void init();
el17m2h 5:8814d6de77d0 35 void update_game(UserInput input);
el17m2h 5:8814d6de77d0 36 void render();
el17m2h 1:0001cb3eb053 37 void welcome();
el17m2h 1:0001cb3eb053 38
el17m2h 1:0001cb3eb053 39 // functions
el17m2h 1:0001cb3eb053 40 int main(){
el17m2h 15:4efa04a6a376 41 while(1){
el17m2h 15:4efa04a6a376 42 init(); // initialise and then display welcome screen...
el17m2h 15:4efa04a6a376 43 welcome();
el17m2h 15:4efa04a6a376 44 render();
el17m2h 15:4efa04a6a376 45 wait(0.1);
el17m2h 1:0001cb3eb053 46 }
el17m2h 1:0001cb3eb053 47 }
el17m2h 1:0001cb3eb053 48
el17m2h 1:0001cb3eb053 49 // initialies all classes and libraries
el17m2h 1:0001cb3eb053 50 void init(){
el17m2h 1:0001cb3eb053 51 // need to initialise LCD and Gamepad
el17m2h 1:0001cb3eb053 52 lcd.init();
el17m2h 1:0001cb3eb053 53 pad.init();
el17m2h 4:8ec314f806ae 54 eng.init(FLOORS_WIDTH, FLOORS_HEIGHT, DOODLER_RADIUS);
el17m2h 1:0001cb3eb053 55 }
el17m2h 1:0001cb3eb053 56
el17m2h 5:8814d6de77d0 57 void render(){
el17m2h 5:8814d6de77d0 58 lcd.clear();
el17m2h 5:8814d6de77d0 59 eng.draw(lcd);
el17m2h 5:8814d6de77d0 60 lcd.refresh();
el17m2h 5:8814d6de77d0 61 }
el17m2h 5:8814d6de77d0 62
el17m2h 1:0001cb3eb053 63 // Starting menu screen display
el17m2h 1:0001cb3eb053 64 void welcome() {
el17m2h 1:0001cb3eb053 65 lcd.printString(" Doodle Jump! ",0,1);
el17m2h 1:0001cb3eb053 66 lcd.printString(" Press Start ",0,4);
el17m2h 1:0001cb3eb053 67 lcd.refresh();
el17m2h 5:8814d6de77d0 68
el17m2h 5:8814d6de77d0 69 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
el17m2h 5:8814d6de77d0 70 pad.leds_on();
el17m2h 5:8814d6de77d0 71 wait(0.1);
el17m2h 5:8814d6de77d0 72 pad.leds_off();
el17m2h 5:8814d6de77d0 73 wait(0.1);
el17m2h 5:8814d6de77d0 74 }
el17m2h 15:4efa04a6a376 75
el17m2h 15:4efa04a6a376 76 int fps = 8;
el17m2h 15:4efa04a6a376 77 render(); // draws
el17m2h 15:4efa04a6a376 78 wait(1.0f/fps);
el17m2h 15:4efa04a6a376 79 while(1){
el17m2h 15:4efa04a6a376 80 eng.read_input(pad);
el17m2h 15:4efa04a6a376 81 eng.update(pad);
el17m2h 15:4efa04a6a376 82 render();
el17m2h 15:4efa04a6a376 83 wait(1.0f/fps);
el17m2h 15:4efa04a6a376 84 if (pad.check_event(Gamepad::BACK_PRESSED) == true){
el17m2h 15:4efa04a6a376 85 break;
el17m2h 15:4efa04a6a376 86 }
el17m2h 15:4efa04a6a376 87 }
el17m2h 15:4efa04a6a376 88 }