cube

Dependencies:   mbed

Fork of manworm_tv_gpu by Jared DiCarlo

Revision:
1:24fd07a24094
Parent:
0:7757ab3f7206
Child:
2:1d16e99f334b
--- a/main.cpp	Sat Nov 18 04:18:42 2017 +0000
+++ b/main.cpp	Sat Nov 18 07:37:42 2017 +0000
@@ -7,6 +7,12 @@
 #define Y_MIN 7
 #define Y_MAX (V_RES/4 - 15)
 
+int SX_MIN = 30;
+int SX_MAX = 90;
+int SY_MIN = 10;
+int SY_MAX = 50;
+int PADDLE_LEN = 10;
+
 #define Y_0 ( (Y_MIN + Y_MAX)/2 )
 #define X_0 ( (X_MIN + X_MAX)/2 )
 #define SIDE 8
@@ -99,11 +105,21 @@
 
 uint8_t im_line_va[H_RES*V_RES]; //image buffer
 
+//pong variables
+float p1 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2, p2 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2;
+float p1v = 0.1, p2v = -0.1;
+
+float bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2;
+float bxv = 0.03, byv = 0.03;
+
+DigitalIn p1_in(A0);
+DigitalIn p2_in(A1);
+
 void make_checkerboard()
 {
     for(int i = 0; i < H_RES; i++)
         for(int j = 0; j < V_RES; j++)
-            im_line_va[i+j*H_RES] = ((i > 20) && (i < 98)) && ((j%2) ^ (i%2)); //checkerboard
+            im_line_va[i+j*H_RES] = 0*((i > 20) && (i < 98)) && ((j%2) ^ (i%2)); //checkerboard
     
 }
 
@@ -299,12 +315,12 @@
     }
     else if(f_count < DEMO_LENGTH)
     {
-        draw_cube_spin(1);
+        draw_cube_spin(0);
     }
-    else if(f_count < DEMO_LENGTH * 2)
+    else if(f_count < DEMO_LENGTH * 1.22)
     {
         for(int k = 1; k < 10; k++)
-            for(int kk = 1; kk < 3; kk++)
+            //for(int kk = 1; kk < 3; kk++)
             {
                 draw_v_check(k,1);
                 draw_v_check(k,1);
@@ -326,7 +342,7 @@
         {
             im_line_va[v*H_RES+h] = 1;
         }
-        wait(.03);
+        wait(.01);
     }
     
         for(int v = Y_MAX+15; v > Y_MIN; v--)
@@ -335,7 +351,7 @@
             {
                 im_line_va[v*H_RES+h] = 0;
             }
-            wait(.03);
+            wait(.005);
         }  
     
         for(uint16_t h = X_MIN; h < X_MAX; h++)
@@ -344,7 +360,7 @@
             {
                 im_line_va[v*H_RES + h] = 1;
             }
-            wait(.03);
+            wait(.005);
         }
     
         for(uint16_t h = X_MIN; h < X_MAX; h++)
@@ -353,7 +369,7 @@
             {
                 im_line_va[v*H_RES + h] = 0;
             }
-            wait(.03);
+            wait(.005);
         }
     
         for(int v = Y_MIN; v < Y_MAX+15; v++)
@@ -413,10 +429,68 @@
 }
 
 int main() {
+    potato:
     init_buffers();
     t.attach_us(&isr,63);
+    for(int y = 0; y < PADDLE_LEN; y++) {
+        im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 1;
+        im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 1;
+    }
+    im_line_va[H_RES*(int)by+(int)bx] = 1;
     for(;;)
-    { 
-        update_image();
+    {
+        for(int y = 0; y < PADDLE_LEN; y++) {
+            im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 0;
+            im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 0;
+        }
+        im_line_va[H_RES*(int)by+(int)bx] = 0;
+        
+        int cmd1 = p1_in.read();
+        int cmd2 = p2_in.read();
+        if (cmd1 == 0) p1v = 0.1; else p1v = -0.1f;
+        if (cmd2 == 0) p2v = 0.1; else p2v = -0.1f;
+        
+        p1 += p1v;
+        p2 += p2v;
+        bx += bxv;
+        by += byv;
+        
+        if (p1 < SY_MIN) p1 = SY_MIN;
+        if (p1 > SY_MAX-PADDLE_LEN) p1 = SY_MAX-PADDLE_LEN;
+        if (p2 < SY_MIN) p2 = SY_MIN;
+        if (p2 > SY_MAX-PADDLE_LEN) p2 = SY_MAX-PADDLE_LEN;
+        
+        if (bx < SX_MIN) {
+            bxv = -bxv; 
+            bx = SX_MIN;
+            if ((int) by < (int) p1 || (int) by > (int) (p1 + 10)) break;
+        }
+        if (bx > SX_MAX) {
+            bxv = -bxv; 
+            bx = SX_MAX;
+            if ((int) by < (int) p2 || (int) by > (int) (p2 + 10)) break;
+        }
+        if (by < SY_MIN) {byv = -byv; by = SY_MIN;}
+        if (by > SY_MAX) {byv = -byv; by = SY_MAX;}
+        
+        for(int y = 0; y < PADDLE_LEN; y++) {
+            im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 1;
+            im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 1;
+        }
+        im_line_va[H_RES*(int)by+(int)bx] = 1;
+        
+        wait(1/600.0f);
+    }
+    
+p1 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2, p2 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2;
+ p1v = 0.1, p2v = -0.1;
+
+ bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2;
+ bxv = 0.03, byv = 0.03;
+    for (;;) 
+    {
+        for(int i = 0; i < 20000; i++)
+            update_image();
+        if(!p1_in.read() || !p2_in.read()) goto potato;
     }
 }