From 6d52abee3eaee4ce34de2bb130f74aae52cf6325 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Fri, 2 Feb 2024 22:00:37 +0100 Subject: [PATCH] fix: collectable should not kill the ship --- src/app/models/pixijs/animated-game-sprite.ts | 3 ++- src/app/models/pixijs/simple-game-sprite.ts | 1 + src/app/services/game-collectable.service.ts | 1 + src/app/utils/sprite.util.ts | 4 ++-- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/app/models/pixijs/animated-game-sprite.ts b/src/app/models/pixijs/animated-game-sprite.ts index 76a2a98..733a5d8 100644 --- a/src/app/models/pixijs/animated-game-sprite.ts +++ b/src/app/models/pixijs/animated-game-sprite.ts @@ -6,8 +6,9 @@ import { ObjectType } from './object-type.enum'; export class AnimatedGameSprite extends AnimatedSprite { protected readonly speed: number = 1; - protected _energy: number | undefined; + + power = 1; reference: ObjectModelType | undefined; destroying = false; targetX?: number; diff --git a/src/app/models/pixijs/simple-game-sprite.ts b/src/app/models/pixijs/simple-game-sprite.ts index aa928e4..608415f 100644 --- a/src/app/models/pixijs/simple-game-sprite.ts +++ b/src/app/models/pixijs/simple-game-sprite.ts @@ -8,6 +8,7 @@ export class GameSprite extends Sprite { private readonly ySpeed: number; private readonly xSpeed: number; + power = 1; reference: ObjectModelType | undefined; energy: number | undefined; destroying = false; diff --git a/src/app/services/game-collectable.service.ts b/src/app/services/game-collectable.service.ts index bbf905c..4a07b91 100644 --- a/src/app/services/game-collectable.service.ts +++ b/src/app/services/game-collectable.service.ts @@ -55,6 +55,7 @@ export class GameCollectableService extends UpdatableService { powerUp.anchor.set(0.5); powerUp.x = x; powerUp.y = y; + powerUp.power = 0; this.application.stage.addChild(powerUp); this.collectables.push(powerUp); } diff --git a/src/app/utils/sprite.util.ts b/src/app/utils/sprite.util.ts index 747dfa4..28f1c27 100644 --- a/src/app/utils/sprite.util.ts +++ b/src/app/utils/sprite.util.ts @@ -18,13 +18,13 @@ export function hit(spriteA: ObjectModelType, spriteB: ObjectModelType): boolean && bounds1.y + bounds1.height > bounds2.y; if (itemHit) { if (spriteA.energy !== undefined) { - spriteA.energy -= 1; + spriteA.energy -= spriteB.power; if (spriteA.energy <= 0) { spriteA.explode(); } } if (spriteB.energy !== undefined) { - spriteB.energy -= 1; + spriteB.energy -= spriteA.power; if (spriteB.energy <= 0) { spriteB.explode(); }