-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGround.js
46 lines (39 loc) · 874 Bytes
/
Ground.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
export default class Ground {
constructor(ctx, width, height, speed, scaleRatio) {
this.ctx = ctx;
this.canvas = ctx.canvas;
this.width = width;
this.height = height;
this.speed = speed;
this.scaleRatio = scaleRatio;
this.x = 0;
this.y = this.canvas.height - this.height;
this.groundImage = new Image();
this.groundImage.src = "./images/ground.png";
}
update(gameSpeed, frameTimeDelta) {
this.x -= gameSpeed * frameTimeDelta * this.speed * this.scaleRatio;
}
draw() {
this.ctx.drawImage(
this.groundImage,
this.x,
this.y,
this.width,
this.height
);
this.ctx.drawImage(
this.groundImage,
this.x + this.width,
this.y,
this.width,
this.height
);
if (this.x < -this.width) {
this.x = 0;
}
}
reset() {
this.x = 0;
}
}