initial commit
This commit is contained in:
commit
e8c3f9862a
193 files changed
+29795
No files matched your search
@@ -0,0 +1,46 @@
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user