-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.js
59 lines (53 loc) · 1.42 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
56
57
58
59
class Sprite{
constructor(
{position,
velocity,
image,
width,
height,
frames = {max:1 , hold:2}
}){
this.position = position;
this.image = image
this.frames = { ...frames, val: 0, elapsed: 0 }
this.width = width/this.frames.max
this.height = height
console.log(this.width)
console.log(this.height)
this.moving = false
}
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 % this.frames.hold === 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
this.height = 48
}
draw(){
c.fillStyle ="rgba(255,0,0,0.08)"
c.fillRect(this.position.x,this.position.y,this.width,this.height)
}
}