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

Committer:
eriklomas
Date:
Tue Nov 01 18:59:29 2016 +0000
Revision:
28:fdaa7ecfbd80
Parent:
27:bd55ab4d137c
4180;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jford38 6:3be57cf4bd33 1 // Student Side.
jford38 0:899c85cd266f 2
jford38 0:899c85cd266f 3 #include "mbed.h"
jford38 15:4b27a3a95772 4
jford38 17:7bc7127782e4 5 #include "SDFileSystem.h"
jford38 17:7bc7127782e4 6 #include "wave_player.h"
jford38 6:3be57cf4bd33 7 #include "game_synchronizer.h"
jford38 27:bd55ab4d137c 8 #include "globals.h"
eriklomas 28:fdaa7ecfbd80 9 #include "playSound.h"
eriklomas 28:fdaa7ecfbd80 10 #include "rtos.h"
eriklomas 28:fdaa7ecfbd80 11 #include "uLCD_4DGL.h"
eriklomas 28:fdaa7ecfbd80 12 #define VOLUME 0.03
eriklomas 28:fdaa7ecfbd80 13 #define BPM 100.0
jford38 17:7bc7127782e4 14
jford38 6:3be57cf4bd33 15
jford38 17:7bc7127782e4 16 Serial pc(USBTX, USBRX); // Serial connection to PC. Useful for debugging!
jford38 17:7bc7127782e4 17 MMA8452 acc(p28, p27, 100000); // Accelerometer (SDA, SCL, Baudrate)
jford38 17:7bc7127782e4 18 uLCD_4DGL uLCD(p9,p10,p11); // LCD (tx, rx, reset)
jford38 17:7bc7127782e4 19 SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD (mosi, miso, sck, cs)
jford38 17:7bc7127782e4 20 AnalogOut DACout(p18); // speaker
jford38 17:7bc7127782e4 21 wave_player player(&DACout); // wav player
jford38 0:899c85cd266f 22
eriklomas 28:fdaa7ecfbd80 23 DigitalIn pb_u(p22); // Up Button
eriklomas 28:fdaa7ecfbd80 24 DigitalIn pb_r(p24); // Right Button
eriklomas 28:fdaa7ecfbd80 25 DigitalIn pb_d(p23); // Down Button
eriklomas 28:fdaa7ecfbd80 26 DigitalIn pb_l(p21); // Left Button
eriklomas 28:fdaa7ecfbd80 27 DigitalIn pb_c(p25);
eriklomas 28:fdaa7ecfbd80 28
eriklomas 28:fdaa7ecfbd80 29 PwmOut pwm_pin(p26);
jford38 22:3c68eea5a609 30
eriklomas 28:fdaa7ecfbd80 31 //InterruptIn button(p21);
jford38 20:6a58052b0140 32
eriklomas 28:fdaa7ecfbd80 33 int ND=0, NU=0, NL=0, NR=0;
eriklomas 28:fdaa7ecfbd80 34 int dx=6;
eriklomas 28:fdaa7ecfbd80 35 int dy=6;
eriklomas 28:fdaa7ecfbd80 36 int a,b,c,d;
eriklomas 28:fdaa7ecfbd80 37 int i,z;
eriklomas 28:fdaa7ecfbd80 38 int cc;
eriklomas 28:fdaa7ecfbd80 39 int w;
jford38 22:3c68eea5a609 40
eriklomas 28:fdaa7ecfbd80 41 int N,E,S,W,N1,N2,E1,E2,S1,S2,W1,W2;
eriklomas 28:fdaa7ecfbd80 42
eriklomas 28:fdaa7ecfbd80 43 int CONVERT_24_TO_16_BPP(int col_24) {
eriklomas 28:fdaa7ecfbd80 44 int p = col_24 & 0xFF;
eriklomas 28:fdaa7ecfbd80 45 int g = (col_24 >> 8) & 0xFF;
eriklomas 28:fdaa7ecfbd80 46 int r = (col_24 >> 16)& 0xFF;
jford38 22:3c68eea5a609 47
eriklomas 28:fdaa7ecfbd80 48 r >>= 3;
eriklomas 28:fdaa7ecfbd80 49 g >>= 2;
eriklomas 28:fdaa7ecfbd80 50 p >>= 3;
eriklomas 28:fdaa7ecfbd80 51
eriklomas 28:fdaa7ecfbd80 52 return r<<11 | g<<5 | p;
eriklomas 28:fdaa7ecfbd80 53 }
jford38 17:7bc7127782e4 54
eriklomas 28:fdaa7ecfbd80 55 bool pixel_eq(int color1, int color2) {
eriklomas 28:fdaa7ecfbd80 56 return (CONVERT_24_TO_16_BPP(color1) == color2 ||
eriklomas 28:fdaa7ecfbd80 57 CONVERT_24_TO_16_BPP(color2) == color1 ||
eriklomas 28:fdaa7ecfbd80 58 color1 == color2);
jford38 7:9506f2d84162 59 }
jford38 7:9506f2d84162 60
eriklomas 28:fdaa7ecfbd80 61 /*
eriklomas 28:fdaa7ecfbd80 62 void thread1(void const *args)
eriklomas 28:fdaa7ecfbd80 63 {
eriklomas 28:fdaa7ecfbd80 64 while(true) { // thread loop
eriklomas 28:fdaa7ecfbd80 65 z=rand()%8;
eriklomas 28:fdaa7ecfbd80 66 pc.printf("%d ",z);
eriklomas 28:fdaa7ecfbd80 67 Thread::wait(500); // wait 0.5s
eriklomas 28:fdaa7ecfbd80 68 if (z==0 || z==4 || z==7){ //Move Left
eriklomas 28:fdaa7ecfbd80 69 cc=cx-dx;
eriklomas 28:fdaa7ecfbd80 70 a=uLCD.read_pixel(cc, cy);
eriklomas 28:fdaa7ecfbd80 71 b = pixel_eq(a, BLACK);
eriklomas 28:fdaa7ecfbd80 72 if (b==1){
eriklomas 28:fdaa7ecfbd80 73 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
eriklomas 28:fdaa7ecfbd80 74 cx=cx-dx;
eriklomas 28:fdaa7ecfbd80 75 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
eriklomas 28:fdaa7ecfbd80 76 pc.printf("C=%d\n",cc);
eriklomas 28:fdaa7ecfbd80 77 }
eriklomas 28:fdaa7ecfbd80 78 t = pixel_eq(a, STONE_COLOR);
eriklomas 28:fdaa7ecfbd80 79
eriklomas 28:fdaa7ecfbd80 80 }
eriklomas 28:fdaa7ecfbd80 81 if (z==1 || z==5 ||z==6){ //Move Right
eriklomas 28:fdaa7ecfbd80 82 cc=cx+dx;
eriklomas 28:fdaa7ecfbd80 83 a=uLCD.read_pixel(cc, cy);
eriklomas 28:fdaa7ecfbd80 84 b = pixel_eq(a, BLACK);
eriklomas 28:fdaa7ecfbd80 85 if (b==1){
eriklomas 28:fdaa7ecfbd80 86 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
eriklomas 28:fdaa7ecfbd80 87 cx=cx+dx;
eriklomas 28:fdaa7ecfbd80 88 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
eriklomas 28:fdaa7ecfbd80 89 pc.printf("C=%d\n",cc);
eriklomas 28:fdaa7ecfbd80 90 }
eriklomas 28:fdaa7ecfbd80 91 t = pixel_eq(a, STONE_COLOR);
eriklomas 28:fdaa7ecfbd80 92
eriklomas 28:fdaa7ecfbd80 93 }
eriklomas 28:fdaa7ecfbd80 94 if (z==2|| z==4 || z==5){ //Move up
eriklomas 28:fdaa7ecfbd80 95 cc=cy-dy;
eriklomas 28:fdaa7ecfbd80 96 a=uLCD.read_pixel(cx, cc);
eriklomas 28:fdaa7ecfbd80 97 b = pixel_eq(a, BLACK);
eriklomas 28:fdaa7ecfbd80 98 if (b==1){
eriklomas 28:fdaa7ecfbd80 99 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
eriklomas 28:fdaa7ecfbd80 100 cy=cy-dy;
eriklomas 28:fdaa7ecfbd80 101 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
eriklomas 28:fdaa7ecfbd80 102 pc.printf("C=%d\n",cc);
eriklomas 28:fdaa7ecfbd80 103 }
eriklomas 28:fdaa7ecfbd80 104 t = pixel_eq(a, STONE_COLOR);
eriklomas 28:fdaa7ecfbd80 105
eriklomas 28:fdaa7ecfbd80 106 }
eriklomas 28:fdaa7ecfbd80 107 if (z==3 || z==6 || z==7){ //Move Down
eriklomas 28:fdaa7ecfbd80 108 cc=cy+dy;
eriklomas 28:fdaa7ecfbd80 109 a=uLCD.read_pixel(cx, cc);
eriklomas 28:fdaa7ecfbd80 110 b = pixel_eq(a, BLACK);
eriklomas 28:fdaa7ecfbd80 111 if (b==1){
eriklomas 28:fdaa7ecfbd80 112 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
eriklomas 28:fdaa7ecfbd80 113 cy=cy+dy;
eriklomas 28:fdaa7ecfbd80 114 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
eriklomas 28:fdaa7ecfbd80 115 pc.printf("C=%d\n",cc);
eriklomas 28:fdaa7ecfbd80 116 }
eriklomas 28:fdaa7ecfbd80 117 t = pixel_eq(a, STONE_COLOR);
eriklomas 28:fdaa7ecfbd80 118
eriklomas 28:fdaa7ecfbd80 119 }
eriklomas 28:fdaa7ecfbd80 120 }
jford38 10:5da9b27e050e 121 }
eriklomas 28:fdaa7ecfbd80 122 */
jford38 10:5da9b27e050e 123
eriklomas 28:fdaa7ecfbd80 124 /*int cl=1;
jford38 6:3be57cf4bd33 125
eriklomas 28:fdaa7ecfbd80 126 void flip(void) {
eriklomas 28:fdaa7ecfbd80 127 c=x-dx;
eriklomas 28:fdaa7ecfbd80 128 a=uLCD.read_pixel(c, y);
eriklomas 28:fdaa7ecfbd80 129 b = TREE_COLOR;
eriklomas 28:fdaa7ecfbd80 130 b = pixel_eq(a, TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 131 pc.printf("a= %d",a);
eriklomas 28:fdaa7ecfbd80 132 pc.printf("b= %d",b);
eriklomas 28:fdaa7ecfbd80 133 while (b==1){
eriklomas 28:fdaa7ecfbd80 134 c=c-dx;
eriklomas 28:fdaa7ecfbd80 135 a=uLCD.read_pixel(c, y);
eriklomas 28:fdaa7ecfbd80 136 b = pixel_eq(a, TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 137 pc.printf("loop:b=%d",b);
eriklomas 28:fdaa7ecfbd80 138 }
eriklomas 28:fdaa7ecfbd80 139 b = pixel_eq(a, LIGHTBLACK);
eriklomas 28:fdaa7ecfbd80 140 pc.printf("a2= %d",a);
eriklomas 28:fdaa7ecfbd80 141 pc.printf("b2:%d",b);
eriklomas 28:fdaa7ecfbd80 142 if (b==1){
eriklomas 28:fdaa7ecfbd80 143 goto Main;
eriklomas 28:fdaa7ecfbd80 144 }
eriklomas 28:fdaa7ecfbd80 145
eriklomas 28:fdaa7ecfbd80 146 a=uLCD.read_pixel(x-dx, y);
eriklomas 28:fdaa7ecfbd80 147 b = pixel_eq(a, BLACK);
eriklomas 28:fdaa7ecfbd80 148 cl=1;
eriklomas 28:fdaa7ecfbd80 149 Main:
eriklomas 28:fdaa7ecfbd80 150 }*/
eriklomas 28:fdaa7ecfbd80 151
eriklomas 28:fdaa7ecfbd80 152 void thread1(void const *args)
eriklomas 28:fdaa7ecfbd80 153 {
eriklomas 28:fdaa7ecfbd80 154 while(true) { // thread loop
eriklomas 28:fdaa7ecfbd80 155 playSound("/sd/wavfiles/minecraft0.wav");
eriklomas 28:fdaa7ecfbd80 156 }
jford38 19:7aa3af04d6a8 157 }
jford38 19:7aa3af04d6a8 158
jford38 21:edfeb289b21f 159
eriklomas 28:fdaa7ecfbd80 160 int main(){
eriklomas 28:fdaa7ecfbd80 161 Start: uLCD.cls();
eriklomas 28:fdaa7ecfbd80 162 pb_l.mode(PullUp);
eriklomas 28:fdaa7ecfbd80 163 pb_r.mode(PullUp);
eriklomas 28:fdaa7ecfbd80 164 pb_u.mode(PullUp);
eriklomas 28:fdaa7ecfbd80 165 pb_d.mode(PullUp);
eriklomas 28:fdaa7ecfbd80 166 pb_c.mode(PullUp);
eriklomas 28:fdaa7ecfbd80 167
eriklomas 28:fdaa7ecfbd80 168 int x=64;
eriklomas 28:fdaa7ecfbd80 169 int y=64;
eriklomas 28:fdaa7ecfbd80 170 int cx=16;
eriklomas 28:fdaa7ecfbd80 171 int cy=64;
eriklomas 28:fdaa7ecfbd80 172 int count=0;
eriklomas 28:fdaa7ecfbd80 173 int t=0;
eriklomas 28:fdaa7ecfbd80 174 /*
eriklomas 28:fdaa7ecfbd80 175 button.mode(PullUp);
eriklomas 28:fdaa7ecfbd80 176 wait(.01);
eriklomas 28:fdaa7ecfbd80 177 button.fall(&flip);
eriklomas 28:fdaa7ecfbd80 178 */
eriklomas 28:fdaa7ecfbd80 179 //Main outer ring
eriklomas 28:fdaa7ecfbd80 180 uLCD.filled_rectangle(0,0,128,6, LIGHTBLACK); //MAKE STONE COLOR (LIGHT GRAY)
eriklomas 28:fdaa7ecfbd80 181 uLCD.filled_rectangle(0,0,6,128, LIGHTBLACK); //STONE COLOR
eriklomas 28:fdaa7ecfbd80 182 uLCD.filled_rectangle(0,122,128,128, LIGHTBLACK); //STONE COLOR
eriklomas 28:fdaa7ecfbd80 183 uLCD.filled_rectangle(122,0,128,128, LIGHTBLACK); //STONE COLOR
eriklomas 28:fdaa7ecfbd80 184
eriklomas 28:fdaa7ecfbd80 185 //inner ring
eriklomas 28:fdaa7ecfbd80 186 uLCD.filled_rectangle(26,26,102,102,TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 187
eriklomas 28:fdaa7ecfbd80 188 //mouse
eriklomas 28:fdaa7ecfbd80 189 uLCD.filled_rectangle(61,61,67,67, STONE_COLOR);
eriklomas 28:fdaa7ecfbd80 190
eriklomas 28:fdaa7ecfbd80 191 //cat
eriklomas 28:fdaa7ecfbd80 192 uLCD.filled_rectangle(13,61,19,67, YELLOW);
eriklomas 28:fdaa7ecfbd80 193
eriklomas 28:fdaa7ecfbd80 194 Thread t1(thread1); //start thread4
eriklomas 28:fdaa7ecfbd80 195 pc.printf("before main");
eriklomas 28:fdaa7ecfbd80 196
eriklomas 28:fdaa7ecfbd80 197 Main: while(1) {
eriklomas 28:fdaa7ecfbd80 198
eriklomas 28:fdaa7ecfbd80 199 ND=0;
eriklomas 28:fdaa7ecfbd80 200 NU=0;
eriklomas 28:fdaa7ecfbd80 201 NL=0;
eriklomas 28:fdaa7ecfbd80 202 NR=0;
eriklomas 28:fdaa7ecfbd80 203 pc.printf("aftre main");
eriklomas 28:fdaa7ecfbd80 204 if (!pb_c){
eriklomas 28:fdaa7ecfbd80 205 uLCD.filled_circle(x,y,.5, ex1);
eriklomas 28:fdaa7ecfbd80 206 //wait(.5);
eriklomas 28:fdaa7ecfbd80 207 uLCD.filled_circle(x,y,1.0, ex2);
eriklomas 28:fdaa7ecfbd80 208 //wait(.5);
eriklomas 28:fdaa7ecfbd80 209 uLCD.filled_circle(x,y,1.5, ex3);
eriklomas 28:fdaa7ecfbd80 210 //wait(.5);
eriklomas 28:fdaa7ecfbd80 211 uLCD.filled_circle(x,y,2.0, ex4);
eriklomas 28:fdaa7ecfbd80 212 uLCD.filled_circle(x,y,2.5, ex1);
eriklomas 28:fdaa7ecfbd80 213 uLCD.filled_circle(x,y,3.0, ex2);
eriklomas 28:fdaa7ecfbd80 214 uLCD.filled_circle(x,y,3.5, ex3);
eriklomas 28:fdaa7ecfbd80 215 uLCD.filled_circle(x,y,4.0, ex4);
eriklomas 28:fdaa7ecfbd80 216 uLCD.filled_circle(x,y,4.5, ex1);
eriklomas 28:fdaa7ecfbd80 217 uLCD.filled_circle(x,y,5.0, ex2);
eriklomas 28:fdaa7ecfbd80 218 uLCD.filled_circle(x,y,5.5, ex3);
eriklomas 28:fdaa7ecfbd80 219 uLCD.filled_circle(x,y,6.0, ex4);
eriklomas 28:fdaa7ecfbd80 220 uLCD.filled_circle(x,y,6.5, ex1);
eriklomas 28:fdaa7ecfbd80 221 uLCD.filled_circle(x,y,7.0, ex2);
eriklomas 28:fdaa7ecfbd80 222 uLCD.filled_circle(x,y,7.5, ex3);
eriklomas 28:fdaa7ecfbd80 223 uLCD.filled_circle(x,y,8.0, ex4);
eriklomas 28:fdaa7ecfbd80 224
eriklomas 28:fdaa7ecfbd80 225 uLCD.filled_circle(x,y,8.0, BLACK);
eriklomas 28:fdaa7ecfbd80 226 uLCD.filled_circle(x,y,7.5, ex3);
eriklomas 28:fdaa7ecfbd80 227 //wait(.5);
eriklomas 28:fdaa7ecfbd80 228 uLCD.filled_circle(x,y,7.5, BLACK);
eriklomas 28:fdaa7ecfbd80 229 uLCD.filled_circle(x,y,7.0, ex2);
eriklomas 28:fdaa7ecfbd80 230 //wait(.5);
eriklomas 28:fdaa7ecfbd80 231 uLCD.filled_circle(x,y,7.0, BLACK);
eriklomas 28:fdaa7ecfbd80 232 uLCD.filled_circle(x,y,6.5, ex1);
eriklomas 28:fdaa7ecfbd80 233 uLCD.filled_circle(x,y,6.5, BLACK);
eriklomas 28:fdaa7ecfbd80 234 uLCD.filled_circle(x,y,6.0, ex3);
eriklomas 28:fdaa7ecfbd80 235 //wait(.5);
eriklomas 28:fdaa7ecfbd80 236 uLCD.filled_circle(x,y,6.0, BLACK);
eriklomas 28:fdaa7ecfbd80 237 uLCD.filled_circle(x,y,5.5, ex2);
eriklomas 28:fdaa7ecfbd80 238 //wait(.5);
eriklomas 28:fdaa7ecfbd80 239 uLCD.filled_circle(x,y,5.5, BLACK);
eriklomas 28:fdaa7ecfbd80 240 uLCD.filled_circle(x,y,5.0, ex1);
eriklomas 28:fdaa7ecfbd80 241 uLCD.filled_circle(x,y,5.0, BLACK);
eriklomas 28:fdaa7ecfbd80 242 uLCD.filled_circle(x,y,4.5, ex3);
eriklomas 28:fdaa7ecfbd80 243 //wait(.5);
eriklomas 28:fdaa7ecfbd80 244 uLCD.filled_circle(x,y,4.5, BLACK);
eriklomas 28:fdaa7ecfbd80 245 uLCD.filled_circle(x,y,4.0, ex2);
eriklomas 28:fdaa7ecfbd80 246 //wait(.5);
eriklomas 28:fdaa7ecfbd80 247 uLCD.filled_circle(x,y,4.0, BLACK);
eriklomas 28:fdaa7ecfbd80 248 uLCD.filled_circle(x,y,3.5, ex1);
eriklomas 28:fdaa7ecfbd80 249 uLCD.filled_circle(x,y,3.5, BLACK);
eriklomas 28:fdaa7ecfbd80 250 uLCD.filled_circle(x,y,3.0, ex3);
eriklomas 28:fdaa7ecfbd80 251 //wait(.5);
eriklomas 28:fdaa7ecfbd80 252 uLCD.filled_circle(x,y,3.0, BLACK);
eriklomas 28:fdaa7ecfbd80 253 uLCD.filled_circle(x,y,2.5, ex2);
eriklomas 28:fdaa7ecfbd80 254 //wait(.5);
eriklomas 28:fdaa7ecfbd80 255 uLCD.filled_circle(x,y,2.5, BLACK);
eriklomas 28:fdaa7ecfbd80 256 uLCD.filled_circle(x,y,2.0, ex1); //
eriklomas 28:fdaa7ecfbd80 257 // wait(.5);
eriklomas 28:fdaa7ecfbd80 258 uLCD.filled_circle(x,y,2.0, BLACK);
eriklomas 28:fdaa7ecfbd80 259 uLCD.filled_circle(x,y,1.5, ex3);
eriklomas 28:fdaa7ecfbd80 260 //wait(.5);
eriklomas 28:fdaa7ecfbd80 261 uLCD.filled_circle(x,y,1.5, BLACK);
eriklomas 28:fdaa7ecfbd80 262 uLCD.filled_circle(x,y,1.0, ex2);
eriklomas 28:fdaa7ecfbd80 263 //wait(.5);
eriklomas 28:fdaa7ecfbd80 264 uLCD.filled_circle(x,y,1.0, BLACK);
eriklomas 28:fdaa7ecfbd80 265 uLCD.filled_circle(x,y,.5, ex1);
eriklomas 28:fdaa7ecfbd80 266 //wait(.5);
eriklomas 28:fdaa7ecfbd80 267 uLCD.filled_circle(x,y,.5, BLACK);
eriklomas 28:fdaa7ecfbd80 268 playSound("/sd/wavfiles/hit.wav");
eriklomas 28:fdaa7ecfbd80 269 t=1;
eriklomas 28:fdaa7ecfbd80 270 //wait(1);
eriklomas 28:fdaa7ecfbd80 271 }
eriklomas 28:fdaa7ecfbd80 272
eriklomas 28:fdaa7ecfbd80 273 if (t==1){
eriklomas 28:fdaa7ecfbd80 274 uLCD.cls();
eriklomas 28:fdaa7ecfbd80 275 uLCD.locate(4,2);
eriklomas 28:fdaa7ecfbd80 276 uLCD.puts("GAME OVER");
eriklomas 28:fdaa7ecfbd80 277 playSound("/sd/wavfiles/gameover.wav");
eriklomas 28:fdaa7ecfbd80 278 t=0;
eriklomas 28:fdaa7ecfbd80 279 wait(1);
eriklomas 28:fdaa7ecfbd80 280 uLCD.cls();
eriklomas 28:fdaa7ecfbd80 281 while (1){
eriklomas 28:fdaa7ecfbd80 282 uLCD.media_init();
eriklomas 28:fdaa7ecfbd80 283 uLCD.set_sector_address(0x003B, 0x5001);
eriklomas 28:fdaa7ecfbd80 284 uLCD.display_image(0,0);
eriklomas 28:fdaa7ecfbd80 285 if (!pb_l){
eriklomas 28:fdaa7ecfbd80 286 goto Start;
eriklomas 28:fdaa7ecfbd80 287 }
eriklomas 28:fdaa7ecfbd80 288 }
jford38 24:2100c9e8ec81 289
eriklomas 28:fdaa7ecfbd80 290 }
eriklomas 28:fdaa7ecfbd80 291 /*
eriklomas 28:fdaa7ecfbd80 292 if (cl==1){
eriklomas 28:fdaa7ecfbd80 293 cl=0;
eriklomas 28:fdaa7ecfbd80 294 uLCD.filled_rectangle(x-3,y-3,x+3,y+3, BLACK);
eriklomas 28:fdaa7ecfbd80 295 x=x-dx;
eriklomas 28:fdaa7ecfbd80 296 uLCD.filled_rectangle(x-3,y-3,x+3,y+3, STONE_COLOR);
eriklomas 28:fdaa7ecfbd80 297 pc.printf("C=%d\n",c);
eriklomas 28:fdaa7ecfbd80 298 if (b==0){
eriklomas 28:fdaa7ecfbd80 299 uLCD.filled_rectangle(c-3,y-3,c+3,y+3,TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 300 }
eriklomas 28:fdaa7ecfbd80 301 }*/
eriklomas 28:fdaa7ecfbd80 302 if (!pb_l){ //Move Left
eriklomas 28:fdaa7ecfbd80 303 c=x-dx;
eriklomas 28:fdaa7ecfbd80 304 a=uLCD.read_pixel(c, y);
eriklomas 28:fdaa7ecfbd80 305 b = TREE_COLOR;
eriklomas 28:fdaa7ecfbd80 306 b = pixel_eq(a, TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 307 pc.printf("a= %d",a);
eriklomas 28:fdaa7ecfbd80 308 pc.printf("b= %d",b);
eriklomas 28:fdaa7ecfbd80 309 while (b==1){
eriklomas 28:fdaa7ecfbd80 310 c=c-dx;
eriklomas 28:fdaa7ecfbd80 311 a=uLCD.read_pixel(c, y);
eriklomas 28:fdaa7ecfbd80 312 b = pixel_eq(a, TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 313 pc.printf("loop:b=%d",b);
eriklomas 28:fdaa7ecfbd80 314 }
eriklomas 28:fdaa7ecfbd80 315 b = pixel_eq(a, LIGHTBLACK);
eriklomas 28:fdaa7ecfbd80 316 w= pixel_eq(a, YELLOW);
eriklomas 28:fdaa7ecfbd80 317 pc.printf("a2= %d",a);
eriklomas 28:fdaa7ecfbd80 318 pc.printf("b2:%d",b);
eriklomas 28:fdaa7ecfbd80 319 if (b==1||w==1){
eriklomas 28:fdaa7ecfbd80 320 goto Main;
eriklomas 28:fdaa7ecfbd80 321 }
eriklomas 28:fdaa7ecfbd80 322
eriklomas 28:fdaa7ecfbd80 323 a=uLCD.read_pixel(x-dx, y);
eriklomas 28:fdaa7ecfbd80 324 b = pixel_eq(a, BLACK);
eriklomas 28:fdaa7ecfbd80 325
eriklomas 28:fdaa7ecfbd80 326 uLCD.filled_rectangle(x-3,y-3,x+3,y+3, BLACK);
eriklomas 28:fdaa7ecfbd80 327 x=x-dx;
eriklomas 28:fdaa7ecfbd80 328 uLCD.filled_rectangle(x-3,y-3,x+3,y+3, STONE_COLOR);
eriklomas 28:fdaa7ecfbd80 329 pc.printf("C=%d\n",c);
eriklomas 28:fdaa7ecfbd80 330 if (b==0){
eriklomas 28:fdaa7ecfbd80 331 uLCD.filled_rectangle(c-3,y-3,c+3,y+3,TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 332 }
eriklomas 28:fdaa7ecfbd80 333
eriklomas 28:fdaa7ecfbd80 334 }
eriklomas 28:fdaa7ecfbd80 335 if (!pb_r){ //Move Right
eriklomas 28:fdaa7ecfbd80 336 c=x+dx;
eriklomas 28:fdaa7ecfbd80 337 a=uLCD.read_pixel(c, y);
eriklomas 28:fdaa7ecfbd80 338 b = TREE_COLOR;
eriklomas 28:fdaa7ecfbd80 339 b = pixel_eq(a, TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 340 pc.printf("a= %d",a);
eriklomas 28:fdaa7ecfbd80 341 pc.printf("b= %d",b);
eriklomas 28:fdaa7ecfbd80 342 while (b==1){
eriklomas 28:fdaa7ecfbd80 343 c=c+dx;
eriklomas 28:fdaa7ecfbd80 344 a=uLCD.read_pixel(c, y);
eriklomas 28:fdaa7ecfbd80 345 b = pixel_eq(a, TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 346 pc.printf("loop:b=%d",b);
eriklomas 28:fdaa7ecfbd80 347 }
eriklomas 28:fdaa7ecfbd80 348 b = pixel_eq(a, LIGHTBLACK);
eriklomas 28:fdaa7ecfbd80 349 w= pixel_eq(a, YELLOW);
eriklomas 28:fdaa7ecfbd80 350 pc.printf("a2= %d",a);
eriklomas 28:fdaa7ecfbd80 351 pc.printf("b2:%d",b);
eriklomas 28:fdaa7ecfbd80 352 if (b==1||w==1){
eriklomas 28:fdaa7ecfbd80 353 goto Main;
eriklomas 28:fdaa7ecfbd80 354 }
eriklomas 28:fdaa7ecfbd80 355 a=uLCD.read_pixel(x+dx, y);
eriklomas 28:fdaa7ecfbd80 356 b = pixel_eq(a, BLACK);
eriklomas 28:fdaa7ecfbd80 357
eriklomas 28:fdaa7ecfbd80 358 uLCD.filled_rectangle(x-3,y-3,x+3,y+3, BLACK);
eriklomas 28:fdaa7ecfbd80 359 x=x+dx;
eriklomas 28:fdaa7ecfbd80 360 uLCD.filled_rectangle(x-3,y-3,x+3,y+3, STONE_COLOR);
eriklomas 28:fdaa7ecfbd80 361 pc.printf("C=%d\n",c);
eriklomas 28:fdaa7ecfbd80 362
eriklomas 28:fdaa7ecfbd80 363 if (b==0){
eriklomas 28:fdaa7ecfbd80 364 uLCD.filled_rectangle(c-3,y-3,c+3,y+3,TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 365 }
eriklomas 28:fdaa7ecfbd80 366 }
eriklomas 28:fdaa7ecfbd80 367 if (!pb_d){ //Move Right
eriklomas 28:fdaa7ecfbd80 368 c=y+dy;
eriklomas 28:fdaa7ecfbd80 369 a=uLCD.read_pixel(x, c);
eriklomas 28:fdaa7ecfbd80 370 b = TREE_COLOR;
eriklomas 28:fdaa7ecfbd80 371 b = pixel_eq(a, TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 372 pc.printf("a= %d",a);
eriklomas 28:fdaa7ecfbd80 373 pc.printf("b= %d",b);
eriklomas 28:fdaa7ecfbd80 374 while (b==1){
eriklomas 28:fdaa7ecfbd80 375 c=c+dy;
eriklomas 28:fdaa7ecfbd80 376 a=uLCD.read_pixel(x, c);
eriklomas 28:fdaa7ecfbd80 377 b = pixel_eq(a, TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 378 pc.printf("loop:b=%d",b);
eriklomas 28:fdaa7ecfbd80 379 }
eriklomas 28:fdaa7ecfbd80 380 b = pixel_eq(a, LIGHTBLACK);
eriklomas 28:fdaa7ecfbd80 381 w= pixel_eq(a, YELLOW);
eriklomas 28:fdaa7ecfbd80 382 pc.printf("a2= %d",a);
eriklomas 28:fdaa7ecfbd80 383 pc.printf("b2:%d",b);
eriklomas 28:fdaa7ecfbd80 384 if (b==1||w==1){
eriklomas 28:fdaa7ecfbd80 385 goto Main;
eriklomas 28:fdaa7ecfbd80 386 }
eriklomas 28:fdaa7ecfbd80 387 a=uLCD.read_pixel(x, y+dy);
eriklomas 28:fdaa7ecfbd80 388 b = pixel_eq(a, BLACK);
eriklomas 28:fdaa7ecfbd80 389
eriklomas 28:fdaa7ecfbd80 390 uLCD.filled_rectangle(x-3,y-3,x+3,y+3, BLACK);
eriklomas 28:fdaa7ecfbd80 391 y=y+dy;
eriklomas 28:fdaa7ecfbd80 392 uLCD.filled_rectangle(x-3,y-3,x+3,y+3, STONE_COLOR);
eriklomas 28:fdaa7ecfbd80 393 pc.printf("C=%d\n",c);
eriklomas 28:fdaa7ecfbd80 394
eriklomas 28:fdaa7ecfbd80 395 if (b==0){
eriklomas 28:fdaa7ecfbd80 396 uLCD.filled_rectangle(x-3,c-3,x+3,c+3,TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 397 }
eriklomas 28:fdaa7ecfbd80 398 }
eriklomas 28:fdaa7ecfbd80 399 if (!pb_u){ //Move Right
eriklomas 28:fdaa7ecfbd80 400 c=y-dy;
eriklomas 28:fdaa7ecfbd80 401 a=uLCD.read_pixel(x, c);
eriklomas 28:fdaa7ecfbd80 402 b = TREE_COLOR;
eriklomas 28:fdaa7ecfbd80 403 b = pixel_eq(a, TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 404 pc.printf("a= %d",a);
eriklomas 28:fdaa7ecfbd80 405 pc.printf("b= %d",b);
eriklomas 28:fdaa7ecfbd80 406 while (b==1){
eriklomas 28:fdaa7ecfbd80 407 c=c-dy;
eriklomas 28:fdaa7ecfbd80 408 a=uLCD.read_pixel(x, c);
eriklomas 28:fdaa7ecfbd80 409 b = pixel_eq(a, TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 410 pc.printf("loop:b=%d",b);
eriklomas 28:fdaa7ecfbd80 411 }
eriklomas 28:fdaa7ecfbd80 412 b = pixel_eq(a, LIGHTBLACK);
eriklomas 28:fdaa7ecfbd80 413 w= pixel_eq(a, YELLOW);
eriklomas 28:fdaa7ecfbd80 414 pc.printf("a2= %d",a);
eriklomas 28:fdaa7ecfbd80 415 pc.printf("b2:%d",b);
eriklomas 28:fdaa7ecfbd80 416 if (b==1||w==1){
eriklomas 28:fdaa7ecfbd80 417 goto Main;
eriklomas 28:fdaa7ecfbd80 418 }
eriklomas 28:fdaa7ecfbd80 419 a=uLCD.read_pixel(x, y-dy);
eriklomas 28:fdaa7ecfbd80 420 b = pixel_eq(a, BLACK);
eriklomas 28:fdaa7ecfbd80 421
eriklomas 28:fdaa7ecfbd80 422 uLCD.filled_rectangle(x-3,y-3,x+3,y+3, BLACK);
eriklomas 28:fdaa7ecfbd80 423 y=y-dy;
eriklomas 28:fdaa7ecfbd80 424 uLCD.filled_rectangle(x-3,y-3,x+3,y+3, STONE_COLOR);
eriklomas 28:fdaa7ecfbd80 425 pc.printf("C=%d\n",c);
eriklomas 28:fdaa7ecfbd80 426
eriklomas 28:fdaa7ecfbd80 427 if (b==0){
eriklomas 28:fdaa7ecfbd80 428 uLCD.filled_rectangle(x-3,c-3,x+3,c+3,TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 429 pc.printf("b2=0 loop");
eriklomas 28:fdaa7ecfbd80 430 }
eriklomas 28:fdaa7ecfbd80 431 }
jford38 23:77049670cae6 432
eriklomas 28:fdaa7ecfbd80 433 //Cat Code
eriklomas 28:fdaa7ecfbd80 434 z=rand()%8;
eriklomas 28:fdaa7ecfbd80 435 pc.printf("%d ",z);
eriklomas 28:fdaa7ecfbd80 436 wait(.005);
eriklomas 28:fdaa7ecfbd80 437 if (z==0 || z==4 || z==7){ //Move Left
eriklomas 28:fdaa7ecfbd80 438
eriklomas 28:fdaa7ecfbd80 439 cc=cx-dx;
eriklomas 28:fdaa7ecfbd80 440 a=uLCD.read_pixel(cc, cy);
eriklomas 28:fdaa7ecfbd80 441 NL = pixel_eq(a, BLACK);
eriklomas 28:fdaa7ecfbd80 442 if (NL==1){
eriklomas 28:fdaa7ecfbd80 443 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
eriklomas 28:fdaa7ecfbd80 444 cx=cx-dx;
eriklomas 28:fdaa7ecfbd80 445 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
eriklomas 28:fdaa7ecfbd80 446 pc.printf("C=%d\n",cc);
eriklomas 28:fdaa7ecfbd80 447 }
eriklomas 28:fdaa7ecfbd80 448
eriklomas 28:fdaa7ecfbd80 449 t = pixel_eq(a, STONE_COLOR);
eriklomas 28:fdaa7ecfbd80 450
eriklomas 28:fdaa7ecfbd80 451 }
eriklomas 28:fdaa7ecfbd80 452 if (z==1 || z==5 ||z==6){ //Move Right
eriklomas 28:fdaa7ecfbd80 453 cc=cx+dx;
eriklomas 28:fdaa7ecfbd80 454 a=uLCD.read_pixel(cc, cy);
eriklomas 28:fdaa7ecfbd80 455 NR = pixel_eq(a, BLACK);
eriklomas 28:fdaa7ecfbd80 456 if (NR==1){
eriklomas 28:fdaa7ecfbd80 457 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
eriklomas 28:fdaa7ecfbd80 458 cx=cx+dx;
eriklomas 28:fdaa7ecfbd80 459 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
eriklomas 28:fdaa7ecfbd80 460 pc.printf("C=%d\n",cc);
eriklomas 28:fdaa7ecfbd80 461 }
jford38 20:6a58052b0140 462
eriklomas 28:fdaa7ecfbd80 463 t = pixel_eq(a, STONE_COLOR);
jford38 22:3c68eea5a609 464
eriklomas 28:fdaa7ecfbd80 465 }
eriklomas 28:fdaa7ecfbd80 466 if (z==2|| z==4 || z==5){ //Move up
eriklomas 28:fdaa7ecfbd80 467 cc=cy-dy;
eriklomas 28:fdaa7ecfbd80 468 a=uLCD.read_pixel(cx, cc);
eriklomas 28:fdaa7ecfbd80 469 NU = pixel_eq(a, BLACK);
eriklomas 28:fdaa7ecfbd80 470 if (NU==1){
eriklomas 28:fdaa7ecfbd80 471 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
eriklomas 28:fdaa7ecfbd80 472 cy=cy-dy;
eriklomas 28:fdaa7ecfbd80 473 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
eriklomas 28:fdaa7ecfbd80 474 pc.printf("C=%d\n",cc);
eriklomas 28:fdaa7ecfbd80 475 }
eriklomas 28:fdaa7ecfbd80 476
eriklomas 28:fdaa7ecfbd80 477 t = pixel_eq(a, STONE_COLOR);
eriklomas 28:fdaa7ecfbd80 478
eriklomas 28:fdaa7ecfbd80 479 }
eriklomas 28:fdaa7ecfbd80 480 if (z==3 || z==6 || z==7){ //Move Down
eriklomas 28:fdaa7ecfbd80 481 cc=cy+dy;
eriklomas 28:fdaa7ecfbd80 482 a=uLCD.read_pixel(cx, cc);
eriklomas 28:fdaa7ecfbd80 483 ND = pixel_eq(a, BLACK);
eriklomas 28:fdaa7ecfbd80 484 if (ND==1){
eriklomas 28:fdaa7ecfbd80 485 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, BLACK);
eriklomas 28:fdaa7ecfbd80 486 cy=cy+dy;
eriklomas 28:fdaa7ecfbd80 487 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, YELLOW);
eriklomas 28:fdaa7ecfbd80 488 pc.printf("C=%d\n",cc);
eriklomas 28:fdaa7ecfbd80 489 }
eriklomas 28:fdaa7ecfbd80 490
eriklomas 28:fdaa7ecfbd80 491 t = pixel_eq(a, STONE_COLOR);
eriklomas 28:fdaa7ecfbd80 492
jford38 23:77049670cae6 493 }
jford38 23:77049670cae6 494
eriklomas 28:fdaa7ecfbd80 495 //CHECK PICS AROUND CAT
eriklomas 28:fdaa7ecfbd80 496 N=uLCD.read_pixel(cx, cy+6);
eriklomas 28:fdaa7ecfbd80 497 N1 = pixel_eq(N, TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 498 N2 = pixel_eq(N, LIGHTBLACK);
eriklomas 28:fdaa7ecfbd80 499 if (N1==1||N2==1){
eriklomas 28:fdaa7ecfbd80 500 NU=2;
eriklomas 28:fdaa7ecfbd80 501 }
eriklomas 28:fdaa7ecfbd80 502 S=uLCD.read_pixel(cx, cy-6);
eriklomas 28:fdaa7ecfbd80 503 S1 = pixel_eq(S, TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 504 S2 = pixel_eq(S, LIGHTBLACK);
eriklomas 28:fdaa7ecfbd80 505 if (S1==1||S2==1){
eriklomas 28:fdaa7ecfbd80 506 ND=2;
eriklomas 28:fdaa7ecfbd80 507 }
eriklomas 28:fdaa7ecfbd80 508 E=uLCD.read_pixel(cx+6, cy);
eriklomas 28:fdaa7ecfbd80 509 E1 = pixel_eq(E, TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 510 E2 = pixel_eq(E, LIGHTBLACK);
eriklomas 28:fdaa7ecfbd80 511 if (E1==1||E2==1){
eriklomas 28:fdaa7ecfbd80 512 NR=2;
eriklomas 28:fdaa7ecfbd80 513 }
eriklomas 28:fdaa7ecfbd80 514 W=uLCD.read_pixel(cx-6, cy);
eriklomas 28:fdaa7ecfbd80 515 W1 = pixel_eq(W, TREE_COLOR);
eriklomas 28:fdaa7ecfbd80 516 W2 = pixel_eq(W, LIGHTBLACK);
eriklomas 28:fdaa7ecfbd80 517 if (W1==1||W2==1){
eriklomas 28:fdaa7ecfbd80 518 NL=2;
eriklomas 28:fdaa7ecfbd80 519 }
eriklomas 28:fdaa7ecfbd80 520
eriklomas 28:fdaa7ecfbd80 521 pc.printf("NR=%d",NR);
eriklomas 28:fdaa7ecfbd80 522 pc.printf("NL=%d", NL);
eriklomas 28:fdaa7ecfbd80 523 pc.printf("NU=%d", NU);
eriklomas 28:fdaa7ecfbd80 524 pc.printf("ND=%d", ND);
eriklomas 28:fdaa7ecfbd80 525 if (NL==2 && NR==2 && NU==2 && ND==2){
eriklomas 28:fdaa7ecfbd80 526 uLCD.filled_rectangle(cx-3,cy-3,cx+3,cy+3, TANK_RED);
eriklomas 28:fdaa7ecfbd80 527 count++;
eriklomas 28:fdaa7ecfbd80 528 if (count==1){
eriklomas 28:fdaa7ecfbd80 529 wait(3);
eriklomas 28:fdaa7ecfbd80 530 uLCD.cls();
eriklomas 28:fdaa7ecfbd80 531 uLCD.locate(4,2);
eriklomas 28:fdaa7ecfbd80 532 uLCD.puts("Winner!!");
eriklomas 28:fdaa7ecfbd80 533 t=0;
eriklomas 28:fdaa7ecfbd80 534 wait(3);
eriklomas 28:fdaa7ecfbd80 535 while (1){
eriklomas 28:fdaa7ecfbd80 536 if (!pb_l){
eriklomas 28:fdaa7ecfbd80 537 goto Start;
eriklomas 28:fdaa7ecfbd80 538 }
eriklomas 28:fdaa7ecfbd80 539 }
eriklomas 28:fdaa7ecfbd80 540 }
eriklomas 28:fdaa7ecfbd80 541
eriklomas 28:fdaa7ecfbd80 542 }
eriklomas 28:fdaa7ecfbd80 543 }
eriklomas 28:fdaa7ecfbd80 544 }