var asdf = require("asdf-games"); // eslint-disable-next-line no-unused-vars const { Texture, TileSprite, deadInTracks, entity } = asdf; const texture = new Texture(__dirname + "/../../res/images/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; const r = deadInTracks.deadInTracks(this, this.level, xo, yo); if (r.x == 0 || r.y == 0) { this.parent.bullet = false; this.dead = true; } else { this.pos.x += xo; this.pos.y += yo; } } } } } module.exports = Bullet;