-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBola.js
More file actions
54 lines (45 loc) · 1.06 KB
/
Copy pathBola.js
File metadata and controls
54 lines (45 loc) · 1.06 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
import _ from './creator.js'
import teclas from './Teclas.js'
import maquina from './Maquina.js'
let circle = _('circle', null, {
cx: 50,
cy: 50,
r: 7,
stroke: "black",
"stroke-width": 1,
fill: "#46E80E",
})
class Bola {
constructor(circle) {
this.node = circle
this.direccion = 15
this.speed = 3
}
getNode() {
return this.node
}
setCoor(coor) {
this.node.setAttribute('cx', coor.x)
this.node.setAttribute('cy', coor.y)
}
getCoor() {
return {
x: this.node.getAttribute('cx'),
y: this.node.getAttribute('cy'),
}
}
avanzar(){
let c = this.getCoor()
c.x = +c.x + Math.cos((Math.PI / 180) * this.direccion)*this.speed
c.y = +c.y - Math.sin((Math.PI / 180) * this.direccion)*this.speed
this.setCoor(c)
}
}
const bolaH = new Bola(circle)
maquina.add(()=>{
if (teclas[37]) bolaH.direccion++
if (teclas[39]) bolaH.direccion--
bolaH.avanzar()
})
export { bolaH }
export default circle