generated from irm1005-itec1005-fall-2023/template-assignment-05
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ground.js
46 lines (39 loc) · 1 KB
/
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/Empty.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;
}
}