Revenge of the Mouse

Dependencies:   4DGL-uLCD-SE EthernetInterface Game_Synchronizer LCD_fonts MMA8452 SDFileSystem mbed-rtos mbed wave_player

Fork of 2035_Tanks_Shell by ECE2035 Spring 2015 TA

Revision:
28:fdaa7ecfbd80
Parent:
27:bd55ab4d137c
diff -r bd55ab4d137c -r fdaa7ecfbd80 main.cpp
--- a/main.cpp	Fri Oct 30 11:08:31 2015 +0000
+++ b/main.cpp	Tue Nov 01 18:59:29 2016 +0000
@@ -5,20 +5,13 @@
 #include "SDFileSystem.h"
 #include "wave_player.h"
 #include "game_synchronizer.h"
-#include "tank.h"
-#include "bullet.h"
 #include "globals.h"
-
+#include "playSound.h"
+#include "rtos.h"
+#include "uLCD_4DGL.h"
+#define VOLUME 0.03
+#define BPM 100.0
 
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
-DigitalOut led3(LED3);
-DigitalOut led4(LED4);
-
-DigitalIn pb_u(p21);                        // Up Button
-DigitalIn pb_r(p22);                        // Right Button
-DigitalIn pb_d(p23);                        // Down Button
-DigitalIn pb_l(p24);                        // Left Button
 
 Serial pc(USBTX, USBRX);                    // Serial connection to PC. Useful for debugging!
 MMA8452 acc(p28, p27, 100000);              // Accelerometer (SDA, SCL, Baudrate)
@@ -26,199 +19,526 @@
 SDFileSystem sd(p5, p6, p7, p8, "sd");      // SD  (mosi, miso, sck, cs)
 AnalogOut DACout(p18);                      // speaker
 wave_player player(&DACout);                // wav player
-Game_Synchronizer sync(PLAYER1);            // Game_Synchronizer (PLAYER)
-Timer frame_timer;                          // Timer
 
-// Global variables go here.
+DigitalIn pb_u(p22);                        // Up Button
+DigitalIn pb_r(p24);                        // Right Button
+DigitalIn pb_d(p23);                        // Down Button
+DigitalIn pb_l(p21);                        // Left Button
+DigitalIn pb_c(p25);
+
+PwmOut pwm_pin(p26);
 
-int winner = -1;
-int whose_turn = PLAYER1;
-
+//InterruptIn button(p21);
 
-// Ask the user whether to run the game in Single- or Multi-Player mode.
-// Note that this function uses uLCD instead of sync because it is only 
-// writing to the local (Player1) lcd. Sync hasn't been initialized yet,
-// so you can't use it anyway. For the same reason, you must access
-// the buttons directly e.g. if( !pb_r ) { do something; }.
+int ND=0, NU=0, NL=0, NR=0; 
+int dx=6;
+int dy=6;
+int a,b,c,d;
+int i,z;
+int cc;
+int w;
 
-// return MULTI_PLAYER if the user selects multi-player.
-// return SINGLE_PLAYER if the user selects single-player.
-int game_menu(void) {
-    
-    uLCD.baudrate(BAUD_3000000);
+int N,E,S,W,N1,N2,E1,E2,S1,S2,W1,W2;
+
+int CONVERT_24_TO_16_BPP(int col_24) {
+    int p = col_24 & 0xFF;
+    int g = (col_24 >> 8) & 0xFF;
+    int r = (col_24 >> 16)& 0xFF;
     
-    // the locate command tells the screen where to place the text.
-    uLCD.locate(0,15);
-    uLCD.puts("Replace me");
+    r >>= 3;
+    g >>= 2;
+    p >>= 3;
+    
+    return r<<11 | g<<5 | p;
+}
 
-    // Button Example:
-    // Use !pb_r to access the player1 right button value.
-    
-    wait(2);        // Eventually you can take this out.
-    
-    // Eventually you should return SINGLE_PLAYER or MULTI_PLAYER
-    // depending on the user's choice.
-    return SINGLE_PLAYER;       
+bool pixel_eq(int color1, int color2) {
+    return (CONVERT_24_TO_16_BPP(color1) == color2 || 
+            CONVERT_24_TO_16_BPP(color2) == color1 ||
+            color1 == color2);
 }
 
-// Initialize the world map. I've provided a basic map here,
-// but as part of the assignment you must create more
-// interesting map(s).
-// Note that calls to sync.function() will run function()
-// on both players' LCDs (assuming you are in multiplayer mode).
-// In single player mode, only your lcd will be modified. (Makes sense, right?)
-void map_init() {
-    
-    // Fill the entire screen with sky blue.
-    sync.background_color(SKY_COLOR);
-    
-    // Call the clear screen function to force the LCD to redraw the screen
-    // with the new background color.
-    sync.cls();
-    
-    // Draw the ground in green.
-    sync.filled_rectangle(0,0,128,20, GND_COLOR);
-    
-    // Draw some obstacles. They don't have to be black, 
-    // but they shouldn't be the same color as the sky or your tanks.
-    // Get creative here. You could use brown and grey to draw a mountain
-    // or something cool like that.
-    sync.filled_rectangle(59, 20, 69, 60, BLACK);
-    
-    // Before you write text on the screens, tell the LCD where to put it.
-    sync.locate(0,15);
-    
-    // Set the text background color to match the sky. Just for looks.
-    sync.textbackground_color(SKY_COLOR);
-    
-    // Display the game title.
-    char title[] = "  Title";
-    sync.puts(title, sizeof(title));
-    
-    // Flush the draw buffer and execute all the accumulated draw commands.
-    sync.update();          
+/*
+void thread1(void const *args)
+{
+    while(true) {         // thread loop
+        z=rand()%8;
+        pc.printf("%d ",z);
+        Thread::wait(500); // wait 0.5s
+        if (z==0 || z==4 || z==7){ //Move Left
+                cc=cx-dx;
+                a=uLCD.read_pixel(cc, cy);
+                b = pixel_eq(a, BLACK);
+                if (b==1){
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
+                    cx=cx-dx;
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
+                    pc.printf("C=%d\n",cc);
+                }
+                t = pixel_eq(a, STONE_COLOR);
+
+            }
+        if (z==1 || z==5 ||z==6){ //Move Right
+                cc=cx+dx;
+                a=uLCD.read_pixel(cc, cy);
+                b = pixel_eq(a, BLACK);
+                if (b==1){
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
+                    cx=cx+dx;
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
+                    pc.printf("C=%d\n",cc);
+                }
+                t = pixel_eq(a, STONE_COLOR);
+
+            }
+        if (z==2|| z==4 || z==5){ //Move up
+                cc=cy-dy;
+                a=uLCD.read_pixel(cx, cc);
+                b = pixel_eq(a, BLACK);
+                if (b==1){
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
+                    cy=cy-dy;
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
+                    pc.printf("C=%d\n",cc);
+                }
+                t = pixel_eq(a, STONE_COLOR);
+
+            }
+        if (z==3 || z==6 || z==7){ //Move Down
+                cc=cy+dy;
+                a=uLCD.read_pixel(cx, cc);
+                b = pixel_eq(a, BLACK);
+                if (b==1){
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
+                    cy=cy+dy;
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
+                    pc.printf("C=%d\n",cc);
+                }
+                t = pixel_eq(a, STONE_COLOR);
+
+            }
+    }
 }
+*/
 
-// Initialize the game hardware. 
-// Call game_menu to find out which mode to play the game in (Single- or Multi-Player)
-// Initialize the game synchronizer.
-void game_init(void) {
-    
-    led1 = 0; led2 = 0; led3 = 0; led4 = 0;
-    
-    pb_u.mode(PullUp);
-    pb_r.mode(PullUp); 
-    pb_d.mode(PullUp);    
-    pb_l.mode(PullUp);
-    
-    pc.printf("\033[2J\033[0;0H");              // Clear the terminal screen.
-    pc.printf("I'm alive! Player 1\n");         // Let us know you made it this far.
-    int mode = game_menu();
-    sync.init(&uLCD, &acc, &pb_u, &pb_r, &pb_d, &pb_l, mode); // Connect to the other player.
-    map_init();
-    pc.printf("Initialized...\n");              // Let us know you finished initializing.
-}
+/*int cl=1;
 
-// Display some kind of game over screen which lets us know who won.
-// Play a cool sound!
-void game_over() {
-    
+void flip(void) {
+                c=x-dx;
+                a=uLCD.read_pixel(c, y);
+                b = TREE_COLOR;
+                b = pixel_eq(a, TREE_COLOR);
+                pc.printf("a= %d",a);
+                pc.printf("b= %d",b);
+                while (b==1){
+                    c=c-dx;
+                    a=uLCD.read_pixel(c, y);
+                    b = pixel_eq(a, TREE_COLOR);
+                    pc.printf("loop:b=%d",b);
+                    }
+                b = pixel_eq(a, LIGHTBLACK);
+                pc.printf("a2= %d",a);
+                pc.printf("b2:%d",b);
+                if (b==1){
+                    goto Main;
+                }
+                
+                a=uLCD.read_pixel(x-dx, y);
+                b = pixel_eq(a, BLACK);
+                cl=1;
+Main:
+}*/
+
+void thread1(void const *args)
+{
+    while(true) {         // thread loop
+        playSound("/sd/wavfiles/minecraft0.wav");
+    }
 }
 
 
-int main (void) {
-    
-    int* p1_buttons;
-    int* p2_buttons;
-    
-    float ax1, ay1, az1;
-    float ax2, ay2, az2;
-    
-    game_init();
-    
-    // Create your tanks.
-    Tank t1(4, 21, 12, 8, TANK_RED);            // (min_x, min_y, width, height, color)
-    Tank t2(111, 21, 12, 8, TANK_BLUE);         // (min_x, min_y, width, height, color)
-    
-    // For each tank, create a bullet.
-    Bullet b1(&t1);
-    Bullet b2(&t2);
-    
-    frame_timer.start();
-    
-    // Your code starts here...
-    while(true) {
+  int main(){       
+Start:      uLCD.cls();
+            pb_l.mode(PullUp);
+            pb_r.mode(PullUp);
+            pb_u.mode(PullUp);
+            pb_d.mode(PullUp);
+            pb_c.mode(PullUp);
+            
+            int x=64;
+            int y=64;
+            int cx=16;
+            int cy=64;
+            int count=0;
+            int t=0;
+        /*
+        button.mode(PullUp);
+        wait(.01);
+        button.fall(&flip);
+        */
+        //Main outer ring
+            uLCD.filled_rectangle(0,0,128,6, LIGHTBLACK);        //MAKE STONE COLOR (LIGHT GRAY)
+            uLCD.filled_rectangle(0,0,6,128, LIGHTBLACK);      //STONE COLOR
+            uLCD.filled_rectangle(0,122,128,128, LIGHTBLACK);       //STONE COLOR
+            uLCD.filled_rectangle(122,0,128,128, LIGHTBLACK);       //STONE COLOR
+        
+            //inner ring
+            uLCD.filled_rectangle(26,26,102,102,TREE_COLOR);
+            
+            //mouse
+            uLCD.filled_rectangle(61,61,67,67, STONE_COLOR);
+            
+            //cat
+            uLCD.filled_rectangle(13,61,19,67, YELLOW);
+            
+            Thread t1(thread1); //start thread4
+            pc.printf("before main");
+        
+Main:  while(1) {
+            
+            ND=0;
+            NU=0;
+            NL=0;
+            NR=0;
+            pc.printf("aftre main");
+            if (!pb_c){
+                uLCD.filled_circle(x,y,.5, ex1);
+                //wait(.5);
+                uLCD.filled_circle(x,y,1.0, ex2);
+                //wait(.5);
+                uLCD.filled_circle(x,y,1.5, ex3);
+                //wait(.5);
+                uLCD.filled_circle(x,y,2.0, ex4);
+                uLCD.filled_circle(x,y,2.5, ex1);
+                uLCD.filled_circle(x,y,3.0, ex2);
+                uLCD.filled_circle(x,y,3.5, ex3);
+                uLCD.filled_circle(x,y,4.0, ex4);
+                uLCD.filled_circle(x,y,4.5, ex1);
+                uLCD.filled_circle(x,y,5.0, ex2);
+                uLCD.filled_circle(x,y,5.5, ex3);
+                uLCD.filled_circle(x,y,6.0, ex4);
+                uLCD.filled_circle(x,y,6.5, ex1);
+                uLCD.filled_circle(x,y,7.0, ex2);
+                uLCD.filled_circle(x,y,7.5, ex3);
+                uLCD.filled_circle(x,y,8.0, ex4);
+                
+                uLCD.filled_circle(x,y,8.0, BLACK);
+                uLCD.filled_circle(x,y,7.5, ex3);
+                //wait(.5);
+                uLCD.filled_circle(x,y,7.5, BLACK);
+                uLCD.filled_circle(x,y,7.0, ex2);
+                //wait(.5);
+                uLCD.filled_circle(x,y,7.0, BLACK);
+                uLCD.filled_circle(x,y,6.5, ex1);       
+                uLCD.filled_circle(x,y,6.5, BLACK);
+                uLCD.filled_circle(x,y,6.0, ex3);
+                //wait(.5);
+                uLCD.filled_circle(x,y,6.0, BLACK);
+                uLCD.filled_circle(x,y,5.5, ex2);
+                //wait(.5);
+                uLCD.filled_circle(x,y,5.5, BLACK);
+                uLCD.filled_circle(x,y,5.0, ex1);       
+                uLCD.filled_circle(x,y,5.0, BLACK);
+                uLCD.filled_circle(x,y,4.5, ex3);
+                //wait(.5);
+                uLCD.filled_circle(x,y,4.5, BLACK);
+                uLCD.filled_circle(x,y,4.0, ex2);
+                //wait(.5);
+                uLCD.filled_circle(x,y,4.0, BLACK);
+                uLCD.filled_circle(x,y,3.5, ex1);      
+                uLCD.filled_circle(x,y,3.5, BLACK);
+                uLCD.filled_circle(x,y,3.0, ex3);
+                //wait(.5);
+                uLCD.filled_circle(x,y,3.0, BLACK);
+                uLCD.filled_circle(x,y,2.5, ex2);
+                //wait(.5);
+                uLCD.filled_circle(x,y,2.5, BLACK);
+                uLCD.filled_circle(x,y,2.0, ex1);         //
+               // wait(.5);
+                uLCD.filled_circle(x,y,2.0, BLACK);
+                uLCD.filled_circle(x,y,1.5, ex3);
+                //wait(.5);
+                uLCD.filled_circle(x,y,1.5, BLACK);
+                uLCD.filled_circle(x,y,1.0, ex2);
+                //wait(.5);
+                uLCD.filled_circle(x,y,1.0, BLACK);
+                uLCD.filled_circle(x,y,.5, ex1);
+                //wait(.5);
+                uLCD.filled_circle(x,y,.5, BLACK);
+                playSound("/sd/wavfiles/hit.wav");
+                t=1;
+                //wait(1);
+                }
+            
+            if (t==1){
+                uLCD.cls();
+                uLCD.locate(4,2);
+                uLCD.puts("GAME OVER");
+                playSound("/sd/wavfiles/gameover.wav");
+                t=0;
+                wait(1);
+                uLCD.cls();
+                while (1){
+                    uLCD.media_init();
+                    uLCD.set_sector_address(0x003B, 0x5001);
+                    uLCD.display_image(0,0);
+                    if (!pb_l){
+                        goto Start;
+                        }
+                    }
 
-        // Get a pointer to the buttons for both sides.
-        // From now on, you can access the buttons for player x using
-        //
-        // px_buttons[U_BUTTON] 
-        // px_buttons[R_BUTTON] 
-        // px_buttons[D_BUTTON] 
-        // px_buttons[L_BUTTON]
-        
-        p1_buttons = sync.get_p1_buttons();
-        p2_buttons = sync.get_p2_buttons();
+            }
+            /*
+            if (cl==1){
+                cl=0;
+                uLCD.filled_rectangle(x-3,y-3,x+3,y+3, BLACK);
+                x=x-dx;
+                uLCD.filled_rectangle(x-3,y-3,x+3,y+3, STONE_COLOR);
+                pc.printf("C=%d\n",c);
+                if (b==0){
+                    uLCD.filled_rectangle(c-3,y-3,c+3,y+3,TREE_COLOR);
+                }
+            }*/
+            if (!pb_l){ //Move Left
+                c=x-dx;
+                a=uLCD.read_pixel(c, y);
+                b = TREE_COLOR;
+                b = pixel_eq(a, TREE_COLOR);
+                pc.printf("a= %d",a);
+                pc.printf("b= %d",b);
+                while (b==1){
+                    c=c-dx;
+                    a=uLCD.read_pixel(c, y);
+                    b = pixel_eq(a, TREE_COLOR);
+                    pc.printf("loop:b=%d",b);
+                    }
+                b = pixel_eq(a, LIGHTBLACK);
+                w= pixel_eq(a, YELLOW);
+                pc.printf("a2= %d",a);
+                pc.printf("b2:%d",b);
+                if (b==1||w==1){
+                    goto Main;
+                }
+                
+                a=uLCD.read_pixel(x-dx, y);
+                b = pixel_eq(a, BLACK);
+                
+                uLCD.filled_rectangle(x-3,y-3,x+3,y+3, BLACK);
+                x=x-dx;
+                uLCD.filled_rectangle(x-3,y-3,x+3,y+3, STONE_COLOR);
+                pc.printf("C=%d\n",c);
+                if (b==0){
+                    uLCD.filled_rectangle(c-3,y-3,c+3,y+3,TREE_COLOR);
+                }
+                
+            }
+            if (!pb_r){ //Move Right
+                c=x+dx;
+                a=uLCD.read_pixel(c, y);
+                b = TREE_COLOR;
+                b = pixel_eq(a, TREE_COLOR);
+                pc.printf("a= %d",a);
+                pc.printf("b= %d",b);
+                while (b==1){
+                    c=c+dx;
+                    a=uLCD.read_pixel(c, y);
+                    b = pixel_eq(a, TREE_COLOR);
+                    pc.printf("loop:b=%d",b);
+                    }
+                b = pixel_eq(a, LIGHTBLACK);
+                w= pixel_eq(a, YELLOW);
+                pc.printf("a2= %d",a);
+                pc.printf("b2:%d",b);
+                if (b==1||w==1){
+                    goto Main;
+                }
+                a=uLCD.read_pixel(x+dx, y);
+                b = pixel_eq(a, BLACK);
+                
+                uLCD.filled_rectangle(x-3,y-3,x+3,y+3, BLACK);
+                x=x+dx;
+                uLCD.filled_rectangle(x-3,y-3,x+3,y+3, STONE_COLOR);
+                pc.printf("C=%d\n",c);
+                
+                if (b==0){
+                    uLCD.filled_rectangle(c-3,y-3,c+3,y+3,TREE_COLOR);
+                }
+        }
+            if (!pb_d){ //Move Right
+                c=y+dy;
+                a=uLCD.read_pixel(x, c);
+                b = TREE_COLOR;
+                b = pixel_eq(a, TREE_COLOR);
+                pc.printf("a= %d",a);
+                pc.printf("b= %d",b);
+                while (b==1){
+                    c=c+dy;
+                    a=uLCD.read_pixel(x, c);
+                    b = pixel_eq(a, TREE_COLOR);
+                    pc.printf("loop:b=%d",b);
+                    }
+                b = pixel_eq(a, LIGHTBLACK);
+                w= pixel_eq(a, YELLOW);
+                pc.printf("a2= %d",a);
+                pc.printf("b2:%d",b);
+                if (b==1||w==1){
+                    goto Main;
+                }
+                a=uLCD.read_pixel(x, y+dy);
+                b = pixel_eq(a, BLACK);
+                
+                uLCD.filled_rectangle(x-3,y-3,x+3,y+3, BLACK);
+                y=y+dy;
+                uLCD.filled_rectangle(x-3,y-3,x+3,y+3, STONE_COLOR);
+                pc.printf("C=%d\n",c);
+                
+                if (b==0){
+                    uLCD.filled_rectangle(x-3,c-3,x+3,c+3,TREE_COLOR);
+                }
+        }   
+            if (!pb_u){ //Move Right
+                c=y-dy;
+                a=uLCD.read_pixel(x, c);
+                b = TREE_COLOR;
+                b = pixel_eq(a, TREE_COLOR);
+                pc.printf("a= %d",a);
+                pc.printf("b= %d",b);
+                while (b==1){
+                    c=c-dy;
+                    a=uLCD.read_pixel(x, c);
+                    b = pixel_eq(a, TREE_COLOR);
+                    pc.printf("loop:b=%d",b);
+                    }
+                b = pixel_eq(a, LIGHTBLACK);
+                w= pixel_eq(a, YELLOW);
+                pc.printf("a2= %d",a);
+                pc.printf("b2:%d",b);
+                if (b==1||w==1){
+                    goto Main;
+                }
+                a=uLCD.read_pixel(x, y-dy);
+                b = pixel_eq(a, BLACK);
+                
+                uLCD.filled_rectangle(x-3,y-3,x+3,y+3, BLACK);
+                y=y-dy;
+                uLCD.filled_rectangle(x-3,y-3,x+3,y+3, STONE_COLOR);
+                pc.printf("C=%d\n",c);
+                
+                if (b==0){
+                    uLCD.filled_rectangle(x-3,c-3,x+3,c+3,TREE_COLOR);
+                    pc.printf("b2=0 loop"); 
+                }
+        }   
         
-        led1 = p1_buttons[0] ^ p2_buttons[0];
-        led2 = p1_buttons[1] ^ p2_buttons[1];
-        led3 = p1_buttons[2] ^ p2_buttons[2];
-        led4 = p1_buttons[3] ^ p2_buttons[3];
+        //Cat Code 
+        z=rand()%8;
+        pc.printf("%d ",z);
+        wait(.005);
+        if (z==0 || z==4 || z==7){ //Move Left
+               
+                cc=cx-dx;
+                a=uLCD.read_pixel(cc, cy);
+                NL = pixel_eq(a, BLACK);
+                if (NL==1){
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
+                    cx=cx-dx;
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
+                    pc.printf("C=%d\n",cc);
+                }
+
+                t = pixel_eq(a, STONE_COLOR);
+
+            }
+        if (z==1 || z==5 ||z==6){ //Move Right
+                cc=cx+dx;
+                a=uLCD.read_pixel(cc, cy);
+                NR = pixel_eq(a, BLACK);
+                if (NR==1){
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
+                    cx=cx+dx;
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
+                    pc.printf("C=%d\n",cc);
+                }
 
-        // Get the accelerometer values.
-        sync.get_p1_accel_data(&ax1, &ay1, &az1);
-        sync.get_p2_accel_data(&ax2, &ay2, &az2);
+                t = pixel_eq(a, STONE_COLOR);
 
-        if(whose_turn == PLAYER1) {
-            
-            // Accelerometer example
-            if(ax1 >  ACC_THRESHOLD) { 
-                // Move the tank to the right if the accelerometer is tipped far enough to the right.
-                 t1.reposition(+1, 0, 0);          
+            }
+        if (z==2|| z==4 || z==5){ //Move up
+                cc=cy-dy;
+                a=uLCD.read_pixel(cx, cc);
+                NU = pixel_eq(a, BLACK);
+                if (NU==1){
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
+                    cy=cy-dy;
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
+                    pc.printf("C=%d\n",cc);
+                }
+              
+                t = pixel_eq(a, STONE_COLOR);
+
+            }
+        if (z==3 || z==6 || z==7){ //Move Down
+                cc=cy+dy;
+                a=uLCD.read_pixel(cx, cc);
+                ND = pixel_eq(a, BLACK);
+                if (ND==1){
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
+                    cy=cy+dy;
+                    uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
+                    pc.printf("C=%d\n",cc);
+                }
+
+                t = pixel_eq(a, STONE_COLOR);
+
             }
             
-            // Button example
-            if(p1_buttons[D_BUTTON]) { 
-                b1.shoot(); 
-            }
-            
-            float dt = frame_timer.read();
-            int intersection_code = b1.time_step(dt); 
-            
-            if(intersection_code != BULLET_NO_COLLISION || intersection_code == BULLET_OFF_SCREEN) { 
-                pc.printf("Now it's P2's turn!\n");
-                whose_turn = PLAYER2;
-            }
-            
-            // If you shot yourself, you lost.
-            if(sync.pixel_eq(intersection_code, t1.tank_color)) { 
-                sync.update();  // Is this necessary?
-                winner = PLAYER2;
-                break;
-            }
-            
-            // If you shot the other guy, you won!
-            if(sync.pixel_eq(intersection_code, t2.tank_color)) { 
-                sync.update();
-                winner = PLAYER1;
-                break;
-            }
-        } else if(whose_turn == PLAYER2) {
-            
-            // I gave you a lot of the logic for Player1. It's up to you to figure out Player2!
-            // If you are in SINGLE_PLAYER mode, you should use the p1 inputs to control p2.
-            // In MULTI_PLAYER mode, you should use the p2 inputs to control p2.
-            //
-            // Hint: 
-            //         sync.play_mode will tell you if you are in MULTI_PLAYER or SINGLE_PLAYER mode.
-            //         
-
-        }
-
-        frame_timer.reset();
-        sync.update();     
-    } 
-    
-    game_over();
-    
-}
\ No newline at end of file
+            //CHECK PICS AROUND CAT
+            N=uLCD.read_pixel(cx, cy+6);
+            N1 = pixel_eq(N, TREE_COLOR);
+            N2 = pixel_eq(N, LIGHTBLACK);
+            if (N1==1||N2==1){
+                NU=2;
+                }
+            S=uLCD.read_pixel(cx, cy-6);
+            S1 = pixel_eq(S, TREE_COLOR);
+            S2 = pixel_eq(S, LIGHTBLACK);
+            if (S1==1||S2==1){
+                ND=2;
+                }
+            E=uLCD.read_pixel(cx+6, cy);
+            E1 = pixel_eq(E, TREE_COLOR);
+            E2 = pixel_eq(E, LIGHTBLACK);
+            if (E1==1||E2==1){
+                NR=2;
+                }
+            W=uLCD.read_pixel(cx-6, cy);
+            W1 = pixel_eq(W, TREE_COLOR);
+            W2 = pixel_eq(W, LIGHTBLACK);
+            if (W1==1||W2==1){
+                NL=2;
+                }
+                
+        pc.printf("NR=%d",NR);
+        pc.printf("NL=%d", NL);
+        pc.printf("NU=%d", NU);
+        pc.printf("ND=%d", ND);
+        if (NL==2 && NR==2 && NU==2 && ND==2){
+            uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, TANK_RED);
+            count++;
+            if (count==1){
+                wait(3);
+                uLCD.cls();
+                uLCD.locate(4,2);
+                uLCD.puts("Winner!!");
+                t=0;
+                wait(3);
+                while (1){
+                    if (!pb_l){
+                        goto Start;
+                    }
+                }
+                }
+                  
+            }         
+        }    
+    }