-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
72 lines (52 loc) · 1.68 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
67
68
69
70
71
72
var canvas;
var block1,block2,block3,block4;
var ball, edges;
var music;
function preload(){
// load sound here
music=loadSound("music.mp3");
}
function setup(){
canvas = createCanvas(800,600);
block1 = createSprite(0,580,360,30);
block1.shapeColor = "blue";
block2 = createSprite(295,580,200,30);
block2.shapeColor = "orange";
//create two more blocks i.e. block3 and block4 here
block3 = createSprite(515,580,200,30);
block3.shapeColor = "red";
block4 = createSprite(740,580,220,30);
block4.shapeColor = "green";
ball = createSprite(random(20,750),100, 40,40);
ball.shapeColor = rgb(255,255,255);
//write code to add velocityX and velocityY
ball1.velocityx = 4;
ball1.velocityy = 9;
}
function draw() {
background(rgb(169,169,169));
edges=createEdgeSprites();
ball.bounceOff(edges);
//write code to bounce off ball from the block1
if(block1.isTouching(ball) && ball.bounceOff(block1)){
ball.shapeColor = "blue";
music.play();
}
if(block2.isTouching(ball)){
ball.shapeColor = "orange";
//write code to set velocityX and velocityY of ball as 0
ball1.velocityx = 0;
ball1.velocityy = 0;
//write code to stop music
music.stop();
}
//write code to bounce off ball from the block3
if(block3.isTouching(ball1) && ball.bounceoff(block3)){
ball1.shapeColor = "red";
}
//write code to bounce off ball from the block4
if(block4.isTouching(ball1) && ball.bounceoff(block4)){
ball1.shapeColor = "green";
}
drawSprites();
}