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@20:a359092079b0, 2019-04-25 (annotated)
- Committer:
- el17m2h
- Date:
- Thu Apr 25 11:34:01 2019 +0000
- Revision:
- 20:a359092079b0
- Parent:
- 19:5a7b0cdf013b
- Child:
- 21:6b16ca9834e6
I added a rectangle for the screen, updated the screen range and removed a floor. Added a tone for when the bullet is shot. Also added an enemy file that in contact with doodler the game ends. It also disappears if shot by bullet.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17m2h | 5:8814d6de77d0 | 1 | /* |
el17m2h | 5:8814d6de77d0 | 2 | ELEC2645 Embedded Systems Project |
el17m2h | 5:8814d6de77d0 | 3 | School of Electronic & Electrical Engineering |
el17m2h | 5:8814d6de77d0 | 4 | University of Leeds |
el17m2h | 5:8814d6de77d0 | 5 | Name: Melissa Hartmann |
el17m2h | 5:8814d6de77d0 | 6 | Username: el17m2h |
el17m2h | 5:8814d6de77d0 | 7 | Student ID Number: 201176603 |
el17m2h | 5:8814d6de77d0 | 8 | Date: 11/04/2019 |
el17m2h | 5:8814d6de77d0 | 9 | */ |
el17m2h | 5:8814d6de77d0 | 10 | |
el17m2h | 5:8814d6de77d0 | 11 | |
el17m2h | 1:0001cb3eb053 | 12 | #include "mbed.h" |
el17m2h | 1:0001cb3eb053 | 13 | #include "Gamepad.h" |
el17m2h | 1:0001cb3eb053 | 14 | #include "N5110.h" |
el17m2h | 2:360a6c301a4e | 15 | #include "Engine.h" |
el17m2h | 1:0001cb3eb053 | 16 | |
el17m2h | 19:5a7b0cdf013b | 17 | #define FLOORS_WIDTH 12 |
el17m2h | 19:5a7b0cdf013b | 18 | #define FLOORS_HEIGHT 1 |
el17m2h | 5:8814d6de77d0 | 19 | #define DOODLER_RADIUS 2 |
el17m2h | 5:8814d6de77d0 | 20 | |
el17m2h | 5:8814d6de77d0 | 21 | //structs |
el17m2h | 5:8814d6de77d0 | 22 | struct UserInput { |
el17m2h | 5:8814d6de77d0 | 23 | Direction d; |
el17m2h | 5:8814d6de77d0 | 24 | float mag; |
el17m2h | 5:8814d6de77d0 | 25 | }; |
el17m2h | 5:8814d6de77d0 | 26 | |
el17m2h | 1:0001cb3eb053 | 27 | |
el17m2h | 1:0001cb3eb053 | 28 | // objects |
el17m2h | 1:0001cb3eb053 | 29 | 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 | 30 | Gamepad pad; |
el17m2h | 2:360a6c301a4e | 31 | Engine eng; |
el17m2h | 19:5a7b0cdf013b | 32 | Doodler dood; |
el17m2h | 20:a359092079b0 | 33 | Enemy eny; |
el17m2h | 1:0001cb3eb053 | 34 | |
el17m2h | 1:0001cb3eb053 | 35 | // prototypes |
el17m2h | 1:0001cb3eb053 | 36 | void init(); |
el17m2h | 5:8814d6de77d0 | 37 | void update_game(UserInput input); |
el17m2h | 5:8814d6de77d0 | 38 | void render(); |
el17m2h | 1:0001cb3eb053 | 39 | void welcome(); |
el17m2h | 19:5a7b0cdf013b | 40 | void game_over(); |
el17m2h | 1:0001cb3eb053 | 41 | |
el17m2h | 1:0001cb3eb053 | 42 | // functions |
el17m2h | 1:0001cb3eb053 | 43 | int main(){ |
el17m2h | 15:4efa04a6a376 | 44 | while(1){ |
el17m2h | 15:4efa04a6a376 | 45 | init(); // initialise and then display welcome screen... |
el17m2h | 15:4efa04a6a376 | 46 | welcome(); |
el17m2h | 19:5a7b0cdf013b | 47 | int fps = 8; |
el17m2h | 19:5a7b0cdf013b | 48 | render(); // draws |
el17m2h | 19:5a7b0cdf013b | 49 | wait(1.0f/fps); |
el17m2h | 19:5a7b0cdf013b | 50 | while(1){ |
el17m2h | 19:5a7b0cdf013b | 51 | eng.read_input(pad); |
el17m2h | 19:5a7b0cdf013b | 52 | eng.update(pad); |
el17m2h | 19:5a7b0cdf013b | 53 | render(); |
el17m2h | 19:5a7b0cdf013b | 54 | wait(0.8f/fps); |
el17m2h | 19:5a7b0cdf013b | 55 | if (pad.check_event(Gamepad::BACK_PRESSED) == true){ |
el17m2h | 19:5a7b0cdf013b | 56 | break; |
el17m2h | 20:a359092079b0 | 57 | } |
el17m2h | 20:a359092079b0 | 58 | Vector2D eny_pos = eny.get_position(); |
el17m2h | 20:a359092079b0 | 59 | if ( |
el17m2h | 20:a359092079b0 | 60 | (dood.get_position_y() > 48) || |
el17m2h | 20:a359092079b0 | 61 | ((eny_pos.y < dood.get_position_y() < eny_pos.y + 6) && (eny_pos.x< dood.get_position_y()< eny_pos.x + 6)) |
el17m2h | 20:a359092079b0 | 62 | ){ |
el17m2h | 19:5a7b0cdf013b | 63 | while(1){ |
el17m2h | 19:5a7b0cdf013b | 64 | game_over(); |
el17m2h | 19:5a7b0cdf013b | 65 | if (pad.check_event(Gamepad::START_PRESSED) == true){ |
el17m2h | 19:5a7b0cdf013b | 66 | break; |
el17m2h | 19:5a7b0cdf013b | 67 | } |
el17m2h | 19:5a7b0cdf013b | 68 | } |
el17m2h | 20:a359092079b0 | 69 | break; |
el17m2h | 19:5a7b0cdf013b | 70 | } |
el17m2h | 19:5a7b0cdf013b | 71 | } |
el17m2h | 15:4efa04a6a376 | 72 | render(); |
el17m2h | 15:4efa04a6a376 | 73 | wait(0.1); |
el17m2h | 1:0001cb3eb053 | 74 | } |
el17m2h | 1:0001cb3eb053 | 75 | } |
el17m2h | 1:0001cb3eb053 | 76 | |
el17m2h | 19:5a7b0cdf013b | 77 | |
el17m2h | 1:0001cb3eb053 | 78 | // initialies all classes and libraries |
el17m2h | 1:0001cb3eb053 | 79 | void init(){ |
el17m2h | 1:0001cb3eb053 | 80 | // need to initialise LCD and Gamepad |
el17m2h | 1:0001cb3eb053 | 81 | lcd.init(); |
el17m2h | 1:0001cb3eb053 | 82 | pad.init(); |
el17m2h | 4:8ec314f806ae | 83 | eng.init(FLOORS_WIDTH, FLOORS_HEIGHT, DOODLER_RADIUS); |
el17m2h | 1:0001cb3eb053 | 84 | } |
el17m2h | 1:0001cb3eb053 | 85 | |
el17m2h | 5:8814d6de77d0 | 86 | void render(){ |
el17m2h | 5:8814d6de77d0 | 87 | lcd.clear(); |
el17m2h | 5:8814d6de77d0 | 88 | eng.draw(lcd); |
el17m2h | 5:8814d6de77d0 | 89 | lcd.refresh(); |
el17m2h | 5:8814d6de77d0 | 90 | } |
el17m2h | 5:8814d6de77d0 | 91 | |
el17m2h | 1:0001cb3eb053 | 92 | // Starting menu screen display |
el17m2h | 1:0001cb3eb053 | 93 | void welcome() { |
el17m2h | 1:0001cb3eb053 | 94 | lcd.printString(" Doodle Jump! ",0,1); |
el17m2h | 1:0001cb3eb053 | 95 | lcd.printString(" Press Start ",0,4); |
el17m2h | 1:0001cb3eb053 | 96 | lcd.refresh(); |
el17m2h | 5:8814d6de77d0 | 97 | |
el17m2h | 5:8814d6de77d0 | 98 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
el17m2h | 5:8814d6de77d0 | 99 | pad.leds_on(); |
el17m2h | 5:8814d6de77d0 | 100 | wait(0.1); |
el17m2h | 5:8814d6de77d0 | 101 | pad.leds_off(); |
el17m2h | 5:8814d6de77d0 | 102 | wait(0.1); |
el17m2h | 5:8814d6de77d0 | 103 | } |
el17m2h | 19:5a7b0cdf013b | 104 | } |
el17m2h | 19:5a7b0cdf013b | 105 | |
el17m2h | 19:5a7b0cdf013b | 106 | void game_over() { |
el17m2h | 19:5a7b0cdf013b | 107 | lcd.clear(); |
el17m2h | 19:5a7b0cdf013b | 108 | lcd.printString("Game Over! Press back",0,1); |
el17m2h | 19:5a7b0cdf013b | 109 | lcd.printString(" SCORE = ",0,4); |
el17m2h | 19:5a7b0cdf013b | 110 | lcd.refresh(); |
el17m2h | 19:5a7b0cdf013b | 111 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
el17m2h | 19:5a7b0cdf013b | 112 | pad.leds_on(); |
el17m2h | 19:5a7b0cdf013b | 113 | wait(0.1); |
el17m2h | 19:5a7b0cdf013b | 114 | pad.leds_off(); |
el17m2h | 19:5a7b0cdf013b | 115 | wait(0.1); |
el17m2h | 15:4efa04a6a376 | 116 | } |
el17m2h | 15:4efa04a6a376 | 117 | } |