Skip to content

Commit

Permalink
fix: collectable should not kill the ship
Browse files Browse the repository at this point in the history
  • Loading branch information
rengert committed Feb 2, 2024
1 parent dae779c commit 6d52abe
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/app/models/pixijs/animated-game-sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/app/models/pixijs/simple-game-sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/app/services/game-collectable.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/utils/sprite.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 6d52abe

Please sign in to comment.