xxxxxxxxxx
var ISOs = [];
var player;
var finished;
var start;
let greeting;
let goodbye;
let score;
function setup() {
createCanvas(windowWidth, windowHeight);
let n = 3;
finished = false;
start = false;
score = 0;
background(color(211,211,211));
for(let j = 0; j < n; j++) {
for(let i = 0; i < n; i++){
ISOs.push(new ISO(x = ((width / n) * i), y = ((height / n) * j) ));
}
}
player = new User();
greeting = createElement('h2', 'Welcome Purple User. Press return to start. Use arrow keys. Avoid other pipes!');
greeting.position(width/2.5, height/2.5);
}
function draw() {
if(finished != true & start == true){
for (let i = 0; i < ISOs.length; i++) {
ISOs[i].avoid_trod();
ISOs[i].move();
ISOs[i].display();
if(frameCount % 100 == 0){ISOs[i].update_direction()}
ISOs[i].avoid_exits();
}
player.avoid_trod();
player.move();
player.display();
player.avoid_exits();
score += 1;
} else if (finished == true & start == true) {
let message_elements = ["Game Over. Score:", str(score)];
goodbye = createElement('h2', join(message_elements, " "));
goodbye.position(width/2.5, height/2.5);
}
}
//function mousePressed() {
// saveCanvas('plumbing-tron-screenshot', 'jpg');
//}
function is_trod(x_pixel, y_pixel){
let pix_ar = get(x_pixel, y_pixel);
let pixel_color = color(pix_ar[0], pix_ar[1], pix_ar[2]);
let equiv_check = JSON.stringify(pixel_color) === JSON.stringify(color(211,211,211));
if(equiv_check != true){
return(true)
} else {
return(false)
}
}
function keyPressed() {
if (keyCode === LEFT_ARROW) {
player.x_direction = -1;
} else if (keyCode === RIGHT_ARROW) {
player.x_direction = 1;
} else if (keyCode === UP_ARROW) {
player.y_direction = -1;
} else if (keyCode === DOWN_ARROW) {
player.y_direction = 1;
} else if (keyCode === RETURN & start == false) {
greeting.remove();
start = true;
}
}