-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSprite.js
More file actions
74 lines (64 loc) · 1.76 KB
/
Sprite.js
File metadata and controls
74 lines (64 loc) · 1.76 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
function Sprite(params = {}) {
var exemplo = {
x: 0,
y: 0,
vx: 0,
vy: 0,
h: 10,
w: 10,
props: {},
color: "blue",
atirando: 0,
comportar: undefined,
scene: undefined
}
Object.assign(this, exemplo, params);
}
Sprite.prototype = new Sprite();
Sprite.prototype.constructor = Sprite;
Sprite.prototype.desenhar = function (ctx) {
ctx.fillStyle = this.color;
ctx.strokeStyle = "black";
ctx.lineWidth = 1;
ctx.fillRect(this.x, this.y, this.w, this.h);
ctx.strokeRect(this.x, this.y, this.w, this.h);
}
Sprite.prototype.mover = function (dt) {
this.x = this.x + this.vx * dt;
this.y = this.y + this.vy * dt;
if (this.atirando > 0) {
this.atirando = this.atirando - dt;
}
}
Sprite.prototype.desenhaTela = function (ctx) {
ctx.strokeStyle = "black";
ctx.lineWidth = 1;
ctx.fillStyle = "tan";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeRect(0, 0, canvas.width, canvas.height);
}
Sprite.prototype.colidiuCom = function (alvo) {
if (alvo.x + alvo.w < this.x)
return false;
if (alvo.x > this.x + this.w)
return false;
if (alvo.y + alvo.w < this.y)
return false;
if (alvo.y > this.y + this.h)
return false;
return true;
}
Sprite.prototype.pontuacao = function (pontos, ctx) {
ctx.fillStyle = "black";
ctx.strokeStyle = "black";
ctx.font = "19px bold monospaced";
ctx.fillText(pontos, 10, 290);
ctx.strokeText(pontos, 10, 290);
}
Sprite.prototype.gameOver = function (ctx) {
ctx.fillStyle = "red";
ctx.strokeStyle = "red";
ctx.font = "35px bold monospaced";
ctx.fillText("Game Over", 300, 150);
ctx.strokeText("Game Over", 300, 150);
}