ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Committer:
el17m2h
Date:
Thu Apr 25 08:43:46 2019 +0000
Revision:
19:5a7b0cdf013b
Parent:
15:4efa04a6a376
Child:
20:a359092079b0
Added a game over function to the main file so that once the doodler hits the floor the game is finalized.

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 19:5a7b0cdf013b 17 #define FLOORS_WIDTH 12
el17m2h 19:5a7b0cdf013b 18 #define FLOORS_HEIGHT 1
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 19:5a7b0cdf013b 32 Doodler dood;
el17m2h 1:0001cb3eb053 33
el17m2h 1:0001cb3eb053 34 // prototypes
el17m2h 1:0001cb3eb053 35 void init();
el17m2h 5:8814d6de77d0 36 void update_game(UserInput input);
el17m2h 5:8814d6de77d0 37 void render();
el17m2h 1:0001cb3eb053 38 void welcome();
el17m2h 19:5a7b0cdf013b 39 void game_over();
el17m2h 1:0001cb3eb053 40
el17m2h 1:0001cb3eb053 41 // functions
el17m2h 1:0001cb3eb053 42 int main(){
el17m2h 15:4efa04a6a376 43 while(1){
el17m2h 15:4efa04a6a376 44 init(); // initialise and then display welcome screen...
el17m2h 15:4efa04a6a376 45 welcome();
el17m2h 19:5a7b0cdf013b 46 int fps = 8;
el17m2h 19:5a7b0cdf013b 47 render(); // draws
el17m2h 19:5a7b0cdf013b 48 wait(1.0f/fps);
el17m2h 19:5a7b0cdf013b 49 while(1){
el17m2h 19:5a7b0cdf013b 50 eng.read_input(pad);
el17m2h 19:5a7b0cdf013b 51 eng.update(pad);
el17m2h 19:5a7b0cdf013b 52 render();
el17m2h 19:5a7b0cdf013b 53 wait(0.8f/fps);
el17m2h 19:5a7b0cdf013b 54 if (pad.check_event(Gamepad::BACK_PRESSED) == true){
el17m2h 19:5a7b0cdf013b 55 break;
el17m2h 19:5a7b0cdf013b 56 }
el17m2h 19:5a7b0cdf013b 57 if (dood.get_position_y() > 36){
el17m2h 19:5a7b0cdf013b 58 while(1){
el17m2h 19:5a7b0cdf013b 59 game_over();
el17m2h 19:5a7b0cdf013b 60 if (pad.check_event(Gamepad::START_PRESSED) == true){
el17m2h 19:5a7b0cdf013b 61 break;
el17m2h 19:5a7b0cdf013b 62 }
el17m2h 19:5a7b0cdf013b 63 }
el17m2h 19:5a7b0cdf013b 64 }
el17m2h 19:5a7b0cdf013b 65 }
el17m2h 15:4efa04a6a376 66 render();
el17m2h 15:4efa04a6a376 67 wait(0.1);
el17m2h 1:0001cb3eb053 68 }
el17m2h 1:0001cb3eb053 69 }
el17m2h 1:0001cb3eb053 70
el17m2h 19:5a7b0cdf013b 71
el17m2h 1:0001cb3eb053 72 // initialies all classes and libraries
el17m2h 1:0001cb3eb053 73 void init(){
el17m2h 1:0001cb3eb053 74 // need to initialise LCD and Gamepad
el17m2h 1:0001cb3eb053 75 lcd.init();
el17m2h 1:0001cb3eb053 76 pad.init();
el17m2h 4:8ec314f806ae 77 eng.init(FLOORS_WIDTH, FLOORS_HEIGHT, DOODLER_RADIUS);
el17m2h 1:0001cb3eb053 78 }
el17m2h 1:0001cb3eb053 79
el17m2h 5:8814d6de77d0 80 void render(){
el17m2h 5:8814d6de77d0 81 lcd.clear();
el17m2h 5:8814d6de77d0 82 eng.draw(lcd);
el17m2h 5:8814d6de77d0 83 lcd.refresh();
el17m2h 5:8814d6de77d0 84 }
el17m2h 5:8814d6de77d0 85
el17m2h 1:0001cb3eb053 86 // Starting menu screen display
el17m2h 1:0001cb3eb053 87 void welcome() {
el17m2h 1:0001cb3eb053 88 lcd.printString(" Doodle Jump! ",0,1);
el17m2h 1:0001cb3eb053 89 lcd.printString(" Press Start ",0,4);
el17m2h 1:0001cb3eb053 90 lcd.refresh();
el17m2h 5:8814d6de77d0 91
el17m2h 5:8814d6de77d0 92 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
el17m2h 5:8814d6de77d0 93 pad.leds_on();
el17m2h 5:8814d6de77d0 94 wait(0.1);
el17m2h 5:8814d6de77d0 95 pad.leds_off();
el17m2h 5:8814d6de77d0 96 wait(0.1);
el17m2h 5:8814d6de77d0 97 }
el17m2h 19:5a7b0cdf013b 98 }
el17m2h 19:5a7b0cdf013b 99
el17m2h 19:5a7b0cdf013b 100 void game_over() {
el17m2h 19:5a7b0cdf013b 101 lcd.clear();
el17m2h 19:5a7b0cdf013b 102 lcd.printString("Game Over! Press back",0,1);
el17m2h 19:5a7b0cdf013b 103 lcd.printString(" SCORE = ",0,4);
el17m2h 19:5a7b0cdf013b 104 lcd.refresh();
el17m2h 19:5a7b0cdf013b 105 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
el17m2h 19:5a7b0cdf013b 106 pad.leds_on();
el17m2h 19:5a7b0cdf013b 107 wait(0.1);
el17m2h 19:5a7b0cdf013b 108 pad.leds_off();
el17m2h 19:5a7b0cdf013b 109 wait(0.1);
el17m2h 15:4efa04a6a376 110 }
el17m2h 15:4efa04a6a376 111 }