ELEC2645 (2018/19) / Mbed 2 deprecated 2645_Project_SiutingWong201186503

Dependencies:   mbed

Committer:
davidwst421
Date:
Wed May 08 20:13:48 2019 +0000
Revision:
3:53f0365461c0
Parent:
2:00a3edbe39b0
Child:
4:fcd80b40f257
add sad music at the end

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davidwst421 0:fd8eda608206 1 /*
davidwst421 0:fd8eda608206 2 ELEC2645 Embedded Systems Project
davidwst421 0:fd8eda608206 3 School of Electronic & Electrical Engineering
davidwst421 0:fd8eda608206 4 University of Leeds
davidwst421 0:fd8eda608206 5 Name: Siuting Wong
davidwst421 0:fd8eda608206 6 Username: Siuting Wong
davidwst421 0:fd8eda608206 7 Student ID Number: 201186503
davidwst421 0:fd8eda608206 8 Date: 06/05/2019
davidwst421 0:fd8eda608206 9 */
davidwst421 0:fd8eda608206 10 ///////// pre-processor directives ////////
davidwst421 0:fd8eda608206 11 #include "mbed.h"
davidwst421 0:fd8eda608206 12 #include "Gamepad.h"
davidwst421 0:fd8eda608206 13 #include "N5110.h"
davidwst421 0:fd8eda608206 14 #include "Engine.h"
davidwst421 0:fd8eda608206 15
davidwst421 0:fd8eda608206 16 #define WALL_WIDTH 2
davidwst421 0:fd8eda608206 17 #define WALL_GAP 8
davidwst421 0:fd8eda608206 18 #define AVENGER_SIZE 2
davidwst421 0:fd8eda608206 19 #define STONE_SIZE 1
davidwst421 2:00a3edbe39b0 20 #define SPEED 2
davidwst421 0:fd8eda608206 21
davidwst421 0:fd8eda608206 22 /////////////// structs /////////////////
davidwst421 0:fd8eda608206 23 struct UserInput {
davidwst421 0:fd8eda608206 24 Direction d;
davidwst421 0:fd8eda608206 25 float mag;
davidwst421 0:fd8eda608206 26 };
davidwst421 0:fd8eda608206 27 /////////////// objects ///////////////
davidwst421 0:fd8eda608206 28 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
davidwst421 0:fd8eda608206 29 Gamepad pad;
davidwst421 0:fd8eda608206 30 Engine eng;
davidwst421 0:fd8eda608206 31
davidwst421 0:fd8eda608206 32 ///////////// prototypes ///////////////
davidwst421 0:fd8eda608206 33 void init();
davidwst421 0:fd8eda608206 34 void update_game(UserInput input);
davidwst421 0:fd8eda608206 35 void render();
davidwst421 0:fd8eda608206 36 void welcome();
davidwst421 0:fd8eda608206 37
davidwst421 0:fd8eda608206 38
davidwst421 0:fd8eda608206 39 ///////////// functions ////////////////
davidwst421 0:fd8eda608206 40 int main() {
davidwst421 2:00a3edbe39b0 41 int fps = 10;
davidwst421 2:00a3edbe39b0 42 int avenger_score = _avenger.get_score();
davidwst421 0:fd8eda608206 43
davidwst421 0:fd8eda608206 44 init(); // initialise and then display welcome screen...
davidwst421 0:fd8eda608206 45 welcome();
davidwst421 0:fd8eda608206 46 render();
davidwst421 0:fd8eda608206 47 wait(1.0f/fps); // and wait for one frame period
davidwst421 0:fd8eda608206 48
davidwst421 2:00a3edbe39b0 49 while (avenger_score >= 0) {
davidwst421 2:00a3edbe39b0 50
davidwst421 0:fd8eda608206 51 eng.read_input(pad);
davidwst421 0:fd8eda608206 52 eng.update(pad);
davidwst421 2:00a3edbe39b0 53
davidwst421 0:fd8eda608206 54 render();
davidwst421 0:fd8eda608206 55 wait(1.0f/fps);
davidwst421 0:fd8eda608206 56 }
davidwst421 2:00a3edbe39b0 57 endgame();
davidwst421 0:fd8eda608206 58 }
davidwst421 0:fd8eda608206 59
davidwst421 0:fd8eda608206 60 void init() {
davidwst421 0:fd8eda608206 61
davidwst421 0:fd8eda608206 62 // need to initialise LCD and Gamepad
davidwst421 0:fd8eda608206 63 lcd.init();
davidwst421 0:fd8eda608206 64 pad.init();
davidwst421 0:fd8eda608206 65
davidwst421 0:fd8eda608206 66 // initialise the game with correct ball and paddle sizes
davidwst421 1:f09ff0ed98fd 67 eng.init(WALL_WIDTH,WALL_GAP,AVENGER_SIZE,STONE_SIZE,SPEED);
davidwst421 0:fd8eda608206 68 }
davidwst421 0:fd8eda608206 69
davidwst421 0:fd8eda608206 70 void welcome() {
davidwst421 0:fd8eda608206 71
davidwst421 0:fd8eda608206 72 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
davidwst421 0:fd8eda608206 73 lcd.clear();
davidwst421 0:fd8eda608206 74 lcd.printString("Eternity Stone",0,1);
davidwst421 0:fd8eda608206 75 lcd.refresh();
davidwst421 0:fd8eda608206 76 wait(0.1);
davidwst421 0:fd8eda608206 77 }
davidwst421 0:fd8eda608206 78 }
davidwst421 0:fd8eda608206 79
davidwst421 0:fd8eda608206 80 void render() {
davidwst421 0:fd8eda608206 81
davidwst421 0:fd8eda608206 82 // clear screen, re-draw and refresh
davidwst421 0:fd8eda608206 83 lcd.clear();
davidwst421 0:fd8eda608206 84 eng.draw(lcd);
davidwst421 0:fd8eda608206 85 lcd.refresh();
davidwst421 2:00a3edbe39b0 86 }
davidwst421 2:00a3edbe39b0 87
davidwst421 2:00a3edbe39b0 88 void endgame() {
davidwst421 3:53f0365461c0 89 lcd.clear();
davidwst421 3:53f0365461c0 90 lcd.printString("Endgame",12,1);
davidwst421 2:00a3edbe39b0 91 lcd.refresh();
davidwst421 3:53f0365461c0 92 pad.tone(587.3,0.9);
davidwst421 3:53f0365461c0 93 pad.tone(0.0,0.1);
davidwst421 3:53f0365461c0 94 pad.tone(587.3,0.9);
davidwst421 3:53f0365461c0 95 pad.tone(0.0,0.1);
davidwst421 3:53f0365461c0 96 pad.tone(587.3,0.9);
davidwst421 3:53f0365461c0 97 pad.tone(0.0,0.1);
davidwst421 3:53f0365461c0 98 pad.tone(698.5,0.6);
davidwst421 3:53f0365461c0 99 pad.tone(659.3,0.3);
davidwst421 3:53f0365461c0 100 pad.tone(0.0,0.1);
davidwst421 3:53f0365461c0 101 pad.tone(659.3,0.6);
davidwst421 3:53f0365461c0 102 pad.tone(587.3,0.3);
davidwst421 3:53f0365461c0 103 pad.tone(0.0,0.1);
davidwst421 3:53f0365461c0 104 pad.tone(554.4,0.6);
davidwst421 3:53f0365461c0 105 pad.tone(587.3,0.3);
davidwst421 3:53f0365461c0 106 wait(0.1);
davidwst421 2:00a3edbe39b0 107 }
davidwst421 0:fd8eda608206 108 }