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@5:1a9d84df7207, 2019-05-04 (annotated)
- Committer:
- el17cr
- Date:
- Sat May 04 10:49:53 2019 +0000
- Revision:
- 5:1a9d84df7207
- Parent:
- 4:03d13a53308c
- Child:
- 6:85314a3d69cd
Ground movement added, ground objects created and collisions updated
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el17cr | 0:adb2f501dd61 | 1 | /* |
| el17cr | 0:adb2f501dd61 | 2 | ELEC2645 Embedded Systems Project |
| el17cr | 0:adb2f501dd61 | 3 | School of Electronic & Electrical Engineering |
| el17cr | 0:adb2f501dd61 | 4 | University of Leeds |
| el17cr | 0:adb2f501dd61 | 5 | Name: |
| el17cr | 0:adb2f501dd61 | 6 | Username: |
| el17cr | 0:adb2f501dd61 | 7 | Student ID Number: |
| el17cr | 0:adb2f501dd61 | 8 | Date: |
| el17cr | 0:adb2f501dd61 | 9 | */ |
| el17cr | 2:7f91a86b4dc0 | 10 | |
| el17cr | 2:7f91a86b4dc0 | 11 | #include "mbed.h" |
| el17cr | 2:7f91a86b4dc0 | 12 | #include "Gamepad.h" |
| el17cr | 2:7f91a86b4dc0 | 13 | #include "N5110.h" |
| el17cr | 2:7f91a86b4dc0 | 14 | #include "Falldown.h" |
| el17cr | 2:7f91a86b4dc0 | 15 | |
| el17cr | 3:5edefa83f8f0 | 16 | //#define GROUND_WIDTH 70 |
| el17cr | 2:7f91a86b4dc0 | 17 | #define GROUND_HEIGHT 2 |
| el17cr | 5:1a9d84df7207 | 18 | #define GROUND_WIDTH 50 |
| el17cr | 3:5edefa83f8f0 | 19 | #define BALL_SIZE 3 |
| el17cr | 5:1a9d84df7207 | 20 | #define LINE_HEIGHT 1 |
| el17cr | 5:1a9d84df7207 | 21 | #define LINE_WIDTH WIDTH |
| el17cr | 3:5edefa83f8f0 | 22 | |
| el17cr | 2:7f91a86b4dc0 | 23 | |
| el17cr | 2:7f91a86b4dc0 | 24 | |
| el17cr | 2:7f91a86b4dc0 | 25 | |
| el17cr | 2:7f91a86b4dc0 | 26 | struct UserInput { |
| el17cr | 2:7f91a86b4dc0 | 27 | Direction d; |
| el17cr | 2:7f91a86b4dc0 | 28 | float mag; |
| el17cr | 2:7f91a86b4dc0 | 29 | }; |
| el17cr | 2:7f91a86b4dc0 | 30 | |
| el17cr | 2:7f91a86b4dc0 | 31 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // K64F - pwr from 3V3 |
| el17cr | 2:7f91a86b4dc0 | 32 | Gamepad pad; |
| el17cr | 2:7f91a86b4dc0 | 33 | Falldown falldown; |
| el17cr | 2:7f91a86b4dc0 | 34 | |
| el17cr | 2:7f91a86b4dc0 | 35 | void init(); |
| el17cr | 2:7f91a86b4dc0 | 36 | void update_game(UserInput input); |
| el17cr | 2:7f91a86b4dc0 | 37 | void render(); |
| el17cr | 2:7f91a86b4dc0 | 38 | |
| el17cr | 5:1a9d84df7207 | 39 | |
| el17cr | 2:7f91a86b4dc0 | 40 | int main() |
| el17cr | 2:7f91a86b4dc0 | 41 | { |
| el17cr | 2:7f91a86b4dc0 | 42 | init(); |
| el17cr | 2:7f91a86b4dc0 | 43 | render(); |
| el17cr | 2:7f91a86b4dc0 | 44 | wait(0.1); |
| el17cr | 2:7f91a86b4dc0 | 45 | while (1) { |
| el17cr | 2:7f91a86b4dc0 | 46 | falldown.read_input(pad); |
| el17cr | 2:7f91a86b4dc0 | 47 | falldown.update(pad); |
| el17cr | 2:7f91a86b4dc0 | 48 | render(); |
| el17cr | 2:7f91a86b4dc0 | 49 | wait(0.1); |
| el17cr | 5:1a9d84df7207 | 50 | if (falldown.check_goal() == 1) { |
| el17cr | 5:1a9d84df7207 | 51 | //falldown.read_input(pad); |
| el17cr | 5:1a9d84df7207 | 52 | //falldown.update(pad); |
| el17cr | 5:1a9d84df7207 | 53 | //render(); |
| el17cr | 5:1a9d84df7207 | 54 | falldown.init(GROUND_HEIGHT,BALL_SIZE,LINE_HEIGHT,LINE_WIDTH); |
| el17cr | 5:1a9d84df7207 | 55 | wait(0.1); |
| el17cr | 5:1a9d84df7207 | 56 | //clear lines |
| el17cr | 5:1a9d84df7207 | 57 | //redraw lines |
| el17cr | 5:1a9d84df7207 | 58 | } |
| el17cr | 2:7f91a86b4dc0 | 59 | } |
| el17cr | 5:1a9d84df7207 | 60 | /*while (falldown.check_goal == 1) { |
| el17cr | 5:1a9d84df7207 | 61 | |
| el17cr | 5:1a9d84df7207 | 62 | falldown.init(GROUND_HEIGHT,BALL_SIZE); |
| el17cr | 5:1a9d84df7207 | 63 | wait(0.1);*/ |
| el17cr | 5:1a9d84df7207 | 64 | } |
| el17cr | 5:1a9d84df7207 | 65 | |
| el17cr | 2:7f91a86b4dc0 | 66 | |
| el17cr | 2:7f91a86b4dc0 | 67 | void init() |
| el17cr | 2:7f91a86b4dc0 | 68 | { |
| el17cr | 2:7f91a86b4dc0 | 69 | lcd.init(); |
| el17cr | 2:7f91a86b4dc0 | 70 | pad.init(); |
| el17cr | 5:1a9d84df7207 | 71 | |
| el17cr | 5:1a9d84df7207 | 72 | falldown.init(GROUND_HEIGHT,BALL_SIZE,LINE_HEIGHT,LINE_WIDTH); |
| el17cr | 2:7f91a86b4dc0 | 73 | } |
| el17cr | 2:7f91a86b4dc0 | 74 | |
| el17cr | 2:7f91a86b4dc0 | 75 | void render() |
| el17cr | 2:7f91a86b4dc0 | 76 | { |
| el17cr | 5:1a9d84df7207 | 77 | |
| el17cr | 4:03d13a53308c | 78 | lcd.clear(); |
| el17cr | 2:7f91a86b4dc0 | 79 | falldown.draw(lcd); |
| el17cr | 2:7f91a86b4dc0 | 80 | lcd.refresh(); |
| el17cr | 5:1a9d84df7207 | 81 | |
| el17cr | 4:03d13a53308c | 82 | } |