-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblip.ts
27 lines (25 loc) · 954 Bytes
/
blip.ts
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
namespace asteroids {
/**
* A blip is a projectile shot by a ship or saucer.
*/
export class Blip extends PolygonSprite {
public body: Body;
public startTime: number;
public onBlipCollision: (blip: Blip, other: Sprite) => void;
constructor() {
super(shapes.Blip, {
kind: ObjKind.Blip
});
this.body = new Body(this, (other) => this.onCollision(other));
this.imprecise = true; // imprecise blip shape looks better at more angles.
}
onCollision(other: Sprite) {
this.onBlipCollision && this.onBlipCollision(this, other);
// Blip assumes it was shot by a ship here. Will need to change once saucers are added!
if (other.kind === ObjKind.Rock || other.kind === ObjKind.Saucer) {
this.body.enabled = false;
this.visible = false;
}
}
}
}