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@24:67dc71a8f009, 2019-05-08 (annotated)
- Committer:
- el17m2h
- Date:
- Wed May 08 14:24:53 2019 +0000
- Revision:
- 24:67dc71a8f009
- Parent:
- 23:9be87557b89a
- Child:
- 26:d16a5b1e0ace
Added comments to the doodler h 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 | 23:9be87557b89a | 16 | #define FLOORS_WIDTH 14 |
el17m2h | 19:5a7b0cdf013b | 17 | #define FLOORS_HEIGHT 1 |
el17m2h | 5:8814d6de77d0 | 18 | |
el17m2h | 5:8814d6de77d0 | 19 | //structs |
el17m2h | 5:8814d6de77d0 | 20 | struct UserInput { |
el17m2h | 5:8814d6de77d0 | 21 | Direction d; |
el17m2h | 5:8814d6de77d0 | 22 | float mag; |
el17m2h | 5:8814d6de77d0 | 23 | }; |
el17m2h | 5:8814d6de77d0 | 24 | |
el17m2h | 1:0001cb3eb053 | 25 | // objects |
el17m2h | 1:0001cb3eb053 | 26 | 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 | 27 | Gamepad pad; |
el17m2h | 2:360a6c301a4e | 28 | Engine eng; |
el17m2h | 19:5a7b0cdf013b | 29 | Doodler dood; |
el17m2h | 20:a359092079b0 | 30 | Enemy eny; |
el17m2h | 1:0001cb3eb053 | 31 | |
el17m2h | 1:0001cb3eb053 | 32 | // prototypes |
el17m2h | 1:0001cb3eb053 | 33 | void init(); |
el17m2h | 5:8814d6de77d0 | 34 | void update_game(UserInput input); |
el17m2h | 5:8814d6de77d0 | 35 | void render(); |
el17m2h | 1:0001cb3eb053 | 36 | void welcome(); |
el17m2h | 19:5a7b0cdf013b | 37 | void game_over(); |
el17m2h | 1:0001cb3eb053 | 38 | |
el17m2h | 1:0001cb3eb053 | 39 | // functions |
el17m2h | 1:0001cb3eb053 | 40 | int main(){ |
el17m2h | 15:4efa04a6a376 | 41 | while(1){ |
el17m2h | 21:6b16ca9834e6 | 42 | init(); |
el17m2h | 15:4efa04a6a376 | 43 | welcome(); |
el17m2h | 19:5a7b0cdf013b | 44 | int fps = 8; |
el17m2h | 19:5a7b0cdf013b | 45 | render(); // draws |
el17m2h | 19:5a7b0cdf013b | 46 | wait(1.0f/fps); |
el17m2h | 19:5a7b0cdf013b | 47 | while(1){ |
el17m2h | 19:5a7b0cdf013b | 48 | eng.read_input(pad); |
el17m2h | 19:5a7b0cdf013b | 49 | eng.update(pad); |
el17m2h | 19:5a7b0cdf013b | 50 | render(); |
el17m2h | 19:5a7b0cdf013b | 51 | wait(0.8f/fps); |
el17m2h | 19:5a7b0cdf013b | 52 | if (pad.check_event(Gamepad::BACK_PRESSED) == true){ |
el17m2h | 19:5a7b0cdf013b | 53 | break; |
el17m2h | 19:5a7b0cdf013b | 54 | } |
el17m2h | 19:5a7b0cdf013b | 55 | } |
el17m2h | 15:4efa04a6a376 | 56 | render(); |
el17m2h | 15:4efa04a6a376 | 57 | wait(0.1); |
el17m2h | 1:0001cb3eb053 | 58 | } |
el17m2h | 1:0001cb3eb053 | 59 | } |
el17m2h | 1:0001cb3eb053 | 60 | |
el17m2h | 1:0001cb3eb053 | 61 | // initialies all classes and libraries |
el17m2h | 1:0001cb3eb053 | 62 | void init(){ |
el17m2h | 1:0001cb3eb053 | 63 | // need to initialise LCD and Gamepad |
el17m2h | 1:0001cb3eb053 | 64 | lcd.init(); |
el17m2h | 23:9be87557b89a | 65 | lcd.setBrightness(1); |
el17m2h | 24:67dc71a8f009 | 66 | lcd.setContrast(0.5), |
el17m2h | 1:0001cb3eb053 | 67 | pad.init(); |
el17m2h | 23:9be87557b89a | 68 | eng.init(FLOORS_WIDTH, FLOORS_HEIGHT); |
el17m2h | 1:0001cb3eb053 | 69 | } |
el17m2h | 1:0001cb3eb053 | 70 | |
el17m2h | 5:8814d6de77d0 | 71 | void render(){ |
el17m2h | 5:8814d6de77d0 | 72 | lcd.clear(); |
el17m2h | 5:8814d6de77d0 | 73 | eng.draw(lcd); |
el17m2h | 5:8814d6de77d0 | 74 | lcd.refresh(); |
el17m2h | 5:8814d6de77d0 | 75 | } |
el17m2h | 5:8814d6de77d0 | 76 | |
el17m2h | 1:0001cb3eb053 | 77 | // Starting menu screen display |
el17m2h | 1:0001cb3eb053 | 78 | void welcome() { |
el17m2h | 1:0001cb3eb053 | 79 | lcd.printString(" Doodle Jump! ",0,1); |
el17m2h | 1:0001cb3eb053 | 80 | lcd.printString(" Press Start ",0,4); |
el17m2h | 1:0001cb3eb053 | 81 | lcd.refresh(); |
el17m2h | 5:8814d6de77d0 | 82 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
el17m2h | 5:8814d6de77d0 | 83 | pad.leds_on(); |
el17m2h | 5:8814d6de77d0 | 84 | wait(0.1); |
el17m2h | 5:8814d6de77d0 | 85 | pad.leds_off(); |
el17m2h | 5:8814d6de77d0 | 86 | wait(0.1); |
el17m2h | 5:8814d6de77d0 | 87 | } |
el17m2h | 19:5a7b0cdf013b | 88 | } |
el17m2h | 19:5a7b0cdf013b | 89 | |
el17m2h | 19:5a7b0cdf013b | 90 | void game_over() { |
el17m2h | 19:5a7b0cdf013b | 91 | lcd.clear(); |
el17m2h | 21:6b16ca9834e6 | 92 | lcd.printString("Game Over!",3,1); |
el17m2h | 21:6b16ca9834e6 | 93 | lcd.printString("Press back",3,3); |
el17m2h | 21:6b16ca9834e6 | 94 | lcd.printString("SCORE = ",3,5); |
el17m2h | 19:5a7b0cdf013b | 95 | lcd.refresh(); |
el17m2h | 21:6b16ca9834e6 | 96 | while ( pad.check_event(Gamepad::BACK_PRESSED) == false) { |
el17m2h | 19:5a7b0cdf013b | 97 | pad.leds_on(); |
el17m2h | 19:5a7b0cdf013b | 98 | wait(0.1); |
el17m2h | 19:5a7b0cdf013b | 99 | pad.leds_off(); |
el17m2h | 19:5a7b0cdf013b | 100 | wait(0.1); |
el17m2h | 15:4efa04a6a376 | 101 | } |
el17m2h | 15:4efa04a6a376 | 102 | } |