diff --git a/src/app/models/pixijs/simple-game-sprite.ts b/src/app/models/pixijs/simple-game-sprite.ts index 98a2624..988b911 100644 --- a/src/app/models/pixijs/simple-game-sprite.ts +++ b/src/app/models/pixijs/simple-game-sprite.ts @@ -5,6 +5,8 @@ export class GameSprite extends Sprite { private readonly ySpeed: number; private readonly xSpeed: number; + power: number | undefined; + constructor(speed: number, texture: Texture) { super(texture); @@ -19,6 +21,10 @@ export class GameSprite extends Sprite { } hit(object2: Sprite): boolean { - return hit(this, object2); + const event = hit(this, object2); + if (event && this.power !== undefined) { + this.power -= 1; + } + return event; } } diff --git a/src/app/services/game-meteor.service.ts b/src/app/services/game-meteor.service.ts index 87fe3a7..6fa7025 100644 --- a/src/app/services/game-meteor.service.ts +++ b/src/app/services/game-meteor.service.ts @@ -31,12 +31,13 @@ export class GameMeteorService extends BaseService { update(delta: number, level: number): void { this.elapsed += delta; + this.#meteors = this.#meteors.filter(meteor => !meteor.destroyed); this.#meteors .filter(meteor => meteor.y > this.application.screen.height + 50) .forEach(meteor => meteor.destroy()); - this.#meteors = this.#meteors.filter(enemy => !enemy.destroyed); + this.#meteors = this.#meteors.filter(meteor => !meteor.destroyed); - this.#meteors.forEach(enemy => enemy.update(delta)); + this.#meteors.forEach(meteor => meteor.update(delta)); const check = Math.floor(this.elapsed); if (((check % Math.floor(60 / (GAME_CONFIG.meteor.autoSpawnSpeed + (0.1 * (level - 1))))) === 0) @@ -48,10 +49,14 @@ export class GameMeteorService extends BaseService { hit(shots: AnimatedGameSprite[]): number { for (const shot of shots.filter(s => !s.destroyed)) { - const hit = this.meteors.find(enemy => !enemy.destroyed && shot.hit(enemy)); + const hit = this.meteors.find(meteor => !meteor.destroyed && meteor.hit(shot)); if (hit) { this.explode(hit.x, hit.y); shot.destroy(); + + if (hit.power === 0) { + hit.destroy(); + } } } @@ -82,6 +87,7 @@ export class GameMeteorService extends BaseService { meteor.y = 10; meteor.width += Math.random() * 20; meteor.height += Math.random() * 20; + meteor.power = 10; this.#meteors.push(meteor); this.application.stage.addChild(meteor); }