generated from irm1005-itec1005-fall-2023/template-assignment-05
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asteroid.js
33 lines (29 loc) · 858 Bytes
/
asteroid.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
export default class Asteroid{
constructor(ctx, x, y, width, height, image){
this.ctx = ctx;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.image = image;
}
update(speed, gamespeed, frameTimeDelta, scaleRatio) {
this.x -= speed * gamespeed * frameTimeDelta * scaleRatio;
}
draw(){
this.ctx.drawImage(this.image, this.x, this.y, this.width, this.height)
}
collideWith(sprite) {
const adjustBy = 1.4;
if (
sprite.x < this.x + this.width / adjustBy &&
sprite.x + sprite.width / adjustBy > this.x &&
sprite.y < this.y + this.height / adjustBy &&
sprite.height + sprite.y / adjustBy > this.y
) {
return true;
} else {
return false;
}
}
}