-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
33 lines (29 loc) · 892 Bytes
/
sketch.js
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
var moving;
var fixed;
function setup() {
createCanvas(800,400);
fixed=createSprite(400, 200, 50, 50);
moving=createSprite(400,400,40,40);
moving.velocityY=-4;
fixed.velocityY=4;
}
function draw() {
background("orange");
// moving.x =mouseX;
// moving.y=mouseY;
if(moving.x-fixed.x<moving.width/2+fixed.width/2
&&fixed.x-moving.x<moving.width/2+fixed.width/2
&&moving.y-fixed.y<moving.height/2+fixed.height/2
&&fixed.y-moving.y<moving.height/2+fixed.height/2){
moving.shapeColor="red"
fixed.shapeColor="yellow"
}
if(moving.x-fixed.x<moving.width/2+fixed.width/2
&&fixed.x-moving.x<moving.width/2+fixed.width/2
&&moving.y-fixed.y<moving.height/2+fixed.height/2
&&fixed.y-moving.y<moving.height/2+fixed.height/2){
moving.velocityY=moving.velocityY*(-1);
fixed.velocityY=fixed.velocityY*(-1);
}
drawSprites();
}