testing documentation
Dependencies: mbed ll16j23s_test_docs
Diff: main.cpp
- Revision:
- 2:86b67b492cbc
- Parent:
- 1:985dfa6cee28
- Child:
- 3:fcd6d70e9694
--- a/main.cpp Sun Apr 05 20:00:17 2020 +0000 +++ b/main.cpp Sun Apr 05 21:16:16 2020 +0000 @@ -4,10 +4,10 @@ University of Leeds 2019/20 -Name: -Username: -Student ID Number: -Date: +Name: Joe Shotton +Username: ll16j23s +Student ID Number: 201127267 +Date: 4/4/20 */ // includes @@ -31,14 +31,15 @@ int cell_size = 2; int fps = 25; int frame_t = 1000/fps; + bool death = false; int x = X_MAX/2; //start coords are centre of the screen int y = Y_MAX/2; struct Dir { int output; // output value - int delta_x; //increment value for x - int delta_y; //increment value for y + int delta_x; // increment value for x + int delta_y; // increment value for y int nextState[5]; // array of next states }; @@ -57,20 +58,31 @@ speed = pad.read_pot2(); - if ((x % cell_size) + (y % cell_size) == 0) { //only allows changing movement when the snake is cell-aligned - d = pad.get_cardinal(); //gets joystick cardinal direction: 0 for centre, 1 - 4 for NESW respectively - state = fsm[state].nextState[d]; //adjusts direction fsm state based on direction + if ((x % cell_size) + (y % cell_size) == 0) { // only allows changing movement when the snake is cell-aligned + d = pad.get_cardinal(); // gets joystick cardinal direction: 0 for centre, 1 - 4 for NESW respectively + state = fsm[state].nextState[d]; // adjusts direction fsm state based on direction } - x += fsm[state].delta_x; //increments x value based on fsm state value - y += fsm[state].delta_y; //increments y value based on fsm state value + x += fsm[state].delta_x; // increments x value based on fsm state value + y += fsm[state].delta_y; // increments y value based on fsm state value - x = ((x % X_MAX) + X_MAX)% X_MAX; //wraps x back to within range 0-83 - y = ((y % Y_MAX) + Y_MAX)% Y_MAX; //wraps y back to within range 0-83 + x = ((x % X_MAX) + X_MAX)% X_MAX; // wraps x back to within range 0-83 + y = ((y % Y_MAX) + Y_MAX)% Y_MAX; // wraps y back to within range 0-83 + if ((lcd.getPixel(x, y) == 1 && ((state == 1) || (state == 4))) || (lcd.getPixel(x+1, y+1) == 1 && ((state == 2) || (state == 3)))) { + // checks infront of head to see if pixel is set + // due to the size of the head, there is an offset for the check for North and Eastward directions + death = true; + pad.led(1,0.9); + } else { + death = false; + pad.led(1,0.0); + } + lcd.clear(); lcd.setContrast(0.5); lcd.drawRect(x,y,cell_size,cell_size,FILL_BLACK); + lcd.drawRect(10,10,6,6,FILL_BLACK); lcd.refresh(); wait_ms(25/speed); }