Testing submission
Dependencies: mbed ll16j23s_test_docs
main.cpp@6:6c9453397f4a, 2020-05-23 (annotated)
- Committer:
- JoeShotton
- Date:
- Sat May 23 20:01:00 2020 +0000
- Revision:
- 6:6c9453397f4a
- Parent:
- 5:06fa7674622a
- Child:
- 7:dd84e0fab346
Implemented screen transition function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eencae | 0:b7f1f47bb26a | 1 | /* |
eencae | 0:b7f1f47bb26a | 2 | ELEC2645 Embedded Systems Project |
eencae | 0:b7f1f47bb26a | 3 | School of Electronic & Electrical Engineering |
eencae | 0:b7f1f47bb26a | 4 | University of Leeds |
eencae | 0:b7f1f47bb26a | 5 | 2019/20 |
eencae | 0:b7f1f47bb26a | 6 | |
JoeShotton | 2:86b67b492cbc | 7 | Name: Joe Shotton |
JoeShotton | 2:86b67b492cbc | 8 | Username: ll16j23s |
JoeShotton | 2:86b67b492cbc | 9 | Student ID Number: 201127267 |
JoeShotton | 2:86b67b492cbc | 10 | Date: 4/4/20 |
eencae | 0:b7f1f47bb26a | 11 | */ |
eencae | 0:b7f1f47bb26a | 12 | |
eencae | 0:b7f1f47bb26a | 13 | // includes |
eencae | 0:b7f1f47bb26a | 14 | #include "mbed.h" |
eencae | 0:b7f1f47bb26a | 15 | #include "Gamepad.h" |
eencae | 0:b7f1f47bb26a | 16 | #include "N5110.h" |
JoeShotton | 3:fcd6d70e9694 | 17 | #include "FXOS8700CQ.h" |
JoeShotton | 3:fcd6d70e9694 | 18 | #include "SnakeEngine.h" |
JoeShotton | 3:fcd6d70e9694 | 19 | #include <vector> |
JoeShotton | 3:fcd6d70e9694 | 20 | #include <cstdlib> |
eencae | 0:b7f1f47bb26a | 21 | |
JoeShotton | 1:985dfa6cee28 | 22 | #define X_MAX 84 |
JoeShotton | 1:985dfa6cee28 | 23 | #define Y_MAX 48 |
eencae | 0:b7f1f47bb26a | 24 | |
eencae | 0:b7f1f47bb26a | 25 | // objects |
eencae | 0:b7f1f47bb26a | 26 | Gamepad pad; |
eencae | 0:b7f1f47bb26a | 27 | N5110 lcd; |
JoeShotton | 3:fcd6d70e9694 | 28 | SnakeEngine snake; |
JoeShotton | 5:06fa7674622a | 29 | FXOS8700CQ mag(I2C_SDA,I2C_SCL); |
eencae | 0:b7f1f47bb26a | 30 | |
JoeShotton | 1:985dfa6cee28 | 31 | int main() { |
JoeShotton | 1:985dfa6cee28 | 32 | |
JoeShotton | 1:985dfa6cee28 | 33 | lcd.init(); |
JoeShotton | 1:985dfa6cee28 | 34 | pad.init(); |
JoeShotton | 5:06fa7674622a | 35 | snake.init(mag); |
JoeShotton | 6:6c9453397f4a | 36 | lcd.setContrast(0.4); |
JoeShotton | 1:985dfa6cee28 | 37 | |
JoeShotton | 6:6c9453397f4a | 38 | snake.transition_black(lcd); |
JoeShotton | 6:6c9453397f4a | 39 | snake.transition_white(lcd); |
JoeShotton | 1:985dfa6cee28 | 40 | float speed = 0.5; |
JoeShotton | 3:fcd6d70e9694 | 41 | |
JoeShotton | 1:985dfa6cee28 | 42 | int fps = 25; |
JoeShotton | 1:985dfa6cee28 | 43 | int frame_t = 1000/fps; |
JoeShotton | 2:86b67b492cbc | 44 | bool death = false; |
JoeShotton | 3:fcd6d70e9694 | 45 | |
JoeShotton | 3:fcd6d70e9694 | 46 | //int length = 10; //intial snake size |
JoeShotton | 3:fcd6d70e9694 | 47 | //int size_inc = 5; //how much longer the snake gets due to food |
JoeShotton | 1:985dfa6cee28 | 48 | |
JoeShotton | 1:985dfa6cee28 | 49 | |
JoeShotton | 3:fcd6d70e9694 | 50 | //int d = 0; //direction starts in centre |
JoeShotton | 3:fcd6d70e9694 | 51 | //int state = 0; //first state is centre of joystick |
JoeShotton | 3:fcd6d70e9694 | 52 | |
JoeShotton | 3:fcd6d70e9694 | 53 | /* |
JoeShotton | 1:985dfa6cee28 | 54 | Dir fsm[5] = { |
JoeShotton | 1:985dfa6cee28 | 55 | {0, 0, 0, {0,1,2,3,4}}, // Centred |
JoeShotton | 1:985dfa6cee28 | 56 | {1, 0, -1, {1,1,2,1,4}}, // North, will not go to centre or south |
JoeShotton | 1:985dfa6cee28 | 57 | {2, 1, 0, {2,1,2,3,2}}, // East, will not go to centre or west |
JoeShotton | 1:985dfa6cee28 | 58 | {3, 0, 1, {3,3,2,3,4}}, // South, will not go to centre or north |
JoeShotton | 1:985dfa6cee28 | 59 | {4, -1, 0, {4,1,4,3,4}} // West, will not go to centre or east |
JoeShotton | 1:985dfa6cee28 | 60 | }; |
JoeShotton | 3:fcd6d70e9694 | 61 | */ |
JoeShotton | 4:ea3fa51c4386 | 62 | while(death == false){ |
JoeShotton | 1:985dfa6cee28 | 63 | |
JoeShotton | 4:ea3fa51c4386 | 64 | //printf("Running!"); |
JoeShotton | 3:fcd6d70e9694 | 65 | |
JoeShotton | 1:985dfa6cee28 | 66 | speed = pad.read_pot2(); |
JoeShotton | 1:985dfa6cee28 | 67 | |
JoeShotton | 4:ea3fa51c4386 | 68 | lcd.clear(); |
JoeShotton | 4:ea3fa51c4386 | 69 | snake.move_body(pad, lcd, death); |
JoeShotton | 4:ea3fa51c4386 | 70 | lcd.refresh(); |
JoeShotton | 4:ea3fa51c4386 | 71 | wait_ms(500/(5+snake.score)); |
JoeShotton | 4:ea3fa51c4386 | 72 | } |
JoeShotton | 4:ea3fa51c4386 | 73 | } |
JoeShotton | 4:ea3fa51c4386 | 74 | |
JoeShotton | 3:fcd6d70e9694 | 75 | /* if ((lcd.getPixel(x, y) == 1 && ((state == 1) || (state == 4))) || (lcd.getPixel(x+1, y+1) == 1 && ((state == 2) || (state == 3)))) { |
JoeShotton | 2:86b67b492cbc | 76 | // checks infront of head to see if pixel is set |
JoeShotton | 2:86b67b492cbc | 77 | // due to the size of the head, there is an offset for the check for North and Eastward directions |
JoeShotton | 2:86b67b492cbc | 78 | death = true; |
JoeShotton | 2:86b67b492cbc | 79 | pad.led(1,0.9); |
JoeShotton | 2:86b67b492cbc | 80 | } else { |
JoeShotton | 2:86b67b492cbc | 81 | death = false; |
JoeShotton | 2:86b67b492cbc | 82 | pad.led(1,0.0); |
JoeShotton | 2:86b67b492cbc | 83 | } |
JoeShotton | 3:fcd6d70e9694 | 84 | */ |
JoeShotton | 3:fcd6d70e9694 | 85 | |
JoeShotton | 3:fcd6d70e9694 | 86 | /* |
JoeShotton | 3:fcd6d70e9694 | 87 | if(pad.B_pressed() == true && length > size_inc) { |
JoeShotton | 3:fcd6d70e9694 | 88 | length -= size_inc; |
JoeShotton | 3:fcd6d70e9694 | 89 | printf("Lenght: %d\n", length); |
JoeShotton | 3:fcd6d70e9694 | 90 | } |
JoeShotton | 3:fcd6d70e9694 | 91 | */ |
JoeShotton | 3:fcd6d70e9694 | 92 | |
JoeShotton | 3:fcd6d70e9694 | 93 | /* |
JoeShotton | 3:fcd6d70e9694 | 94 | body_x.insert(body_x.begin(), x_head); //sets first array element to head coordinates |
JoeShotton | 3:fcd6d70e9694 | 95 | body_y.insert(body_y.begin(), y_head); |
JoeShotton | 3:fcd6d70e9694 | 96 | |
JoeShotton | 3:fcd6d70e9694 | 97 | body_x.erase(body_x.begin()+length); |
JoeShotton | 3:fcd6d70e9694 | 98 | body_y.erase(body_y.begin()+length); |
JoeShotton | 3:fcd6d70e9694 | 99 | */ |
JoeShotton | 3:fcd6d70e9694 | 100 | /* |
JoeShotton | 3:fcd6d70e9694 | 101 | if(pad.A_pressed() == true) { |
JoeShotton | 3:fcd6d70e9694 | 102 | length += size_inc; |
JoeShotton | 3:fcd6d70e9694 | 103 | //printf("Length: %d\n", length); |
JoeShotton | 3:fcd6d70e9694 | 104 | body = new int*[length]; |
JoeShotton | 3:fcd6d70e9694 | 105 | for(int i = length + 1; i < length + size_inc + 1; i++) { |
JoeShotton | 3:fcd6d70e9694 | 106 | body[i] = new int[2]; |
JoeShotton | 3:fcd6d70e9694 | 107 | body[i][0] = X_MAX + 1; //snake body starts outside the screen |
JoeShotton | 3:fcd6d70e9694 | 108 | body[i][1] = 0; |
JoeShotton | 3:fcd6d70e9694 | 109 | } |
JoeShotton | 3:fcd6d70e9694 | 110 | */ |
eencae | 0:b7f1f47bb26a | 111 | |
JoeShotton | 4:ea3fa51c4386 | 112 |