-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbola.js
62 lines (56 loc) · 1.87 KB
/
bola.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class Bola {
constructor(x, y) {
this.position = createVector(x, y)
this.velocity = createVector(0, 0)
}
start() {
this.velocity.set(5, 5)
}
update() {
this.colisao();
this.position.add(this.velocity)
if(bola.position.x - raio <= largura) {
//ponto do bot
players[1]["pontos"].val++
fezPonto = true
this.position.set(width/2, height/2)
this.velocity.set(random(0.75, 1.25) * 5, random(0.75, 1.25) * 5)
if(random() < 0.5)
this.velocity.mult(-1)
if(players[1].pontos.val == 10){
game = false
winner = players[1].nome
}
} else if(bola.position.x + raio >= width - largura){
//ponto do player
fezPonto = true
players[0].pontos.val++
this.velocity.set(random(0.75, 1.25) * 5, random(0.75, 1.25) * 5)
if(random() < 0.5)
this.velocity.mult(-1)
this.position.set(width/2, height/2)
if(players[0].pontos.val == 10){
game = false
winner = players[0].nome
}
}
}
colisao(){
if(this.position.x <= raio){
this.position.x = diametro
this.velocity.x *= -1
}else if(this.position.x >= width - raio){
this.position.x = width - diametro
this.velocity.x *= -1
} else if(this.position.y <= raio){
this.position.y = diametro
this.velocity.y *= -1
}else if(this.position.y >= height - raio){
this.position.y = height - diametro
this.velocity.y *= -1
}else if(this.position.x < raio && this.position.y < raio){
console.log("Teste")
this.velocity.mult(-1)
}
}
}