-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.js
55 lines (51 loc) · 1.64 KB
/
classes.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
// class definining
class Sprite {
constructor({ position, image, frames = {col: 1, row: 1, hold: 10}, animate = false}) {
this.position = position
this.image = image
this.frames = {...frames, colVal: 0, rowVal: 0, elapsed: 0}
this.image.onload = () => {
this.width = this.image.width / this.frames.col
this.height = this.image.height / this.frames.row
// console.log(this.width)
// console.log(this.height)
}
this.animate = animate
}
draw() {
c.drawImage(
this.image,
this.frames.colVal * this.width,
this.frames.rowVal * this.height,
this.image.width / this.frames.col,
this.image.height / this.frames.row,
this.position.x,
this.position.y,
this.image.width / this.frames.col,
this.image.height / this.frames.row
)
if (!this.animate) return
if (this.frames.col > 1){
this.frames.elapsed++
}
if (this.frames.elapsed % this.frames.hold === 0) {
if (this.frames.colVal < this.frames.col - 1) this.frames.colVal++
else this.frames.colVal = 0
}
}
}
// define booundaries class
class Boundary {
// static property for zoomed in map image (16px actual x 4 zoom)
static width = 64
static height = 64
constructor({position}) {
this.position = position
this.width = 64
this.height = 64
}
draw() {
c.fillStyle = "rgba(255, 0, 0, 0)"
c.fillRect(this.position.x, this.position.y, this.width, this.height)
}
};