-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.js
102 lines (89 loc) · 3.07 KB
/
game.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
class Game {
constructor() {
this.player = new Player()
this.secondPrize = []
this.obstacles = []
this.prize = []
}
preload() {
this.tony = loadImage('./images/tony.png')
this.gun = loadImage('./images/pistola.png')
this.espresso = loadImage('./images/espresso.png')
this.jamon = loadImage('./images/jamon.png')
this.sad = loadImage('./images/sad.gif')
this.happy = loadImage('./images/celebrating.gif')
}
draw() {
background(106, 92, 92)
stroke(255, 204, 0);
strokeWeight(4);
this.player.draw()
if (frameCount % 20 === 0) {
this.obstacles.push(new Obstacles(this.gun))
}
this.obstacles.forEach((obstacle) => {
obstacle.draw()
})
this.obstacles = this.obstacles.filter(obstacle => {
if (!obstacle.collision(this.player)) {
document.querySelector(".life span").innerHTML = this.player.life
if (game.player.life ===0){
noLoop()
textSize(50)
text("You died", 250, 200)
image(this.sad, 200, 300, 300, 300)
} else {
return false
}
} else {
return true
}
})
if (frameCount % 200 === 0) {
this.prize.push(new Prize())
}
this.prize.forEach((prize) => {
prize.draw()
})
this.prize = this.prize.filter(prize => {
if (prize.collision(this.player)) {
if (game.player.score >= 50){
noLoop()
textSize(50)
text("You win", 250, 200)
image(this.happy, 200, 300, 300, 300)
} else {
this.player.score += 10
document.querySelector(".score span").innerHTML = this.player.score
console.log(this.player.score)
return false
}
} else {
return true
}
})
if (frameCount % 150 === 0) {
this.secondPrize.push(new Secondprize())
}
this.secondPrize.forEach((secondPrize) => {
secondPrize.draw()
})
this.secondPrize = this.secondPrize.filter(secondPrize => {
if (secondPrize.collision(this.player)) {
if (game.player.score >= 50){
noLoop()
textSize(32)
text("You win", 300, 300)
image(this.happy, 200, 300, 300, 300)
} else {
this.player.score += 5
document.querySelector(".score span").innerHTML = this.player.score
console.log(this.player.score)
return false
}
} else {
return true
}
})
}
}