52 lines
1.1 KiB
JavaScript
52 lines
1.1 KiB
JavaScript
var asdf = require("asdf-games");
|
|
// eslint-disable-next-line no-unused-vars
|
|
const { Texture, TileSprite, AnimManager, wallslide, entity } = asdf;
|
|
|
|
const texture = new Texture("./res/tilemap.png");
|
|
|
|
class Bullet extends TileSprite {
|
|
constructor(pos, angle, parent, player, level) {
|
|
super(texture, 32, 32);
|
|
this.pos = pos;
|
|
this.pivot = { x: 21, y: 17 };
|
|
this.rotation = angle;
|
|
this.scale = { x: 1, y: 1 };
|
|
this.frame = { x: 1, y: 9 };
|
|
|
|
this.parent = parent;
|
|
this.player = player;
|
|
this.level = level;
|
|
|
|
this.lifetime = 2.5;
|
|
this.speed = 100;
|
|
this.hitBox = {
|
|
x: 4,
|
|
y: 10,
|
|
w: 24,
|
|
h: 14
|
|
};
|
|
}
|
|
|
|
update(dt) {
|
|
this.lifetime -= dt;
|
|
|
|
if (this.lifetime <= 0) {
|
|
this.parent.bullet = false;
|
|
this.dead = true;
|
|
} else {
|
|
if (entity.hit(this, this.player)) {
|
|
this.player.lives -= 1;
|
|
this.parent.bullet = false;
|
|
this.dead = true;
|
|
} else {
|
|
const xo = Math.cos(this.rotation) * 100 * dt;
|
|
const yo = Math.sin(this.rotation) * 100 * dt;
|
|
|
|
this.pos.x += xo;
|
|
this.pos.y += yo;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = Bullet; |