-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.js
58 lines (49 loc) · 1.26 KB
/
draw.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
class Texture {
constructor(file_name, solid = false) {
this.file_name = file_name;
this.img = new Image();
Texture.total_to_load++;
this.img.onload = function (event) {
Texture.total_loaded++;
}
this.img.src = this.file_name;
this.solid = solid;
}
}
class DrawObject {
constructor(img, x, y, sx, sy, z_offset, time) {
this.img = img;
this.x = x;
this.y = y;
this.sx = sx;
this.sy = sy;
this.z_offset = z_offset;
this.time = time;
}
draw() {
ctx.drawImage(this.img, this.x, this.y, this.sx, this.sy);
this.time--;
}
}
class TextDrawObject extends DrawObject {
constructor(text, color, x, y, sx, sy, z_offset, time = 1) {
super(undefined, x, y, sx, sy, z_offset, time);
// debugger;
this.color = color;
this.text = text;
}
draw() {
// console.log(this.text)
ctx.font = Math.floor(this.sy) + "px Arial";
ctx.fillStyle = this.color;
ctx.fillText(this.text, this.x, this.y, this.sx);
}
}
function addDrawable(img, x, y, sx, sy, z_offset, time = 1) {
drawables.push(new DrawObject(img, x, y, sx, sy, z_offset, time));
}
function addCustomDrawable(drawable) {
drawables.push(drawable);
}
Texture.total_loaded = 0;
Texture.total_to_load = 0;