-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
66 lines (56 loc) · 1.47 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var canvas;
var music;
var sur1, sur2, sur3, sur4;
var box, edge;
function preload(){
music = loadSound("music.mp3");
}
function setup(){
canvas = createCanvas(750,750);
//create 4 different surfaces
sur1 = createSprite(1,750,200,60);
sur1.shapeColor = ' blue';
sur2 = createSprite(220,750,200,60);
sur2.shapeColor = 'orange';
sur3 = createSprite(440,750,200,60);
sur3.shapeColor = 'purple';
sur4 = createSprite(660,750,200,60);
sur4.shapeColor = 'green';
//create box sprite and give velocity
box = createSprite(random(20,750), 60,40,40);
box.shapeColor = 'white';
box.velocityY = 10;
edge = createEdgeSprites();
}
function draw() {
createCanvas(750,750);
background(rgb(169,169,169));
//create edgeSprite
createEdgeSprites();
//add condition to check if box touching surface and make it box
if(sur1.isTouching(box))
{
box.shapeColor = 'blue';
box.velocityY = 0;
music.play();
}
else if(sur2.isTouching(box))
{
box.shapeColor = 'orange';
box.velocityY = 0;
music.play();
}
else if(sur3.isTouching(box))
{
box.shapeColor = 'purple';
box.velocityY = 0;
music.play();
}
else if(sur4.isTouching(box))
{
box.shapeColor = 'green';
box.velocityY = 0;
music.play();
}
drawSprites();
}