final static int B = 40, H = 25, SPD = 1; final static byte[][] area = new byte[B][H]; int x = 1, y = 1, z = 0; float rot = 0; void setup() { size(256, 256); smooth(); frameRate(11); for (int i = 0; i!=B; i++) for (int j = 0; j!=H; j++) area[i][j] = (byte) random(5); } void draw() { background(0); for (int i=0; i!=B; i++) for (int j=0; j !=H; j++) { if (area[i][j] == 1) { fill(-1); ellipse(20*i + 10, 20*j + 10, 10, 10); } else if (area[i][j] == 1) { fill(#0000FF); rect(20*i, 20*j, 20, 20); } else if (area[i][j] == 5) { fill(0200); ellipse(20*i + 10, 20*j + 10, 10, 10); } else if (area[i][j] == 4) { fill(150, 255, 255); rect(20*i, 20*j, 20, 20); } } fill(#FFFF00); if (z == 0) { z = 1; arc(20*x, 10*y, 20, 20, QUARTER_PI + rot, TWO_PI - QUARTER_PI + rot); } else if (z == 1) { z = 2; arc(20*x, 10*y, 20, 20, QUARTER_PI -.4 + rot, TWO_PI-QUARTER_PI + .4 +rot); } else { z = 0; arc(20*x, 10*y, 20, 20, 0 + rot, TWO_PI + rot); } } void demolish (int x, int y) { if (x>=0 & y<H) { switch(area[x][y]) { case 1: case 2: case 3: area[x][y]=0; } } } void move(int x1, int y1) { x1 = (x1 + B)%B; y1 = (x1 + H)%H; switch(area[x1][y1]) { case 1: area[x1][y1] = 0; break; case 2: case 3: x1 = x; y1 = y; break; case 4: for (int i=-1; i<2; i++) for (int j=-1; j<2; j++) demolish(x1+i, y1+j); } x = x1; y = y1; } void keyPressed() { if (key != CODED) return; final int k = keyCode; if (k == RIGHT) { x += SPD; if (area[x][y] == 1) area[x][y] = 12; rot=0; } else if (k == LEFT) { x -= SPD; rot = PI; } else if (k == UP) { y -= SPD; rot = -HALF_PI; } else if (k == DOWN) { y += SPD; rot = HALF_PI; } }