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@15:47ea86f1ed70, 2018-05-07 (annotated)
- Committer:
- weiway
- Date:
- Mon May 07 11:57:22 2018 +0000
- Revision:
- 15:47ea86f1ed70
- Parent:
- 13:4026781772cb
- Child:
- 18:e58a1f8e72ad
the game runs well but the fruit reborn outside of the screen. and the snake would not die even if hit the wall
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 | 9:f82627d119f6 | 28 | struct UserInput { |
| weiway | 9:f82627d119f6 | 29 | Direction d; |
| weiway | 9:f82627d119f6 | 30 | float mag; |
| weiway | 9:f82627d119f6 | 31 | }; |
| weiway | 9:f82627d119f6 | 32 | |
| weiway | 13:4026781772cb | 33 | int main() |
| weiway | 13:4026781772cb | 34 | { |
| weiway | 13:4026781772cb | 35 | init(); |
| weiway | 13:4026781772cb | 36 | welcome(); |
| weiway | 13:4026781772cb | 37 | while (1) { |
| weiway | 13:4026781772cb | 38 | |
| weiway | 13:4026781772cb | 39 | engine.read_input(pad); |
| weiway | 13:4026781772cb | 40 | engine.update(pad, lcd); |
| weiway | 13:4026781772cb | 41 | render(); |
| weiway | 13:4026781772cb | 42 | wait(0.05f); |
| weiway | 13:4026781772cb | 43 | reset(); |
| weiway | 13:4026781772cb | 44 | } |
| weiway | 15:47ea86f1ed70 | 45 | |
| weiway | 13:4026781772cb | 46 | } |
| weiway | 13:4026781772cb | 47 | void init() |
| weiway | 13:4026781772cb | 48 | { |
| weiway | 13:4026781772cb | 49 | lcd.init(); |
| weiway | 13:4026781772cb | 50 | pad.init(); |
| weiway | 13:4026781772cb | 51 | engine.init(); |
| weiway | 13:4026781772cb | 52 | } |
| weiway | 13:4026781772cb | 53 | |
| weiway | 13:4026781772cb | 54 | void render() |
| weiway | 13:4026781772cb | 55 | { |
| weiway | 13:4026781772cb | 56 | lcd.clear(); |
| weiway | 13:4026781772cb | 57 | engine.draw(lcd); |
| weiway | 13:4026781772cb | 58 | lcd.refresh(); |
| weiway | 13:4026781772cb | 59 | } |
| weiway | 13:4026781772cb | 60 | void welcome() |
| weiway | 13:4026781772cb | 61 | { |
| weiway | 15:47ea86f1ed70 | 62 | lcd.printString(" Simple ",0,1); |
| weiway | 15:47ea86f1ed70 | 63 | lcd.printString("Snake Game",0,2); |
| weiway | 15:47ea86f1ed70 | 64 | lcd.printString(" WEI WEI ",0,3); |
| weiway | 15:47ea86f1ed70 | 65 | lcd.printString("200975452",0,4); |
| weiway | 15:47ea86f1ed70 | 66 | lcd.printString(" PRESS START ",0,5); |
| weiway | 15:47ea86f1ed70 | 67 | lcd.refresh(); |
| weiway | 15:47ea86f1ed70 | 68 | lcd.clear(); |
| weiway | 15:47ea86f1ed70 | 69 | wait(0.5); |
| weiway | 13:4026781772cb | 70 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
| weiway | 13:4026781772cb | 71 | } |
| weiway | 13:4026781772cb | 72 | |
| weiway | 13:4026781772cb | 73 | } |
| weiway | 13:4026781772cb | 74 | |
| weiway | 13:4026781772cb | 75 | void reset() |
| weiway | 13:4026781772cb | 76 | { |
| weiway | 13:4026781772cb | 77 | if ( pad.check_event(Gamepad::BACK_PRESSED) == true) { |
| weiway | 13:4026781772cb | 78 | lcd.clear(); |
| weiway | 13:4026781772cb | 79 | lcd.refresh(); |
| weiway | 13:4026781772cb | 80 | |
| weiway | 13:4026781772cb | 81 | init(); |
| weiway | 13:4026781772cb | 82 | welcome(); |
| weiway | 13:4026781772cb | 83 | } |
| weiway | 13:4026781772cb | 84 | } |
| weiway | 9:f82627d119f6 | 85 | |
| weiway | 9:f82627d119f6 | 86 | |
| weiway | 9:f82627d119f6 | 87 |