-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform.js
36 lines (33 loc) · 971 Bytes
/
platform.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
class Platform {
constructor(pos, size, sprite) {
this.pos = pos;
this.size = size;
this.sprite = sprite;
}
get halfSize() {
return this.size.copy().div(2);
}
draw() {
for (let xOff = 0; xOff < this.size.x; xOff += this.sprite.width/2) {
image(
this.sprite,
this.pos.x-this.halfSize.x+xOff, // x
this.pos.y-this.halfSize.y, // y
min(this.sprite.width/2, this.size.x-xOff), // width
this.size.y, // height
0, // source x
0, // source y
min(this.sprite.width/2, this.size.x-xOff)*2, // source width
this.size.y*2, // source height
)
}
noFill();
noStroke();
rect(
this.pos.x - this.size.x/2,
this.pos.y - this.size.y/2,
this.size.x,
this.size.y
);
}
}