-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameOver.js
More file actions
132 lines (89 loc) · 2.6 KB
/
GameOver.js
File metadata and controls
132 lines (89 loc) · 2.6 KB
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
//Script da tela de GameOver
function GameOver(canvas){
//Estados das telas do Jogo
var gameState = 0;
var thisScene = 7; // Tela atual;
var nextScene = thisScene; // Seleciona a proxima tela do jogo;
//Variaveis de Canvas
var cnv = canvas;
var ctx = cnv.getContext("2d");
var alpha = 0; // controle do alpha do canvas
var delta = 0.1; // delta = velocidade do efeito de transição de tela
//Trilha Sonora
trilha_GO = new Audio();
trilha_GO.src = "musicas/Game Over.mp3";
trilha_GO.volume = 0.5;
//Sprite do Mapa
var scene = new Image();
scene.src = "img/cenarios/game_Over.png";
//=====================================================================================================================================
//COMANDOS DA TELA
//ativa função de mouseClicked
addEventListener('click', mouseClicked);
//função para tratar clicks na tela
function mouseClicked(e){
if(gameState == thisScene){
nextScene = 1; //MENU INICIAL
gameState = nextScene;
}
}
//=====================================================================================================================================
//ATUALIZAÇÃO DO GAMESTATE
//Função que atualiza o gameState na classe
this.updateGameState = function(_gameState){
gameState = _gameState;
}
//Função que retorna o estado da tela
this.returnState = function(){
if(gameState == thisScene){
return thisScene;
}
else{
trilha_GO.load();
trilha_GO.pause();
return nextScene;
}
}
//=====================================================================================================================================
//FUNÇÕES DO JOGO
//função de inicialização do jogo
this.start = function (){
console.log("Iniciou GAME OVER!");
}
//Função de atualização do jogo
this.loop = function (){
if(gameState == thisScene)
{
this.canvasFade("in");
this.update();
this.draw();
trilha_GO.play();
}
else{
this.canvasFade("out");
console.log("fim do Game Over!");
}
}
//Função de verificações "in game"
this.update = function(){
}
//Função de renderização das imagens
this.draw = function (){
//limpar a tela a cada atualização
ctx.clearRect(0,0,cnv.width,cnv.height);
ctx.drawImage(scene,0,0,scene.width,scene.height,0,0,cnv.width,cnv.height);
}
//Função de efeito de transição
this.canvasFade = function (escolha){
if(escolha == "in"){
if(alpha <= 1){
alpha += delta;
ctx.globalAlpha = alpha;
}
}
if(escolha == "out"){
alpha = 0;
ctx.globalAlpha = alpha;
}
}
}