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@8:c3cf8d1057bb, 2017-05-03 (annotated)
- Committer:
- el15as
- Date:
- Wed May 03 14:25:55 2017 +0000
- Revision:
- 8:c3cf8d1057bb
- Parent:
- 7:b54323241435
- Child:
- 9:35f992fd407b
Menu added with its own separate engine
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el15as | 0:9aa78a94ec93 | 1 | #include "mbed.h" |
| el15as | 0:9aa78a94ec93 | 2 | #include "N5110.h" |
| el15as | 0:9aa78a94ec93 | 3 | #include "Gamepad.h" |
| el15as | 2:8c5c47b2372d | 4 | #include "GameEngine.h" |
| el15as | 8:c3cf8d1057bb | 5 | #include "MenuEngine.h" |
| el15as | 0:9aa78a94ec93 | 6 | |
| el15as | 0:9aa78a94ec93 | 7 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
| el15as | 1:5e5791293388 | 8 | Serial pc(USBTX, USBRX); // tx, rx |
| el15as | 0:9aa78a94ec93 | 9 | Gamepad pad; |
| el15as | 2:8c5c47b2372d | 10 | GameEngine game; |
| el15as | 8:c3cf8d1057bb | 11 | MenuEngine menu; |
| el15as | 0:9aa78a94ec93 | 12 | |
| el15as | 1:5e5791293388 | 13 | void update_screen(); |
| el15as | 8:c3cf8d1057bb | 14 | void welcome(); |
| el15as | 8:c3cf8d1057bb | 15 | |
| el15as | 8:c3cf8d1057bb | 16 | bool showStart = true; |
| el15as | 0:9aa78a94ec93 | 17 | |
| el15as | 0:9aa78a94ec93 | 18 | int main() |
| el15as | 0:9aa78a94ec93 | 19 | { |
| el15as | 0:9aa78a94ec93 | 20 | lcd.init(); |
| el15as | 1:5e5791293388 | 21 | pad.init(); |
| el15as | 2:8c5c47b2372d | 22 | |
| el15as | 1:5e5791293388 | 23 | lcd.normalMode(); |
| el15as | 1:5e5791293388 | 24 | lcd.setBrightness(1); |
| el15as | 0:9aa78a94ec93 | 25 | |
| el15as | 8:c3cf8d1057bb | 26 | while (!pad.check_event(Gamepad::START_PRESSED)) { |
| el15as | 8:c3cf8d1057bb | 27 | welcome(); |
| el15as | 8:c3cf8d1057bb | 28 | } |
| el15as | 3:e05d4de7690b | 29 | |
| el15as | 8:c3cf8d1057bb | 30 | while(1) |
| el15as | 8:c3cf8d1057bb | 31 | { |
| el15as | 8:c3cf8d1057bb | 32 | menu.init(); |
| el15as | 8:c3cf8d1057bb | 33 | while (!menu.gameStarted) |
| el15as | 8:c3cf8d1057bb | 34 | { |
| el15as | 8:c3cf8d1057bb | 35 | menu.read_input(pad, pc); |
| el15as | 8:c3cf8d1057bb | 36 | menu.update(pad, pc, lcd); |
| el15as | 8:c3cf8d1057bb | 37 | menu.draw(lcd,pc); |
| el15as | 8:c3cf8d1057bb | 38 | menu.check_finish(pad, lcd, pc); |
| el15as | 8:c3cf8d1057bb | 39 | wait(1.0f/10); |
| el15as | 8:c3cf8d1057bb | 40 | } |
| el15as | 8:c3cf8d1057bb | 41 | game.init(menu.selectedLevel, menu.soundIsOn, pad); |
| el15as | 8:c3cf8d1057bb | 42 | while (game.isActive) |
| el15as | 8:c3cf8d1057bb | 43 | { |
| el15as | 8:c3cf8d1057bb | 44 | game.read_input(pad,pc); |
| el15as | 8:c3cf8d1057bb | 45 | game.update(pad, pc, lcd); |
| el15as | 8:c3cf8d1057bb | 46 | game.draw(lcd); |
| el15as | 8:c3cf8d1057bb | 47 | game.check_finish(pad, lcd); |
| el15as | 8:c3cf8d1057bb | 48 | wait(1.0f/10); // 10 fps |
| el15as | 8:c3cf8d1057bb | 49 | } |
| el15as | 8:c3cf8d1057bb | 50 | } |
| el15as | 8:c3cf8d1057bb | 51 | } |
| el15as | 2:8c5c47b2372d | 52 | |
| el15as | 8:c3cf8d1057bb | 53 | void welcome() |
| el15as | 8:c3cf8d1057bb | 54 | { |
| el15as | 8:c3cf8d1057bb | 55 | lcd.clear(); |
| el15as | 8:c3cf8d1057bb | 56 | lcd.printString("Escape", 5, 0); |
| el15as | 8:c3cf8d1057bb | 57 | lcd.printString("is", 30, 1); |
| el15as | 8:c3cf8d1057bb | 58 | lcd.printString("an", 35, 2); |
| el15as | 8:c3cf8d1057bb | 59 | lcd.printString("Ellusion", 30, 3); |
| el15as | 8:c3cf8d1057bb | 60 | if (showStart) |
| el15as | 8:c3cf8d1057bb | 61 | { |
| el15as | 8:c3cf8d1057bb | 62 | lcd.printString("Press START", 10, 5); |
| el15as | 8:c3cf8d1057bb | 63 | showStart = false; |
| el15as | 0:9aa78a94ec93 | 64 | } |
| el15as | 8:c3cf8d1057bb | 65 | else |
| el15as | 8:c3cf8d1057bb | 66 | { |
| el15as | 8:c3cf8d1057bb | 67 | showStart = true; |
| el15as | 8:c3cf8d1057bb | 68 | } |
| el15as | 8:c3cf8d1057bb | 69 | lcd.refresh(); |
| el15as | 8:c3cf8d1057bb | 70 | wait(0.5); |
| el15as | 3:e05d4de7690b | 71 | } |