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@28:a38070a1cdcf, 2019-04-09 (annotated)
- Committer:
- el17arm
- Date:
- Tue Apr 09 21:03:49 2019 +0000
- Revision:
- 28:a38070a1cdcf
- Parent:
- 27:e73dd64ef334
reorganised differently (unfinished) returning to previous version but may return to this one still
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el17arm | 0:fe19852199d2 | 1 | #include "mbed.h" |
| el17arm | 0:fe19852199d2 | 2 | #include "N5110.h" |
| el17arm | 0:fe19852199d2 | 3 | #include "Gamepad.h" |
| el17arm | 28:a38070a1cdcf | 4 | #include "Gameengine.h" |
| el17arm | 27:e73dd64ef334 | 5 | #include "Levelobjects.h" |
| el17arm | 0:fe19852199d2 | 6 | |
| el17arm | 28:a38070a1cdcf | 7 | Levelobjects obj; |
| el17arm | 28:a38070a1cdcf | 8 | Gameengine game; |
| el17arm | 23:1ee8686af747 | 9 | Key _k; |
| el17arm | 0:fe19852199d2 | 10 | Gamepad pad; |
| el17arm | 0:fe19852199d2 | 11 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
| el17arm | 0:fe19852199d2 | 12 | AnalogIn pot0(PTB2); |
| el17arm | 0:fe19852199d2 | 13 | |
| el17arm | 0:fe19852199d2 | 14 | void contrast(); |
| el17arm | 0:fe19852199d2 | 15 | void init(); |
| el17arm | 0:fe19852199d2 | 16 | void start_screen(); |
| el17arm | 15:2bda80896a84 | 17 | void render(); |
| el17arm | 19:4789cb4ca550 | 18 | void restart(); |
| el17arm | 0:fe19852199d2 | 19 | |
| el17arm | 0:fe19852199d2 | 20 | int main() |
| el17arm | 0:fe19852199d2 | 21 | { |
| el17arm | 0:fe19852199d2 | 22 | init(); |
| el17arm | 2:725c213b2396 | 23 | start_screen(); |
| el17arm | 0:fe19852199d2 | 24 | |
| el17arm | 0:fe19852199d2 | 25 | while (1) { |
| el17arm | 19:4789cb4ca550 | 26 | |
| el17arm | 0:fe19852199d2 | 27 | contrast(); |
| el17arm | 15:2bda80896a84 | 28 | render(); |
| el17arm | 28:a38070a1cdcf | 29 | game.update(lcd, pad); |
| el17arm | 19:4789cb4ca550 | 30 | restart(); |
| el17arm | 9:f16581e1eba9 | 31 | wait(0.1); |
| el17arm | 0:fe19852199d2 | 32 | } |
| el17arm | 0:fe19852199d2 | 33 | |
| el17arm | 0:fe19852199d2 | 34 | } |
| el17arm | 0:fe19852199d2 | 35 | |
| el17arm | 0:fe19852199d2 | 36 | void init() |
| el17arm | 0:fe19852199d2 | 37 | { |
| el17arm | 0:fe19852199d2 | 38 | lcd.init(); |
| el17arm | 0:fe19852199d2 | 39 | lcd.normalMode(); // normal colour mode |
| el17arm | 0:fe19852199d2 | 40 | lcd.setBrightness(0.5); // put LED backlight on 50% |
| el17arm | 0:fe19852199d2 | 41 | lcd.refresh(); |
| el17arm | 0:fe19852199d2 | 42 | pad.init(); |
| el17arm | 0:fe19852199d2 | 43 | pad.leds_off(); |
| el17arm | 3:d27ee2440829 | 44 | contrast(); |
| el17arm | 28:a38070a1cdcf | 45 | game.game_init(); |
| el17arm | 15:2bda80896a84 | 46 | } |
| el17arm | 2:725c213b2396 | 47 | |
| el17arm | 15:2bda80896a84 | 48 | void render() |
| el17arm | 15:2bda80896a84 | 49 | { |
| el17arm | 28:a38070a1cdcf | 50 | game.draw(_k, lcd, pad); |
| el17arm | 0:fe19852199d2 | 51 | } |
| el17arm | 0:fe19852199d2 | 52 | |
| el17arm | 0:fe19852199d2 | 53 | void contrast() |
| el17arm | 0:fe19852199d2 | 54 | { |
| el17arm | 0:fe19852199d2 | 55 | lcd.refresh(); |
| el17arm | 0:fe19852199d2 | 56 | float con = pot0.read(); |
| el17arm | 0:fe19852199d2 | 57 | lcd.setContrast(con); |
| el17arm | 1:813ba5341985 | 58 | lcd.clear(); |
| el17arm | 0:fe19852199d2 | 59 | } |
| el17arm | 0:fe19852199d2 | 60 | |
| el17arm | 0:fe19852199d2 | 61 | void start_screen() |
| el17arm | 19:4789cb4ca550 | 62 | { |
| el17arm | 3:d27ee2440829 | 63 | lcd.printString("*MANIC MILNER!*",0,1); |
| el17arm | 3:d27ee2440829 | 64 | lcd.printString(" Press start! ",0,4); |
| el17arm | 3:d27ee2440829 | 65 | lcd.refresh(); |
| el17arm | 0:fe19852199d2 | 66 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
| el17arm | 0:fe19852199d2 | 67 | pad.leds_on(); |
| el17arm | 0:fe19852199d2 | 68 | wait(0.1); |
| el17arm | 0:fe19852199d2 | 69 | pad.leds_off(); |
| el17arm | 0:fe19852199d2 | 70 | wait(0.1); |
| el17arm | 0:fe19852199d2 | 71 | } |
| el17arm | 19:4789cb4ca550 | 72 | } |
| el17arm | 19:4789cb4ca550 | 73 | |
| el17arm | 19:4789cb4ca550 | 74 | void restart() |
| el17arm | 19:4789cb4ca550 | 75 | { |
| el17arm | 28:a38070a1cdcf | 76 | if (game.game_over() == true) { |
| el17arm | 19:4789cb4ca550 | 77 | lcd.clear(); |
| el17arm | 19:4789cb4ca550 | 78 | lcd.printString("Game Over! ",16,1); |
| el17arm | 19:4789cb4ca550 | 79 | lcd.printString("Press reset to try again! ",0,3); |
| el17arm | 19:4789cb4ca550 | 80 | lcd.printString("try again! ",16,4); |
| el17arm | 19:4789cb4ca550 | 81 | wait(1); |
| el17arm | 19:4789cb4ca550 | 82 | } |
| el17arm | 3:d27ee2440829 | 83 | } |