testing documentation

Dependencies:   mbed ll16j23s_test_docs

Revision:
3:fcd6d70e9694
Parent:
2:86b67b492cbc
Child:
4:ea3fa51c4386
--- a/main.cpp	Sun Apr 05 21:16:16 2020 +0000
+++ b/main.cpp	Wed May 20 21:25:40 2020 +0000
@@ -14,6 +14,10 @@
 #include "mbed.h"
 #include "Gamepad.h"
 #include "N5110.h"
+#include "FXOS8700CQ.h"
+#include "SnakeEngine.h"
+#include <vector>
+#include <cstdlib>
 
 #define X_MAX       84
 #define Y_MAX       48
@@ -21,6 +25,8 @@
 // objects
 Gamepad pad;
 N5110 lcd;
+SnakeEngine snake;
+FXOS8700CQ device(I2C_SDA,I2C_SCL);
 
 int main() {
     
@@ -29,23 +35,19 @@
     
     float speed = 0.5;
     int cell_size = 2;
+    
     int fps = 25;
     int frame_t = 1000/fps;
     bool death = false;
+
+    //int length = 10; //intial snake size
+    //int size_inc = 5; //how much longer the snake gets due to food
     
-    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 nextState[5];  // array of next states
-    };
-    
-    int d = 0; //direction starts in centre
-    int state = 0; //first state is centre of joystick
-    
+    //int d = 0; //direction starts in centre
+    //int state = 0; //first state is centre of joystick
+
+/*    
     Dir fsm[5] = {
         {0, 0,  0, {0,1,2,3,4}},  // Centred
         {1, 0, -1, {1,1,2,1,4}},  // North, will not go to centre or south
@@ -53,23 +55,27 @@
         {3, 0,  1, {3,3,2,3,4}},  // South, will not go to centre or north
         {4, -1, 0, {4,1,4,3,4}}   // West, will not go to centre or east
     };
-
+*/
     while(1){
         
+        printf("Running!");
+        
         speed = pad.read_pot2();
         
-        if ((x % cell_size) + (y % cell_size) == 0) {   // only allows changing movement when the snake is cell-aligned
+/*
+        if ((x_head % cell_size) + (y_head % 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_head += fsm[state].delta_x; // increments x value based on fsm state value
+        y_head += 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
-        
-        if ((lcd.getPixel(x, y) == 1 && ((state == 1) || (state == 4))) || (lcd.getPixel(x+1, y+1) == 1 && ((state == 2) || (state == 3)))) {
+        x_head = ((x_head % X_MAX) + X_MAX)% X_MAX; // wraps x back to within range 0-83
+        y_head = ((y_head % 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;
@@ -78,11 +84,42 @@
             death = false;
             pad.led(1,0.0);
         }
-                
+*/        
+        
+ /*       
+        if(pad.B_pressed() == true && length > size_inc) {
+            length -= size_inc;
+            printf("Lenght: %d\n", length);
+        }
+*/  
+        
+/*        
+        body_x.insert(body_x.begin(), x_head); //sets first array element to head coordinates
+        body_y.insert(body_y.begin(), y_head);
+        
+        body_x.erase(body_x.begin()+length);
+        body_y.erase(body_y.begin()+length);
+*/        
+/*
+        if(pad.A_pressed() == true) {
+            length += size_inc;
+            //printf("Length: %d\n", length);
+            body = new int*[length];
+              for(int i = length + 1; i < length + size_inc + 1; i++) {
+                body[i] = new int[2];
+                body[i][0] = X_MAX + 1;        //snake body starts outside the screen
+                body[i][1] = 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);
+        
+        //for(int i = 0; i < length; i++) {
+            //lcd.drawRect(body_x[i],body_y[i],cell_size,cell_size,FILL_BLACK);
+        //}
+        
+        //lcd.drawRect(10,10,6,6,FILL_BLACK);
         lcd.refresh();
         wait_ms(25/speed);
     }