xxxxxxxxxx
function setup() {
createCanvas(windowWidth, windowHeight);
print(windowWidth);
print(windowHeight);
background(255);
lightblue = color(179, 236, 255);
darkblue = color(0, 0, 255);
blue = color(0, 191, 255);
bluegreen = color(0, 98, 128);
darkgray = color(90);
gray = color(200);
white = color(255);
}
var x;
var y;
var position = 0;
var positionx = 0;
var positiony = 0;
//colors
var lightblue;
var darkblue;
var blue;
var bluegreen;
var darkgray;
var gray;
var white;
var rockx = 0;
var rocky = 0;
var rockspeed = 10;
var score = 0;
function draw() {
var armcolor = lightblue;
if (mouseIsPressed == true){
armcolor = darkgray;
}
else {
armcolor = lightblue;
}
var bodycolor = white;
if (mouseIsPressed == true){
bodycolor = darkgray
}
else {
bodycolor = white
}
if (keyIsDown(UP_ARROW) && positiony > -windowHeight/2) {
positiony -= 10;
}
if (keyIsDown(DOWN_ARROW) && positiony < windowHeight/2) {
positiony += 10;
}
if (keyIsDown(RIGHT_ARROW) && positionx < windowWidth/2) {
positionx += 10;
}
if (keyIsDown(LEFT_ARROW) && positionx > -windowWidth/2) {
positionx -= 10;
}
clear();
robot(armcolor, bodycolor);
push();
rocks();
pop();
if (rockx < x+100 && rockx > x-100 && rocky < y+100 && rocky > y-100) {
clear();
textSize(200);
textAlign(CENTER, CENTER);
text('YOU LOSE', windowWidth / 2, windowHeight / 2);
noLoop();
}
fill(0);
textSize(150);
text(score, windowWidth/1.1, windowHeight/1.1);
if (rocky > windowHeight) {
score += 1;
if (score % 2 == 0) {
rockspeed = rockspeed + 1;
}
}
}
function rocks() {
fill('brown');
for (let i = 0; i < 1; i++) {
push();
if (rocky > windowHeight) {
rockx = random(0, windowWidth);
rocky = 0;
}
ellipseMode(CENTER);
translate(0, rocky);
ellipse(rockx, 0, 100, 100);
rocky += rockspeed;
pop();
}
}
function robot(armcolor, bodycolor) {
x = windowWidth/2+positionx;
y = windowHeight/2+positiony;
//right arm
push();
fill(armcolor);
stroke(armcolor);
translate(x+75, y)
rectMode(CORNER);
angleMode(DEGREES);
rotate(-30);
rect(0, 0, 120, 30);
pop();
push();
fill(armcolor);
stroke(armcolor);
translate(x+170, y-50);
rectMode(CORNER);
angleMode(DEGREES);
rotate(-60);
rect (0, 0, 100, 30);
pop();
push();
fill(armcolor);
stroke(gray);
translate(x+240, y-170);
rotate(180);
arc(0, 0, 100, 100, 180, PI + QUARTER_PI, OPEN);
pop();
//left arm
push();
translate(x+x, 0);
scale(-1, 1);
push();
fill(armcolor);
stroke(armcolor);
translate(x+75, y);
rectMode(CORNER);
angleMode(DEGREES);
rotate(-30);
rect(0, 0, 120, 30);
pop();
push();
fill(armcolor);
stroke(armcolor);
translate(x+170, y-50);
rectMode(CORNER);
angleMode(DEGREES);
rotate(-60)
rect (0, 0, 100, 30);
pop();
push();
fill(armcolor);
stroke(gray);
translate(x+240, y-170);
rotate(180);
arc(0, 0, 100, 100, 180, PI + QUARTER_PI, OPEN);
pop();
pop();
//right leg
push();
fill(darkgray);
stroke(darkgray);
translate(x+50, y+75);
angleMode(DEGREES);
rotate(-20);
rect(0, 0, 15, 40, 20);
pop();
//left leg
push();
translate(x+x, 0);
scale(-1, 1);
push();
fill(darkgray);
stroke(darkgray);
translate(x+50, y+75);
angleMode(DEGREES);
rotate(-20);
rect(0, 0, 15, 40, 20);
pop();
pop();
//copters
push();
fill(blue);
stroke(bluegreen);
ellipse(x+100, y-110, 200, 10);
ellipse(x-100, y-110, 200, 10);
rectMode(CENTER);
fill(gray);
rect(x, y-100, 10, 20);
pop();
//main circle
push();
fill(bodycolor);
stroke(gray);
ellipse(x, y, 200, 200);
pop();
//screen
push();
fill(blue);
stroke(darkblue);
rectMode(CENTER);
rect(x, y, 150, 150, 45);
pop();
push();
fill(0);
textSize(20);
text('10:24 AM', x-50, y-30);
pop();
push();
line(x-50, y-10, x+50, y-10);
line(x-50, y+10, x+50, y+10);
line(x-50, y+30, x+50, y+30);
pop();
push();
fill(0);
ellipse(x-60, y-10, 5, 5);
ellipse(x-60, y+10, 5, 5);
pop();
push();
line(x-60, y+35, x-65, y+30);
line(x-60, y+35, x-55, y+20);
pop();
}
p5 had problems creating the global function "blue", possibly because your code is already using that name as a variable. You may want to rename your variable to something else.
300
150