-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent.js
66 lines (55 loc) · 1016 Bytes
/
agent.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
63
64
65
66
class Agent {
constructor() {
this.x = width / 2
this.y = height - 30
this.size = 100
this.dx = 25
}
getCoord() {
return {
x: this.x,
y: this.y
}
}
getSize() {
return this.size
}
draw() {
fill(255)
rect(this.x, this.y, this.size, 30)
}
hitTheBall(ball) {
if (ball.doesHitAgent()) {
return false
}
if ((ball.getX() - 22.5 > (this.x + this.size)) || ((ball.getX() + 22.5) < this.x)) {
return false
}
if (Math.floor((this.y - ball.getY())) <= ball.diameter()) {
ball.sethitAgent()
stroke(255, 204, 0);
return true
}
return false
}
moveRight(dx = null) {
if (dx === null) {
dx = this.dx
}
if ((this.x + this.size + dx) < width) {
this.x += dx
return
}
this.x = width - this.size
}
moveLeft(dx = null) {
if (dx === null) {
dx = this.dx
}
if ((this.x - dx) > 0) {
this.x -= dx
return
}
this.x = 0
}
}