-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.js
93 lines (78 loc) · 2.83 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
class Game {
constructor() {
this.score = 0;
this.lives = 3;
this.gameOver = false;
this.currentScreen = 1;
this.livesElement = document.querySelector("#lives");
this.scoreElement = document.querySelector("#score");
this.element = document.querySelector("#game-area");
this.width = this.element.getBoundingClientRect().width;
this.height = this.element.getBoundingClientRect().height;
this.updateLives();
this.updateScore();
this.ambienceSound = new Audio("./sounds/ambienceSound.wav");
this.ambienceSoundMetro = new Audio("./sounds/ambienceSoundMetro.m4a");
this.isAmbienceSoundPlaying = false;
this.isAmbienceSoundMetroPlaying = false;
this.ambienceOffice= new Audio ("./sounds/ambienceOffice.mp3")
this.isAmbienceOfficePlaying = false;
}
updateLives() {
this.livesElement.innerText = "♥️".repeat(this.lives);
}
updateScore() {
this.scoreElement.innerText = this.score.toString();
}
clearScreen() {
this.element.innerHTML = "";
}
changeScreen(screen, Pickpocket) {
this.currentScreen = screen;
this.clearScreen();
Cockroach.cockroachArray=[];
Tourist.touristsArray=[];
this.obstacleTop;
this.obstacleBottom;
this.obstacleCenter;
if (screen === 2) {
this.element.setAttribute( "id", "game-area-2")
this.obstacleTop = new Obstacle("obstacle-top");
this.element.appendChild(this.obstacleTop.element);
this.obstacleTop.height =
this.obstacleTop.element.getBoundingClientRect().height;
this.obstacleTop.width =
this.obstacleTop.element.getBoundingClientRect().width;
this.obstacleBottom = new Obstacle("obstacle-bottom");
this.element.appendChild(this.obstacleBottom.element);
this.obstacleBottom.height =
this.obstacleBottom.element.getBoundingClientRect().height;
this.obstacleBottom.width =
this.obstacleBottom.element.getBoundingClientRect().width;
if (myGame.score >= 300) {
player.positionLeft = 300;
player.positionBottom = (this.height - player.height) / 2;
} else if (player.score >= 100 && player.score < 300) {
player.positionLeft = 150;
player.positionBottom = (this.height - player.height) / 2;
} else {
player.positionLeft = 100;
player.positionBottom = (this.height - player.height) / 2;
}
player.velocity = 3;
player.element.style.left = player.positionLeft + "px";
player.element.style.bottom = player.positionBottom + "px";
myGame.element.appendChild(player.element);
setTimeout(() => {
// código asíncrono
this.pickpocket = new Pickpocket();
}, 500);
}
}
changeScreenFinal(screen) {
this.currentScreen = screen;
this.clearScreen();
this.element.classList.add("win");
}
}
const myGame = new Game();