-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.js
More file actions
53 lines (47 loc) · 1.4 KB
/
classes.js
File metadata and controls
53 lines (47 loc) · 1.4 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
class Sprite {
constructor({position, image, frames = {max: 1}, sprites}) {
this.position = position;
this.image = image;
this.frames = {...frames, val: 0, elapsed: 0};
this.image.onload = () => {
this.width = this.image.width / this.frames.max;
this.height = this.image.height;
}
this.moving = false;
this.sprites = sprites;
}
draw() {
c.drawImage(
this.image,
this.frames.val * this.width,
0,
this.image.width / this.frames.max,
this.image.height,
this.position.x,
this.position.y,
this.image.width / this.frames.max,
this.image.height
);
if (!this.moving) return;
if (this.frames.max > 1){
this.frames.elapsed++
}
if (this.frames.elapsed % 10 === 0) {
if (this.frames.val < this.frames.max - 1) this.frames.val++;
else this.frames.val = 0;
}
}
}
class Boundary {
static width = 48;
static height = 48;
constructor({position}) {
this.position = position;
this.width = 48; // 12px x 400% (the zoom level of the map export)
this.height = 24;
}
draw() {
c.fillStyle = 'rgba(255,0,0,0.0)';
c.fillRect(this.position.x, this.position.y, this.width, this.height);
}
}