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@26:d16a5b1e0ace, 2019-05-08 (annotated)
- Committer:
- el17m2h
- Date:
- Wed May 08 17:24:35 2019 +0000
- Revision:
- 26:d16a5b1e0ace
- Parent:
- 24:67dc71a8f009
- Child:
- 27:af14fcd5a520
Added comments for the documentation file.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17m2h | 24:67dc71a8f009 | 1 | /* |
el17m2h | 24:67dc71a8f009 | 2 | ELEC2645 Embedded Systems Project |
el17m2h | 24:67dc71a8f009 | 3 | School of Electronic & Electrical Engineering |
el17m2h | 24:67dc71a8f009 | 4 | University of Leeds |
el17m2h | 24:67dc71a8f009 | 5 | Name: Melissa Hartmann |
el17m2h | 24:67dc71a8f009 | 6 | Username: el17m2h |
el17m2h | 24:67dc71a8f009 | 7 | Student ID Number: 201176603 |
el17m2h | 24:67dc71a8f009 | 8 | Date: 09/05/2019 |
el17m2h | 24:67dc71a8f009 | 9 | */ |
el17m2h | 24:67dc71a8f009 | 10 | |
el17m2h | 1:0001cb3eb053 | 11 | #include "mbed.h" |
el17m2h | 1:0001cb3eb053 | 12 | #include "Gamepad.h" |
el17m2h | 1:0001cb3eb053 | 13 | #include "N5110.h" |
el17m2h | 2:360a6c301a4e | 14 | #include "Engine.h" |
el17m2h | 1:0001cb3eb053 | 15 | |
el17m2h | 5:8814d6de77d0 | 16 | //structs |
el17m2h | 5:8814d6de77d0 | 17 | struct UserInput { |
el17m2h | 5:8814d6de77d0 | 18 | Direction d; |
el17m2h | 5:8814d6de77d0 | 19 | float mag; |
el17m2h | 5:8814d6de77d0 | 20 | }; |
el17m2h | 5:8814d6de77d0 | 21 | |
el17m2h | 1:0001cb3eb053 | 22 | // objects |
el17m2h | 1:0001cb3eb053 | 23 | N5110 lcd(PTC5,PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // START, LCD SCE, LCD RST, LCD DC, LCD MOSI, LCD CLK, LCD Backlight |
el17m2h | 1:0001cb3eb053 | 24 | Gamepad pad; |
el17m2h | 2:360a6c301a4e | 25 | Engine eng; |
el17m2h | 19:5a7b0cdf013b | 26 | Doodler dood; |
el17m2h | 20:a359092079b0 | 27 | Enemy eny; |
el17m2h | 1:0001cb3eb053 | 28 | |
el17m2h | 1:0001cb3eb053 | 29 | // prototypes |
el17m2h | 1:0001cb3eb053 | 30 | void init(); |
el17m2h | 5:8814d6de77d0 | 31 | void update_game(UserInput input); |
el17m2h | 5:8814d6de77d0 | 32 | void render(); |
el17m2h | 1:0001cb3eb053 | 33 | void welcome(); |
el17m2h | 19:5a7b0cdf013b | 34 | void game_over(); |
el17m2h | 1:0001cb3eb053 | 35 | |
el17m2h | 1:0001cb3eb053 | 36 | // functions |
el17m2h | 1:0001cb3eb053 | 37 | int main(){ |
el17m2h | 15:4efa04a6a376 | 38 | while(1){ |
el17m2h | 21:6b16ca9834e6 | 39 | init(); |
el17m2h | 15:4efa04a6a376 | 40 | welcome(); |
el17m2h | 19:5a7b0cdf013b | 41 | int fps = 8; |
el17m2h | 19:5a7b0cdf013b | 42 | render(); // draws |
el17m2h | 19:5a7b0cdf013b | 43 | wait(1.0f/fps); |
el17m2h | 19:5a7b0cdf013b | 44 | while(1){ |
el17m2h | 19:5a7b0cdf013b | 45 | eng.read_input(pad); |
el17m2h | 19:5a7b0cdf013b | 46 | eng.update(pad); |
el17m2h | 19:5a7b0cdf013b | 47 | render(); |
el17m2h | 19:5a7b0cdf013b | 48 | wait(0.8f/fps); |
el17m2h | 19:5a7b0cdf013b | 49 | if (pad.check_event(Gamepad::BACK_PRESSED) == true){ |
el17m2h | 19:5a7b0cdf013b | 50 | break; |
el17m2h | 19:5a7b0cdf013b | 51 | } |
el17m2h | 19:5a7b0cdf013b | 52 | } |
el17m2h | 15:4efa04a6a376 | 53 | render(); |
el17m2h | 15:4efa04a6a376 | 54 | wait(0.1); |
el17m2h | 1:0001cb3eb053 | 55 | } |
el17m2h | 1:0001cb3eb053 | 56 | } |
el17m2h | 1:0001cb3eb053 | 57 | |
el17m2h | 1:0001cb3eb053 | 58 | // initialies all classes and libraries |
el17m2h | 1:0001cb3eb053 | 59 | void init(){ |
el17m2h | 1:0001cb3eb053 | 60 | // need to initialise LCD and Gamepad |
el17m2h | 1:0001cb3eb053 | 61 | lcd.init(); |
el17m2h | 23:9be87557b89a | 62 | lcd.setBrightness(1); |
el17m2h | 24:67dc71a8f009 | 63 | lcd.setContrast(0.5), |
el17m2h | 1:0001cb3eb053 | 64 | pad.init(); |
el17m2h | 26:d16a5b1e0ace | 65 | eng.init(); |
el17m2h | 1:0001cb3eb053 | 66 | } |
el17m2h | 1:0001cb3eb053 | 67 | |
el17m2h | 5:8814d6de77d0 | 68 | void render(){ |
el17m2h | 5:8814d6de77d0 | 69 | lcd.clear(); |
el17m2h | 5:8814d6de77d0 | 70 | eng.draw(lcd); |
el17m2h | 5:8814d6de77d0 | 71 | lcd.refresh(); |
el17m2h | 5:8814d6de77d0 | 72 | } |
el17m2h | 5:8814d6de77d0 | 73 | |
el17m2h | 1:0001cb3eb053 | 74 | // Starting menu screen display |
el17m2h | 1:0001cb3eb053 | 75 | void welcome() { |
el17m2h | 1:0001cb3eb053 | 76 | lcd.printString(" Doodle Jump! ",0,1); |
el17m2h | 1:0001cb3eb053 | 77 | lcd.printString(" Press Start ",0,4); |
el17m2h | 1:0001cb3eb053 | 78 | lcd.refresh(); |
el17m2h | 5:8814d6de77d0 | 79 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
el17m2h | 5:8814d6de77d0 | 80 | pad.leds_on(); |
el17m2h | 5:8814d6de77d0 | 81 | wait(0.1); |
el17m2h | 5:8814d6de77d0 | 82 | pad.leds_off(); |
el17m2h | 5:8814d6de77d0 | 83 | wait(0.1); |
el17m2h | 5:8814d6de77d0 | 84 | } |
el17m2h | 19:5a7b0cdf013b | 85 | } |
el17m2h | 19:5a7b0cdf013b | 86 | |
el17m2h | 19:5a7b0cdf013b | 87 | void game_over() { |
el17m2h | 19:5a7b0cdf013b | 88 | lcd.clear(); |
el17m2h | 21:6b16ca9834e6 | 89 | lcd.printString("Game Over!",3,1); |
el17m2h | 21:6b16ca9834e6 | 90 | lcd.printString("Press back",3,3); |
el17m2h | 21:6b16ca9834e6 | 91 | lcd.printString("SCORE = ",3,5); |
el17m2h | 19:5a7b0cdf013b | 92 | lcd.refresh(); |
el17m2h | 21:6b16ca9834e6 | 93 | while ( pad.check_event(Gamepad::BACK_PRESSED) == false) { |
el17m2h | 19:5a7b0cdf013b | 94 | pad.leds_on(); |
el17m2h | 19:5a7b0cdf013b | 95 | wait(0.1); |
el17m2h | 19:5a7b0cdf013b | 96 | pad.leds_off(); |
el17m2h | 19:5a7b0cdf013b | 97 | wait(0.1); |
el17m2h | 15:4efa04a6a376 | 98 | } |
el17m2h | 15:4efa04a6a376 | 99 | } |