-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaddle.js
More file actions
26 lines (24 loc) · 699 Bytes
/
paddle.js
File metadata and controls
26 lines (24 loc) · 699 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
25
26
class Paddle {
constructor() {
this.width = 150
this.height = 25
this.color = color(255)
this.location = createVector((width / 2) - (this.width / 2), height - 35)
this.speed = {
right: createVector(8, 0),
left: createVector(-8, 0)
}
}
display() {
fill(this.color)
rect(this.location.x, this.location.y, this.width, this.height)
}
move(direction) {
this.location.add(this.speed[direction])
if (this.location.x < 0) {
this.location.x = 0
} else if (this.location.x + this.width > width) {
this.location.x = width - this.width
}
}
}