-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrick.js
More file actions
24 lines (21 loc) · 768 Bytes
/
brick.js
File metadata and controls
24 lines (21 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Brick {
constructor(location, width, height, color) {
this.location = location
this.width = width
this.points = 1
this.height = height
this.color = color
}
display() {
fill(this.color)
rect(this.location.x, this.location.y, this.width, this.height)
}
collide(ball) {
if (ball.location.y - ball.radius <= this.location.y + this.height &&//collides with bottom
ball.location.y + ball.radius >= this.location.y &&//collides with top
ball.location.x + ball.radius >= this.location.x &&//collides with right side
ball.location.x - ball.radius <= this.location.x + this.width) {//collides with left side
return true
}
}
}