-
Notifications
You must be signed in to change notification settings - Fork 0
/
Class.js
150 lines (109 loc) · 2.6 KB
/
Class.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
class Player {
constructor() {
this.x = 250
this.y = 750
this.width = 150
this.height = 150
this.life = 3
this.score=0
}
draw(){
image(game.tony, this.x , this.y, this.width, this.height)
}
moveUp() {
if (this.y >= 100) {
this.y -= 40
}
}
moveDown() {
if (this.y <= 700) {
this.y += 40
}
}
moveLeft() {
if (this.x >= 0) {
this.x -= 25
}
}
moveRight() {
if (this.x <= 570) {
this.x += 25
}
}
}
class Obstacles {
constructor(){
this.x = (Math.random() * height)
this.y = 0
this.width = 60
this.height = 50
this.velocity = 1
}
draw(){
this.y++
this.y += this.velocity
image(game.gun, this.x, this.y, this.width, this.height)
}
collision(playerInfo) {
let obstacleX = this.x + this.width / 2
let obstacleY = this.y + this.height / 2
let playerX = playerInfo.x + playerInfo.width / 2
let playerY = playerInfo.y + playerInfo.height / 2
if (dist(obstacleX, obstacleY, playerX, playerY) < 50) {
game.player.life--
return false
} else {
return true
}
}
}
class Prize {
constructor(){
this.jamon
this.x = (Math.random() * height)
this.y = 0
this.width = 70
this.height = 60
this.velocity = 1
}
draw(){
this.y += this.velocity
image(game.jamon, this.x, this.y, this.width, this.height)
}
collision(prizePlayer) {
let prizePlayerX = this.x + this.width / 2
let prizePlayerY = this.y + this.height / 2
let prizeX = prizePlayer.x + prizePlayer.width / 2
let prizeY = prizePlayer.y + prizePlayer.height / 2
if (dist(prizePlayerX, prizePlayerY, prizeX, prizeY) > 50) {
return false
} else {
return true
}
}
}
class Secondprize {
constructor(){
this.espresso
this.x = (Math.random() * height)
this.y = 0
this.width = 80
this.height = 40
this.velocity = 1
}
draw() {
this.y += this.velocity
image(game.espresso, this.x, this.y, this.width, this.height)
}
collision(secondprize) {
let secondprizeX = this.x + this.width / 2
let secondprizeY = this.y + this.height / 2
let secondX = secondprize.x + secondprize.width / 2
let secondY = secondprize.y + secondprize.height / 2
if (dist(secondprizeX, secondprizeY, secondX, secondY) > 50) {
return false
} else {
return true
}
}
}