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