-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColisiones.js
More file actions
51 lines (45 loc) · 1.65 KB
/
Copy pathColisiones.js
File metadata and controls
51 lines (45 loc) · 1.65 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
import cancha from './Cancha.js'
import { bolaH } from './Bola.js'
import { jugadorH, jugadorH2 } from './Jugador.js'
import maquina from './Maquina.js'
import puntuacion from './Puntuacion.js'
import {pegar} from './Audio.js'
let jugadorRebote = (jugadorH, bolaH) => {
let halfWidth = jugadorH.getNode().getAttribute('width') / 2
let colision = [
Math.abs(+bolaH.getCoor().x - +jugadorH.getCoor().x - halfWidth) < halfWidth,
+bolaH.getCoor().y > +jugadorH.getCoor().y,
+bolaH.getCoor().y < +jugadorH.getCoor().y + jugadorH.getNode().getAttribute('height') * 1
]
if (colision.every(e => e)) {
pegar.play()
bolaH.direccion += 2 * (jugadorH.angulo - bolaH.direccion)
bolaH.direccion = (bolaH.direccion < 0) ? bolaH.direccion + 360 : bolaH.direccion
}
}
let reobte = (cancha, bolaH) => {
let vertical = [
+bolaH.getCoor().y > +cancha.getAttribute('height') - 5,
+bolaH.getCoor().y < 5
]
if (!vertical.every(c => !c)) {
bolaH.direccion += 2 * (0 - bolaH.direccion)
bolaH.direccion = (bolaH.direccion < 0) ? bolaH.direccion + 360 : bolaH.direccion
bolaH.avanzar()
}
let horizontal = [
+bolaH.getCoor().x > +cancha.getAttribute('width') - 5,
+bolaH.getCoor().x < +5
]
puntuacion(cancha, bolaH)
if (!horizontal.every(c => !c)) {
bolaH.direccion += 2 * (90 - bolaH.direccion)
bolaH.direccion = (bolaH.direccion < 0) ? bolaH.direccion + 360 : bolaH.direccion
bolaH.avanzar()
}
}
maquina.add(()=>{
reobte(cancha, bolaH)
jugadorRebote(jugadorH, bolaH)
jugadorRebote(jugadorH2, bolaH)
})