This repository was archived by the owner on Dec 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
98 lines (72 loc) · 2.12 KB
/
sketch.js
File metadata and controls
98 lines (72 loc) · 2.12 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var canvas;
var block1, block2, block3, block4;
var ball, edges;
var music;
function preload() {
// load sound here
music = loadSound("music.mp3");
}
function setup() {
userStartAudio();
frameRate(60);
rectMode(CENTER);
canvas = createCanvas(800, 600);
block1 = createSprite(95, 580, 200, 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(495, 580, 200, 30);
block3.shapeColor = "red";
block4 = createSprite(695, 580, 200, 30);
block4.shapeColor = "green";
ball = createSprite(random(20, 750), 100, 40, 40);
ball.shapeColor = "white";
//write code to add velocityX and velocityY
ball.velocityX = random(-8, 8);
ball.velocityY = random(-8, 8);
textStyle(BOLDITALIC);
textSize(50);
fill(0);
textAlign(CENTER);
}
function draw() {
background(170);
if (!started && frameCount < 500) {
text("Click To Start Audio Please :/", width / 2, height / 3);
}
edges = createEdgeSprites();
ball.bounceOff(edges);
if (ball.isTouching(edges)) {
ball.velocityX = random(-8, 8);
ball.velocityY = random(-8, 8);
}
//write code to bounce off ball from the block1
if (block1.isTouching(ball)) {
ball.bounceOff(block1);
ball.shapeColor = "blue";
if (!music.isPlaying()) music.loop();
}
if (block2.isTouching(ball)) {
ball.bounceOff(block2);
ball.shapeColor = "orange";
//write code to set velocityX and velocityY of ball as 0
if (music.isPlaying()) music.stop();
//write code to stop music
}
//write code to bounce off ball from the block3
if (block3.isTouching(ball)) {
ball.bounceOff(block3);
ball.shapeColor = "red";
}
//write code to bounce off ball from the block4
if (block4.isTouching(ball)) {
ball.bounceOff(block4);
ball.shapeColor = "green";
}
drawSprites();
}
let started = false;
function mousePressed() {
started = true;
}