Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@11:0e6a221ad8a9, 2019-05-10 (annotated)
- Committer:
- batJoro
- Date:
- Fri May 10 13:58:51 2019 +0000
- Revision:
- 11:0e6a221ad8a9
- Parent:
- 10:b939edd9b87c
- Child:
- 12:bc9a43f56261
final 2;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| batJoro | 1:3183193cf44e | 1 | |
| batJoro | 0:a0dedca5e89f | 2 | |
| batJoro | 0:a0dedca5e89f | 3 | /* |
| batJoro | 0:a0dedca5e89f | 4 | ELEC2645 Embedded Systems Project |
| batJoro | 0:a0dedca5e89f | 5 | School of Electronic & Electrical Engineering University of Leeds |
| batJoro | 0:a0dedca5e89f | 6 | |
| batJoro | 0:a0dedca5e89f | 7 | Name: Dobri Tsvetkov |
| batJoro | 0:a0dedca5e89f | 8 | Username: el17dtt |
| batJoro | 0:a0dedca5e89f | 9 | Student ID Number: 201154059 |
| batJoro | 0:a0dedca5e89f | 10 | Date: 12.03.2019 |
| batJoro | 0:a0dedca5e89f | 11 | */ |
| batJoro | 0:a0dedca5e89f | 12 | |
| batJoro | 3:f686f6d7bdff | 13 | |
| batJoro | 5:5e92567d0a44 | 14 | #include "mbed.h" |
| batJoro | 5:5e92567d0a44 | 15 | #include "Gamepad.h" |
| batJoro | 5:5e92567d0a44 | 16 | #include "N5110.h" |
| batJoro | 5:5e92567d0a44 | 17 | #include "menu.h" |
| batJoro | 6:4c55dd4b6d42 | 18 | #include "engine.h" |
| batJoro | 6:4c55dd4b6d42 | 19 | |
| batJoro | 6:4c55dd4b6d42 | 20 | |
| batJoro | 5:5e92567d0a44 | 21 | |
| batJoro | 3:f686f6d7bdff | 22 | /////////////// structs ///////////////// |
| batJoro | 3:f686f6d7bdff | 23 | |
| batJoro | 3:f686f6d7bdff | 24 | |
| batJoro | 3:f686f6d7bdff | 25 | /////////////// objects /////////////// |
| batJoro | 3:f686f6d7bdff | 26 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
| batJoro | 1:3183193cf44e | 27 | Gamepad gamepad; |
| batJoro | 8:b3738229ba85 | 28 | Engine engine; |
| batJoro | 1:3183193cf44e | 29 | |
| batJoro | 3:f686f6d7bdff | 30 | ///////////// prototypes /////////////// |
| batJoro | 4:2deeeeb6c1e1 | 31 | void init(); |
| batJoro | 4:2deeeeb6c1e1 | 32 | void welcome(); |
| batJoro | 10:b939edd9b87c | 33 | void finish(); |
| batJoro | 6:4c55dd4b6d42 | 34 | void render(); |
| batJoro | 3:f686f6d7bdff | 35 | |
| batJoro | 3:f686f6d7bdff | 36 | ///////////// functions //////////////// |
| batJoro | 0:a0dedca5e89f | 37 | int main() { |
| batJoro | 0:a0dedca5e89f | 38 | |
| batJoro | 10:b939edd9b87c | 39 | int fps = 9; // frames per second |
| batJoro | 8:b3738229ba85 | 40 | |
| batJoro | 4:2deeeeb6c1e1 | 41 | init(); |
| batJoro | 1:3183193cf44e | 42 | |
| batJoro | 6:4c55dd4b6d42 | 43 | welcome(); |
| batJoro | 6:4c55dd4b6d42 | 44 | // game loop - read input, update the game state and render the display |
| batJoro | 6:4c55dd4b6d42 | 45 | while(1) { |
| batJoro | 10:b939edd9b87c | 46 | engine.read_input(gamepad, 1.0f/fps); |
| batJoro | 9:dc13042b09f5 | 47 | engine.update(gamepad, lcd, 1.0f/fps); |
| batJoro | 10:b939edd9b87c | 48 | if ( engine.get_lap() == 1) break; |
| batJoro | 6:4c55dd4b6d42 | 49 | render(); |
| batJoro | 8:b3738229ba85 | 50 | wait(1.0f/fps); |
| batJoro | 4:2deeeeb6c1e1 | 51 | } |
| batJoro | 10:b939edd9b87c | 52 | |
| batJoro | 10:b939edd9b87c | 53 | finish(); |
| batJoro | 4:2deeeeb6c1e1 | 54 | } |
| batJoro | 3:f686f6d7bdff | 55 | |
| batJoro | 8:b3738229ba85 | 56 | |
| batJoro | 4:2deeeeb6c1e1 | 57 | // initialies all classes and libraries |
| batJoro | 4:2deeeeb6c1e1 | 58 | void init() |
| batJoro | 4:2deeeeb6c1e1 | 59 | { |
| batJoro | 6:4c55dd4b6d42 | 60 | |
| batJoro | 8:b3738229ba85 | 61 | // need to initialise LCD and Gamepad and Engine |
| batJoro | 4:2deeeeb6c1e1 | 62 | lcd.init(); |
| batJoro | 4:2deeeeb6c1e1 | 63 | gamepad.init(); |
| batJoro | 8:b3738229ba85 | 64 | |
| batJoro | 8:b3738229ba85 | 65 | // init the engine and start the game at 0 speed |
| batJoro | 8:b3738229ba85 | 66 | engine.init(48 , 84, 0); |
| batJoro | 8:b3738229ba85 | 67 | |
| batJoro | 4:2deeeeb6c1e1 | 68 | gamepad.leds_on(); |
| batJoro | 4:2deeeeb6c1e1 | 69 | lcd.setContrast(0.4); |
| batJoro | 4:2deeeeb6c1e1 | 70 | } |
| batJoro | 6:4c55dd4b6d42 | 71 | // function to call the intro method of the menu class |
| batJoro | 4:2deeeeb6c1e1 | 72 | void welcome() { |
| batJoro | 4:2deeeeb6c1e1 | 73 | |
| batJoro | 4:2deeeeb6c1e1 | 74 | Menu menu; |
| batJoro | 11:0e6a221ad8a9 | 75 | //menu.intro(lcd, gamepad); |
| batJoro | 10:b939edd9b87c | 76 | menu.startMainMenu(lcd, gamepad); |
| batJoro | 10:b939edd9b87c | 77 | |
| batJoro | 10:b939edd9b87c | 78 | } |
| batJoro | 10:b939edd9b87c | 79 | // display lap time and finish |
| batJoro | 10:b939edd9b87c | 80 | void finish() { |
| batJoro | 10:b939edd9b87c | 81 | clearScreen(lcd); |
| batJoro | 10:b939edd9b87c | 82 | if(engine.get_lap_time() < 37) { |
| batJoro | 10:b939edd9b87c | 83 | printSoundString(lcd, gamepad, "Great job", 0, 0, 876, 0.1); |
| batJoro | 10:b939edd9b87c | 84 | printSoundString(lcd, gamepad, "lap time < 37s", 0, 1, 876, 0.1); |
| batJoro | 10:b939edd9b87c | 85 | printSoundString(lcd, gamepad, "The planet is ", 0, 2, 876, 0.1); |
| batJoro | 10:b939edd9b87c | 86 | printSoundString(lcd, gamepad, "safe", 0, 3, 876, 0.1); |
| batJoro | 10:b939edd9b87c | 87 | } |
| batJoro | 10:b939edd9b87c | 88 | if(engine.get_lap_time() > 37) { |
| batJoro | 10:b939edd9b87c | 89 | printSoundString(lcd, gamepad, "Game over", 0, 1, 876, 0.1); |
| batJoro | 10:b939edd9b87c | 90 | printSoundString(lcd, gamepad, "lap time > 37s", 0, 1, 876, 0.1); |
| batJoro | 10:b939edd9b87c | 91 | printSoundString(lcd, gamepad, "The delivery", 0, 2, 876, 0.1); |
| batJoro | 10:b939edd9b87c | 92 | printSoundString(lcd, gamepad, "failed and the ", 0, 3, 876, 0.1); |
| batJoro | 10:b939edd9b87c | 93 | printSoundString(lcd, gamepad, "planet will", 0, 4, 876, 0.1); |
| batJoro | 10:b939edd9b87c | 94 | printSoundString(lcd, gamepad, "be destroyed", 0, 5, 876, 0.1); |
| batJoro | 10:b939edd9b87c | 95 | } |
| batJoro | 10:b939edd9b87c | 96 | wait(60); |
| batJoro | 6:4c55dd4b6d42 | 97 | } |
| batJoro | 6:4c55dd4b6d42 | 98 | // this function draws each frame on the LCD |
| batJoro | 6:4c55dd4b6d42 | 99 | void render() { |
| batJoro | 6:4c55dd4b6d42 | 100 | |
| batJoro | 11:0e6a221ad8a9 | 101 | lcd.clear(); |
| batJoro | 11:0e6a221ad8a9 | 102 | engine.draw(lcd); |
| batJoro | 11:0e6a221ad8a9 | 103 | lcd.refresh(); |
| batJoro | 0:a0dedca5e89f | 104 | } |