ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Committer:
el17m2h
Date:
Wed May 01 16:40:35 2019 +0000
Revision:
21:6b16ca9834e6
Parent:
20:a359092079b0
Child:
22:0d2ac98a8b48
Changed the values the floors need to be to add score points, so that the score value will increase every time the floors are y=10.

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