-
Notifications
You must be signed in to change notification settings - Fork 0
/
ball.js
42 lines (36 loc) · 910 Bytes
/
ball.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
export default class Ball {
element
posX
posY
radius
velocity
direction
constructor() {
this.element = document.createElement('div')
this.element.className = "ball"
document.querySelector("body").appendChild(this.element)
this.setRadius(15)
this.setPosCenter()
}
setRadius(radius) {
this.radius = radius
this.element.style.width = 2 * radius + "px"
this.element.style.height = 2 * radius + "px"
}
setPos(x, y) {
this.setX(x)
this.setY(y)
}
setPosCenter() {
this.setX(window.innerWidth / 2)
this.setY(window.innerHeight / 2)
}
setX(x) {
this.posX = x
this.element.style.left = (x - this.radius) + "px"
}
setY(y) {
this.posY = y
this.element.style.top = (y - this.radius) + "px"
}
}