46 lines
1.0 KiB
JavaScript
46 lines
1.0 KiB
JavaScript
import { GameObject } from '../engine/GameObject.js';
|
|
import { Vector2D } from '../engine/Vector2D.js';
|
|
|
|
export class Bullet extends GameObject {
|
|
constructor(
|
|
x,
|
|
y,
|
|
direction,
|
|
{ container, viewport, speed = 800, size = 8, damage = 1, color = [1, 0.2, 0.2, 1] } = {},
|
|
) {
|
|
super(x, y);
|
|
this.velocity = direction.mulS(speed);
|
|
this.container = container;
|
|
this.viewport = viewport;
|
|
this.size = size;
|
|
this.damage = damage;
|
|
this.color = color;
|
|
this.width = size;
|
|
this.height = size;
|
|
}
|
|
|
|
update(dt) {
|
|
super.update(dt);
|
|
|
|
const { width, height } = this.viewport;
|
|
if (
|
|
this.pos.x < -this.size ||
|
|
this.pos.x > width + this.size ||
|
|
this.pos.y < -this.size ||
|
|
this.pos.y > height + this.size
|
|
) {
|
|
this.remove(this.container);
|
|
}
|
|
}
|
|
|
|
draw(renderer) {
|
|
renderer.drawTexture(
|
|
renderer.whiteTexture,
|
|
this.pos.x - this.size / 2,
|
|
this.pos.y - this.size / 2,
|
|
this.size,
|
|
this.size,
|
|
this.color,
|
|
);
|
|
}
|
|
} |