Final Submission. I have read and agreed with Statement of Academic Integrity.
Dependencies: mbed Gamepad N5110 Joystick
main.cpp@3:660de4311976, 2019-05-09 (annotated)
- Committer:
- el16dlc
- Date:
- Thu May 09 00:19:35 2019 +0000
- Revision:
- 3:660de4311976
- Parent:
- 2:0bd6711eae26
- Child:
- 4:0fc3441556e1
4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el16dlc | 1:b9f3b7d869d8 | 1 | /* |
el16dlc | 1:b9f3b7d869d8 | 2 | ELEC2645 Embedded Systems Project |
el16dlc | 1:b9f3b7d869d8 | 3 | School of Electronic & Electrical Engineering |
el16dlc | 1:b9f3b7d869d8 | 4 | University of Leeds |
el16dlc | 1:b9f3b7d869d8 | 5 | |
el16dlc | 1:b9f3b7d869d8 | 6 | Name: DANIEL CROCKFORD |
el16dlc | 1:b9f3b7d869d8 | 7 | Username: el16dlc |
el16dlc | 1:b9f3b7d869d8 | 8 | Student ID Number: 201039580 |
el16dlc | 1:b9f3b7d869d8 | 9 | Date: 07/05/2019 |
el16dlc | 1:b9f3b7d869d8 | 10 | */ |
el16dlc | 1:b9f3b7d869d8 | 11 | |
el16dlc | 1:b9f3b7d869d8 | 12 | |
el16dlc | 1:b9f3b7d869d8 | 13 | #include "main.h" |
el16dlc | 1:b9f3b7d869d8 | 14 | #include "Snake.h" |
el16dlc | 1:b9f3b7d869d8 | 15 | #include "Game_engine.h" |
el16dlc | 1:b9f3b7d869d8 | 16 | |
el16dlc | 1:b9f3b7d869d8 | 17 | // Gamepad Peripherals |
el16dlc | 1:b9f3b7d869d8 | 18 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
el16dlc | 1:b9f3b7d869d8 | 19 | |
el16dlc | 1:b9f3b7d869d8 | 20 | Gamepad gamepad; |
el16dlc | 1:b9f3b7d869d8 | 21 | |
el16dlc | 1:b9f3b7d869d8 | 22 | // Instances |
el16dlc | 1:b9f3b7d869d8 | 23 | GameEngine engine; |
el16dlc | 1:b9f3b7d869d8 | 24 | |
el16dlc | 3:660de4311976 | 25 | |
el16dlc | 1:b9f3b7d869d8 | 26 | int main() { |
el16dlc | 3:660de4311976 | 27 | srand(time(NULL)); |
el16dlc | 1:b9f3b7d869d8 | 28 | Init(); |
el16dlc | 1:b9f3b7d869d8 | 29 | Welcome(); |
el16dlc | 2:0bd6711eae26 | 30 | engine.init(); |
el16dlc | 1:b9f3b7d869d8 | 31 | |
el16dlc | 1:b9f3b7d869d8 | 32 | |
el16dlc | 1:b9f3b7d869d8 | 33 | |
el16dlc | 1:b9f3b7d869d8 | 34 | while(1) { |
el16dlc | 1:b9f3b7d869d8 | 35 | render(); |
el16dlc | 2:0bd6711eae26 | 36 | engine.get_dir(gamepad); |
el16dlc | 2:0bd6711eae26 | 37 | engine.snake_move(); |
el16dlc | 3:660de4311976 | 38 | engine.food_move(); |
el16dlc | 1:b9f3b7d869d8 | 39 | } |
el16dlc | 1:b9f3b7d869d8 | 40 | } |
el16dlc | 1:b9f3b7d869d8 | 41 | |
el16dlc | 1:b9f3b7d869d8 | 42 | |
el16dlc | 1:b9f3b7d869d8 | 43 | // Initialise gamepad |
el16dlc | 1:b9f3b7d869d8 | 44 | void Init() { |
el16dlc | 1:b9f3b7d869d8 | 45 | lcd.init(); |
el16dlc | 1:b9f3b7d869d8 | 46 | gamepad.init(); |
el16dlc | 1:b9f3b7d869d8 | 47 | lcd.setContrast(0.5); |
el16dlc | 1:b9f3b7d869d8 | 48 | lcd.setBrightness(0.5); |
el16dlc | 1:b9f3b7d869d8 | 49 | gamepad.leds_off(); |
el16dlc | 1:b9f3b7d869d8 | 50 | gamepad.check_event(Gamepad::A_PRESSED); |
el16dlc | 1:b9f3b7d869d8 | 51 | gamepad.check_event(Gamepad::B_PRESSED); |
el16dlc | 1:b9f3b7d869d8 | 52 | gamepad.check_event(Gamepad::X_PRESSED); |
el16dlc | 1:b9f3b7d869d8 | 53 | gamepad.check_event(Gamepad::Y_PRESSED); |
el16dlc | 1:b9f3b7d869d8 | 54 | gamepad.check_event(Gamepad::L_PRESSED); |
el16dlc | 1:b9f3b7d869d8 | 55 | gamepad.check_event(Gamepad::R_PRESSED); |
el16dlc | 1:b9f3b7d869d8 | 56 | gamepad.check_event(Gamepad::BACK_PRESSED); |
el16dlc | 2:0bd6711eae26 | 57 | gamepad.check_event(Gamepad::START_PRESSED); |
el16dlc | 1:b9f3b7d869d8 | 58 | } |
el16dlc | 1:b9f3b7d869d8 | 59 | |
el16dlc | 1:b9f3b7d869d8 | 60 | // Prototype welcome screen |
el16dlc | 1:b9f3b7d869d8 | 61 | void Welcome() { |
el16dlc | 1:b9f3b7d869d8 | 62 | lcd.clear(); |
el16dlc | 1:b9f3b7d869d8 | 63 | lcd.printString("Welcome",2,1); |
el16dlc | 1:b9f3b7d869d8 | 64 | lcd.refresh(); |
el16dlc | 1:b9f3b7d869d8 | 65 | wait(2.0); |
el16dlc | 1:b9f3b7d869d8 | 66 | } |
el16dlc | 1:b9f3b7d869d8 | 67 | |
el16dlc | 1:b9f3b7d869d8 | 68 | // Draws each frame on screen |
el16dlc | 1:b9f3b7d869d8 | 69 | void render() { |
el16dlc | 1:b9f3b7d869d8 | 70 | lcd.clear(); |
el16dlc | 2:0bd6711eae26 | 71 | engine.draw(lcd); |
el16dlc | 1:b9f3b7d869d8 | 72 | lcd.refresh(); |
el16dlc | 3:660de4311976 | 73 | wait(0.2); |
el16dlc | 1:b9f3b7d869d8 | 74 | } |