Professional Documents
Culture Documents
Code
Code
function setup() {
createCanvas(800,400);
obj1 = createSprite (400,200,50,50);
obj2 = createSprite (100,200,100,100);
obj3 = createSprite (700,200,80,80);
obj4 = createSprite (500,200,80,80);
obj1.shapeColor = "yellow";
obj2.shapeColor = "blue";
obj3.shapeColor = "red";
obj4.shapeColor = "green";
//object.velocityX = 2;
//block.velocityX = -2;
}
function draw() {
background("lightblue");
obj1.x = mouseX;
obj1.y = mouseY;
if (Jonathan(obj1,obj3)){obj1.shapeColor = "blue";
obj3.shapeColor = "blue";
}
else {obj1.shapeColor = "yellow";
obj3.shapeColor = "yellow";}
drawSprites();
}
function Jonathan(object1,object2);
{
if (object1.x - object2.x < object1.width/2 + object2.width/2
&& object2.x - object1.x < object1. width/2 + object2.width/2
&& object1.y - object2.y < object1.width/2 + object2.width/2
&& object2.y - object1.y < object1.width/2 + object2.width/2)
{
return true;
else {
return false;
}
}