-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathsketch.js
More file actions
49 lines (42 loc) · 1.29 KB
/
sketch.js
File metadata and controls
49 lines (42 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var fixedRect, movingRect;
var gameObject1, gameObject2, gameObject3, gameObject4;
function setup() {
createCanvas(1200,800);
fixedRect = createSprite(600, 400, 50, 80);
fixedRect.shapeColor = "green";
movingRect = createSprite(800, 400,80,30);
movingRect.shapeColor = "green";
gameObject1 = createSprite(100, 100, 50, 50);
gameObject1.shapeColor = "green";
gameObject2 = createSprite(200, 100, 50, 50);
gameObject2.shapeColor = "green";
gameObject3 = createSprite(300, 100, 50, 50);
gameObject3.shapeColor = "green";
gameObject4 = createSprite(400, 100, 50, 50);
gameObject4.shapeColor = "green";
}
function draw() {
background(0,0,0);
movingRect.x = World.mouseX;
movingRect.y = World.mouseY;
if(isTouching(movingRect, gameObject1)){
movingRect.shapeColor = "blue";
gameObject1.shapeColor = "blue";
}
else {
movingRect.shapeColor = "green";
gameObject1.shapeColor = "green";
}
drawSprites();
}
function isTouching(object1,object2){
if (object1.x - object2.x < object2.width/2 + object1.width/2
&& object2.x - object1.x < object2.width/2 + object1.width/2
&& object1.y - object2.y < object2.height/2 + object1.height/2
&& object2.y - object2.y < object2.height/2 + object1.height/2) {
return true;
}
else {
return false;
}
}