color cblack = color(0,0,0); int t1_x = 135; int t1_y = 135; int t1_d = 2; int t2_x = 365; int t2_y = 365; int t2_d = 4; int crash = 0; void setup(){ size(500,500); background(cblack); stroke(200,200,200); noFill(); rect(20,20,460,460); PFont font = loadFont("ArialMT-48.vlw"); textFont(font, 12); loop(); } void draw() { // Get current colour color t1_c = get(t1_x,t1_y); color t2_c = get(t2_x,t2_y); // Collision? if ( t1_c != cblack ) { crash = 1; crash(); } if ( t2_c != cblack ) { crash = 2; crash(); } // Draw next point and decide next direction stroke(20,170,220); point(t1_x, t1_y); stroke(220,170,20); point(t2_x, t2_y); if ( t1_d == 1 ) { t1_y--; } if ( t1_d == 2 ) { t1_x++; } if ( t1_d == 3 ) { t1_y++; } if ( t1_d == 4 ) { t1_x--; } if ( t2_d == 1 ) { t2_y--; } if ( t2_d == 2 ) { t2_x++; } if ( t2_d == 3 ) { t2_y++; } if ( t2_d == 4 ) { t2_x--; } } void keyPressed(){ // Traceon 1 Controls switch(key){ case 'd': case 'D': t1_d = 2; break; case 's': case 'S': t1_d = 3; break; case 'a': case 'A': t1_d = 4; break; case 'w': case 'W': t1_d = 1; break; } // Traceon 2 Controls switch(keyCode){ case UP: t2_d = 1; break; case RIGHT: t2_d = 2; break; case DOWN: t2_d = 3; break; case LEFT: t2_d = 4; break; } } void crash() { noLoop(); text("Ow. Traceon "+crash+" has crashed and lost! Click to restart.", 50, 50); } // Reset void mousePressed() { if ( crash != 0 ) { background(cblack); stroke(200,200,200); noFill(); rect(20,20,460,460); t1_x = 135; t1_y = 135; t1_d = 2; t2_x = 365; t2_y = 365; t2_d = 4; crash = 0; loop(); } }