-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsprite.js
More file actions
96 lines (82 loc) · 2.63 KB
/
sprite.js
File metadata and controls
96 lines (82 loc) · 2.63 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
var
s_dog,
s_bg,
s_fg,
s_pipeNorth,
s_pipeSouth,
s_text,
s_score,
s_splash,
s_buttons,
s_numberS,
s_numberB,
s_medals;
function Sprite(img, x, y, width, height) {
this.img = img;
this.x = x * 2;
this.y = y * 2;
this.width = width * 2;
this.height = height * 2;
};
Sprite.prototype.draw = function (ctx, x, y) {
ctx.drawImage(this.img, this.x, this.y, this.width, this.height,
x, y, this.width, this.height);
};
function initSprites(img) {
s_dog = [
// new Sprite(img, 156, 115, 17, 12),
// new Sprite(img, 156, 128, 17, 12),
// new Sprite(img, 156, 141, 17, 12)
new Sprite(img, 215, 120, 36, 62),
new Sprite(img, 252, 120, 27, 62),
new Sprite(img, 271, 57, 34, 62)
];
s_medals = {
Bronze: new Sprite(img, 197, 137, 23, 23),
Silver: new Sprite(img, 197, 114, 23, 23),
Gold: new Sprite(img, 173, 137, 23, 23),
Platinum: new Sprite(img, 173, 114, 23, 23)
},
s_bg = new Sprite(img, 0, 0, 138, 114);
s_bg.color = "#70C5CF";
s_fg = new Sprite(img, 138, 0, 160, 26);
//s_pipeNorth = new Sprite(img, 251, 0, 10, 200);
s_pipeNorth = new Sprite(img, 253, 57, 20, 35);
//s_pipeSouth = new Sprite(img, 277, 0, 10, 200);
//pajaro
s_pipeSouth = new Sprite(img, 283, 126, 14, 14);
s_text = {
Flappydog: new Sprite(img, 59, 114, 96, 22),
GameOver: new Sprite(img, 59, 136, 94, 19),
GetReady: new Sprite(img, 59, 155, 87, 22)
}
s_buttons = {
Rate: new Sprite(img, 79, 177, 40, 14),
Menu: new Sprite(img, 119, 177, 40, 14),
Share: new Sprite(img, 159, 177, 40, 14),
Score: new Sprite(img, 79, 191, 40, 14),
Ok: new Sprite(img, 119, 191, 40, 14),
Start: new Sprite(img, 159, 191, 40, 14),
Test : new Sprite(img, 119,177,40,14)
}
s_score = new Sprite(img, 138, 56, 113, 58);
s_splash = new Sprite(img, 0, 130, 59, 39);
s_numberS = new Sprite(img, 0, 177, 6, 7);
s_numberB = new Sprite(img, 0, 188, 7, 10);
s_numberS.draw = s_numberB.draw = function (ctx, x, y, num, center, offset) {
num = num.toString();
var step = this.width + 2;
if (center) {
x = center - (num.length * step - 1) / 2;
}
if (offset) {
x += step * (offset - num.length);
}
for (var i = 0, len = num.length; i < len; i++) {
var n = parseInt(num[i]);
ctx.drawImage(img, step * n, this.y, this.width, this.height,
x, y, this.width, this.height)
x += step;
}
}
}