ZIYI CHEN ml17z4c 201214999
Dependencies: mbed
main.cpp@8:52e0506e98b8, 2019-05-06 (annotated)
- Committer:
- ziyi11
- Date:
- Mon May 06 00:06:15 2019 +0000
- Revision:
- 8:52e0506e98b8
- Parent:
- 7:8b6f175fcb0e
- Child:
- 9:a8b2086a46e5
add game.h and game.cpp although it still has some errors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ziyi11 | 0:bf56f20b9c5a | 1 | /* |
ziyi11 | 0:bf56f20b9c5a | 2 | ELEC2645 Embedded Systems Project |
ziyi11 | 0:bf56f20b9c5a | 3 | School of Electronic & Electrical Engineering |
ziyi11 | 0:bf56f20b9c5a | 4 | University of Leeds |
ziyi11 | 0:bf56f20b9c5a | 5 | Name: |
ziyi11 | 0:bf56f20b9c5a | 6 | Username: Ziyi Chen |
ziyi11 | 0:bf56f20b9c5a | 7 | Student ID Number:201214999 |
ziyi11 | 0:bf56f20b9c5a | 8 | Date:3.17.2019 |
ziyi11 | 0:bf56f20b9c5a | 9 | */ |
ziyi11 | 0:bf56f20b9c5a | 10 | |
ziyi11 | 4:104a7dafcecd | 11 | #include "mbed.h" |
ziyi11 | 3:da7256e04d41 | 12 | #include "N5110.h" |
ziyi11 | 6:13c43182a848 | 13 | //#include "Snake_menu.h" |
ziyi11 | 8:52e0506e98b8 | 14 | #include "Game.h" |
ziyi11 | 8:52e0506e98b8 | 15 | #include "Gamepad.h" |
ziyi11 | 0:bf56f20b9c5a | 16 | |
ziyi11 | 5:f1a193bb84a2 | 17 | |
ziyi11 | 4:104a7dafcecd | 18 | |
ziyi11 | 4:104a7dafcecd | 19 | |
ziyi11 | 3:da7256e04d41 | 20 | |
ziyi11 | 5:f1a193bb84a2 | 21 | /////////////// objects /////////////// |
ziyi11 | 5:f1a193bb84a2 | 22 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
ziyi11 | 5:f1a193bb84a2 | 23 | Gamepad pad; |
ziyi11 | 5:f1a193bb84a2 | 24 | |
ziyi11 | 5:f1a193bb84a2 | 25 | |
ziyi11 | 5:f1a193bb84a2 | 26 | ///////////// prototypes /////////////// |
ziyi11 | 5:f1a193bb84a2 | 27 | void init(); |
ziyi11 | 6:13c43182a848 | 28 | |
ziyi11 | 5:f1a193bb84a2 | 29 | //void update_game(UserInput input); |
ziyi11 | 5:f1a193bb84a2 | 30 | void render(); |
ziyi11 | 5:f1a193bb84a2 | 31 | void welcome(); |
ziyi11 | 5:f1a193bb84a2 | 32 | |
ziyi11 | 5:f1a193bb84a2 | 33 | ///////////// functions //////////////// |
ziyi11 | 5:f1a193bb84a2 | 34 | int main() |
ziyi11 | 5:f1a193bb84a2 | 35 | { |
ziyi11 | 5:f1a193bb84a2 | 36 | |
ziyi11 | 6:13c43182a848 | 37 | // int fps = 8; // frames per second |
ziyi11 | 5:f1a193bb84a2 | 38 | |
ziyi11 | 5:f1a193bb84a2 | 39 | init(); // initialise and then display welcome screen... |
ziyi11 | 5:f1a193bb84a2 | 40 | welcome(); // waiting for the user to start |
ziyi11 | 5:f1a193bb84a2 | 41 | |
ziyi11 | 5:f1a193bb84a2 | 42 | render(); // first draw the initial frame |
ziyi11 | 5:f1a193bb84a2 | 43 | |
ziyi11 | 5:f1a193bb84a2 | 44 | } |
ziyi11 | 5:f1a193bb84a2 | 45 | |
ziyi11 | 5:f1a193bb84a2 | 46 | // initialies all classes and libraries |
ziyi11 | 5:f1a193bb84a2 | 47 | void init() |
ziyi11 | 5:f1a193bb84a2 | 48 | { |
ziyi11 | 5:f1a193bb84a2 | 49 | //initialise LCD and Gamepad |
ziyi11 | 5:f1a193bb84a2 | 50 | lcd.init(); |
ziyi11 | 6:13c43182a848 | 51 | lcd.setContrast(0.4); |
ziyi11 | 5:f1a193bb84a2 | 52 | pad.init(); |
ziyi11 | 5:f1a193bb84a2 | 53 | } |
ziyi11 | 5:f1a193bb84a2 | 54 | |
ziyi11 | 5:f1a193bb84a2 | 55 | // this function draws each frame on the LCD |
ziyi11 | 5:f1a193bb84a2 | 56 | void render() |
ziyi11 | 5:f1a193bb84a2 | 57 | { |
ziyi11 | 5:f1a193bb84a2 | 58 | // clear screen, re-draw and refresh |
ziyi11 | 5:f1a193bb84a2 | 59 | lcd.clear(); |
ziyi11 | 5:f1a193bb84a2 | 60 | lcd.refresh(); |
ziyi11 | 5:f1a193bb84a2 | 61 | } |
ziyi11 | 5:f1a193bb84a2 | 62 | |
ziyi11 | 5:f1a193bb84a2 | 63 | // simple splash screen displayed on start-up |
ziyi11 | 5:f1a193bb84a2 | 64 | void welcome() { |
ziyi11 | 4:104a7dafcecd | 65 | |
ziyi11 | 4:104a7dafcecd | 66 | |
ziyi11 | 7:8b6f175fcb0e | 67 | lcd.printString("Snake Game",5,1); |
ziyi11 | 7:8b6f175fcb0e | 68 | lcd.printString("Press Start",4,2); |
ziyi11 | 7:8b6f175fcb0e | 69 | lcd.printString("A.ScoreRecord",3,3); |
ziyi11 | 7:8b6f175fcb0e | 70 | lcd.printString("B.Mode",3,4); |
ziyi11 | 7:8b6f175fcb0e | 71 | lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); // transparent, just outline |
ziyi11 | 7:8b6f175fcb0e | 72 | |
ziyi11 | 7:8b6f175fcb0e | 73 | |
ziyi11 | 5:f1a193bb84a2 | 74 | lcd.refresh(); |
ziyi11 | 7:8b6f175fcb0e | 75 | |
ziyi11 | 5:f1a193bb84a2 | 76 | // wait flashing LEDs until start button is pressed |
ziyi11 | 7:8b6f175fcb0e | 77 | while( pad.check_event(Gamepad::START_PRESSED) == false) { |
ziyi11 | 7:8b6f175fcb0e | 78 | // _event_state.set(BACK_PRESSED); |
ziyi11 | 7:8b6f175fcb0e | 79 | pad.leds_off(); |
ziyi11 | 7:8b6f175fcb0e | 80 | } |
ziyi11 | 7:8b6f175fcb0e | 81 | // _event_state.set(A_PRESSED) |
ziyi11 | 7:8b6f175fcb0e | 82 | while ( pad.check_event(Gamepad::A_PRESSED) == false) { |
ziyi11 | 7:8b6f175fcb0e | 83 | pad.leds_off(); |
ziyi11 | 7:8b6f175fcb0e | 84 | } |
ziyi11 | 7:8b6f175fcb0e | 85 | while ( pad.check_event(Gamepad::B_PRESSED) == false) { |
ziyi11 | 5:f1a193bb84a2 | 86 | pad.leds_on(); |
ziyi11 | 7:8b6f175fcb0e | 87 | } |
ziyi11 | 7:8b6f175fcb0e | 88 | |
ziyi11 | 7:8b6f175fcb0e | 89 | } |
ziyi11 | 5:f1a193bb84a2 | 90 | |
ziyi11 | 3:da7256e04d41 | 91 | |
ziyi11 | 7:8b6f175fcb0e | 92 |