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@18:e58a1f8e72ad, 2018-05-08 (annotated)
- Committer:
- weiway
- Date:
- Tue May 08 12:38:36 2018 +0000
- Revision:
- 18:e58a1f8e72ad
- Parent:
- 15:47ea86f1ed70
- Child:
- 20:980b37fde361
snake wall coliision
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| weiway | 0:d557f30e3a95 | 1 | /* |
| weiway | 0:d557f30e3a95 | 2 | ELEC2645 Embedded Systems Project |
| weiway | 0:d557f30e3a95 | 3 | School of Electronic & Electrical Engineering |
| weiway | 0:d557f30e3a95 | 4 | University of Leeds |
| weiway | 0:d557f30e3a95 | 5 | Name: Wei Wei |
| weiway | 0:d557f30e3a95 | 6 | Username: el15ww |
| weiway | 0:d557f30e3a95 | 7 | Student ID Number: 200975452 |
| weiway | 0:d557f30e3a95 | 8 | Date: |
| weiway | 9:f82627d119f6 | 9 | */ |
| weiway | 9:f82627d119f6 | 10 | |
| weiway | 9:f82627d119f6 | 11 | #include "mbed.h" |
| weiway | 9:f82627d119f6 | 12 | #include "Gamepad.h" |
| weiway | 9:f82627d119f6 | 13 | #include "N5110.h" |
| weiway | 15:47ea86f1ed70 | 14 | #include "snake_engine.h" |
| weiway | 13:4026781772cb | 15 | #include "snake.h" |
| weiway | 9:f82627d119f6 | 16 | |
| weiway | 9:f82627d119f6 | 17 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
| weiway | 15:47ea86f1ed70 | 18 | |
| weiway | 9:f82627d119f6 | 19 | Gamepad pad; |
| weiway | 13:4026781772cb | 20 | snake_engine engine; |
| weiway | 15:47ea86f1ed70 | 21 | void init(); |
| weiway | 15:47ea86f1ed70 | 22 | void render(); |
| weiway | 15:47ea86f1ed70 | 23 | void welcome(); |
| weiway | 15:47ea86f1ed70 | 24 | void reset(); |
| weiway | 15:47ea86f1ed70 | 25 | |
| weiway | 15:47ea86f1ed70 | 26 | |
| weiway | 9:f82627d119f6 | 27 | |
| weiway | 18:e58a1f8e72ad | 28 | |
| weiway | 9:f82627d119f6 | 29 | struct UserInput { |
| weiway | 9:f82627d119f6 | 30 | Direction d; |
| weiway | 9:f82627d119f6 | 31 | float mag; |
| weiway | 9:f82627d119f6 | 32 | }; |
| weiway | 9:f82627d119f6 | 33 | |
| weiway | 13:4026781772cb | 34 | int main() |
| weiway | 13:4026781772cb | 35 | { |
| weiway | 13:4026781772cb | 36 | init(); |
| weiway | 13:4026781772cb | 37 | welcome(); |
| weiway | 13:4026781772cb | 38 | while (1) { |
| weiway | 18:e58a1f8e72ad | 39 | if ((engine.clision == 1)) { |
| weiway | 18:e58a1f8e72ad | 40 | init(); |
| weiway | 18:e58a1f8e72ad | 41 | welcome(); |
| weiway | 18:e58a1f8e72ad | 42 | render(); |
| weiway | 18:e58a1f8e72ad | 43 | wait(0.03f); |
| weiway | 18:e58a1f8e72ad | 44 | engine.clision = 0; |
| weiway | 18:e58a1f8e72ad | 45 | } |
| weiway | 13:4026781772cb | 46 | |
| weiway | 13:4026781772cb | 47 | engine.read_input(pad); |
| weiway | 13:4026781772cb | 48 | engine.update(pad, lcd); |
| weiway | 13:4026781772cb | 49 | render(); |
| weiway | 13:4026781772cb | 50 | wait(0.05f); |
| weiway | 13:4026781772cb | 51 | reset(); |
| weiway | 13:4026781772cb | 52 | } |
| weiway | 15:47ea86f1ed70 | 53 | |
| weiway | 13:4026781772cb | 54 | } |
| weiway | 13:4026781772cb | 55 | void init() |
| weiway | 13:4026781772cb | 56 | { |
| weiway | 13:4026781772cb | 57 | lcd.init(); |
| weiway | 13:4026781772cb | 58 | pad.init(); |
| weiway | 13:4026781772cb | 59 | engine.init(); |
| weiway | 13:4026781772cb | 60 | } |
| weiway | 13:4026781772cb | 61 | |
| weiway | 13:4026781772cb | 62 | void render() |
| weiway | 13:4026781772cb | 63 | { |
| weiway | 13:4026781772cb | 64 | lcd.clear(); |
| weiway | 13:4026781772cb | 65 | engine.draw(lcd); |
| weiway | 13:4026781772cb | 66 | lcd.refresh(); |
| weiway | 13:4026781772cb | 67 | } |
| weiway | 13:4026781772cb | 68 | void welcome() |
| weiway | 13:4026781772cb | 69 | { |
| weiway | 15:47ea86f1ed70 | 70 | lcd.printString(" Simple ",0,1); |
| weiway | 15:47ea86f1ed70 | 71 | lcd.printString("Snake Game",0,2); |
| weiway | 15:47ea86f1ed70 | 72 | lcd.printString(" WEI WEI ",0,3); |
| weiway | 15:47ea86f1ed70 | 73 | lcd.printString("200975452",0,4); |
| weiway | 15:47ea86f1ed70 | 74 | lcd.printString(" PRESS START ",0,5); |
| weiway | 15:47ea86f1ed70 | 75 | lcd.refresh(); |
| weiway | 15:47ea86f1ed70 | 76 | lcd.clear(); |
| weiway | 15:47ea86f1ed70 | 77 | wait(0.5); |
| weiway | 13:4026781772cb | 78 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
| weiway | 13:4026781772cb | 79 | } |
| weiway | 13:4026781772cb | 80 | |
| weiway | 13:4026781772cb | 81 | } |
| weiway | 13:4026781772cb | 82 | |
| weiway | 13:4026781772cb | 83 | void reset() |
| weiway | 13:4026781772cb | 84 | { |
| weiway | 13:4026781772cb | 85 | if ( pad.check_event(Gamepad::BACK_PRESSED) == true) { |
| weiway | 13:4026781772cb | 86 | lcd.clear(); |
| weiway | 13:4026781772cb | 87 | lcd.refresh(); |
| weiway | 13:4026781772cb | 88 | |
| weiway | 13:4026781772cb | 89 | init(); |
| weiway | 13:4026781772cb | 90 | welcome(); |
| weiway | 13:4026781772cb | 91 | } |
| weiway | 13:4026781772cb | 92 | } |
| weiway | 9:f82627d119f6 | 93 | |
| weiway | 9:f82627d119f6 | 94 | |
| weiway | 18:e58a1f8e72ad | 95 | |
| weiway | 9:f82627d119f6 | 96 | |
| weiway | 18:e58a1f8e72ad | 97 |