let cubeLoc;
function setup() {
cubeLoc = createVector(100,80);
createCanvas(400, 400);
textSize(22);
}
function draw() {
background(220);
//Draw UI
push();
if((50<mouseX)&&(mouseX<130)&&(200<mouseY)&&(mouseY<280)){
fill(80);
rect(50, 200, 80, 80);
}else{
fill(255);
rect(50, 200, 80, 80);
}
pop();
push();
if((260<mouseX)&&(mouseX<340)&&(200<mouseY)&&(mouseY<280)){
fill(80);
rect(260, 200, 80, 80);
}else{
fill(255);
rect(260, 200, 80, 80);
}
pop();
text('LEFT', 60, 250);
text('RIGHT', 265, 250);
rect(cubeLoc.x, cubeLoc.y, 55, 55);
}
function mouseClicked(){
if((260<mouseX)&&(mouseX<340)&&(200<mouseY)&&(mouseY<280)){
cubeLoc.x += 5;
}
if((50<mouseX)&&(mouseX<130)&&(200<mouseY)&&(mouseY<280)){
cubeLoc.x -= 5;
}
print("("+mouseX+","+mouseY+")")
}
Code language: JavaScript (javascript)
Conditions
by
Tags:
Leave a Reply