-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeoxys.js
70 lines (61 loc) · 2.01 KB
/
deoxys.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
function Deoxys(context, imagem, imagem2, imgExplosao) {
this.context = context;
this.imagem = imagem;
this.imagem2 = imagem2;
this.x = 0;
this.y = 0;
this.velocidade = 0;
this.imgExplosao = imgExplosao;
this.spritesheet = new Spritesheet(context, imagem, 1, 2);
this.spritesheet2 = new Spritesheet(context, imagem2, 1, 2);
this.deoxys_vida = 8;
}
Deoxys.prototype = {
atualizar: function() {
this.y +=
this.velocidade * this.animacao.decorrido / 1000;
if (this.y > this.context.canvas.height) {
this.animacao.excluirSprite(this);
this.colisor.excluirSprite(this);
}
},
desenhar: function() {
if(this.deoxys_vida == 8) {
this.spritesheet.desenhar(this.x, this.y);
this.spritesheet.proximoQuadro();
}
if(this.deoxys_vida < 8) {
this.spritesheet2.desenhar(this.x, this.y);
this.spritesheet2.proximoQuadro();
}
},
retangulosColisao: function() {
// Estes valores vão sendo ajustados aos poucos
var rets =
[
{x: this.x, y: this.y, largura: 57, altura: 47}
];
return rets;
},
colidiuCom: function(outro) {
// Se colidiu com um Tiro, os dois desaparecem
if (outro instanceof Tiro) {
if(this.deoxys_vida >= 0) {
var explosao = new Explosao(this.context, this.imgExplosao,
this.x, this.y, 'snd/deoxys-cry.mp3');
this.animacao.novoSprite(explosao);
this.deoxys_vida = this.deoxys_vida - 1;
this.velocidade = 500;
}
if(this.deoxys_vida == 0) {
this.animacao.excluirSprite(this);
this.colisor.excluirSprite(this);
this.animacao.excluirSprite(outro);
this.colisor.excluirSprite(outro);
var explosao = new Explosao(this.context, this.imgExplosao,
this.x, this.y, 'snd/explosao.mp3');
this.animacao.novoSprite(explosao);
}
}
}
}