Skip to content

Commit

Permalink
Fixed spawn effect
Browse files Browse the repository at this point in the history
  • Loading branch information
neki-dev committed Nov 4, 2023
1 parent dae7037 commit 386982c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 36 deletions.
30 changes: 1 addition & 29 deletions src/game/scenes/world/entities/npc/variants/enemy/enemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ export class Enemy extends NPC implements IEnemy {

private damageLabelTween: Nullable<Phaser.Tweens.Tween> = null;

private spawnEffect: boolean;

constructor(scene: IWorld, {
texture, score, multipliers, spawnEffect = true, ...data
texture, score, multipliers, ...data
}: EnemyData) {
super(scene, {
...data,
Expand Down Expand Up @@ -82,7 +80,6 @@ export class Enemy extends NPC implements IEnemy {
scale: DIFFICULTY.ENEMY_DAMAGE_GROWTH,
level: scene.wave.number,
});
this.spawnEffect = spawnEffect;
this.score = score ?? 1;
this.might = multipliers.might;

Expand All @@ -94,10 +91,6 @@ export class Enemy extends NPC implements IEnemy {

this.handlePlayerSuperskill();

if (this.spawnEffect) {
this.addSpawnEffect();
}

const frost = this.scene.player.activeSuperskills[PlayerSuperskill.FROST];

if (frost) {
Expand Down Expand Up @@ -262,27 +255,6 @@ export class Enemy extends NPC implements IEnemy {
}
}

private addSpawnEffect() {
this.freeze(750);

setTimeout(() => {
const originAlpha = this.alpha;

this.container.setAlpha(0.0);
this.setAlpha(0.0);
this.scene.tweens.add({
targets: this,
alpha: originAlpha,
duration: 750,
onComplete: () => {
this.container.setAlpha(originAlpha);
},
});
}, 0);

this.scene.fx.createSpawnEffect(this);
}

private handlePlayerSuperskill() {
const handler = (type: PlayerSuperskill) => {
const superskill = this.scene.player.activeSuperskills[type];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class EnemyStranger extends Enemy {

offsets.forEach((offset) => {
new EnemyInstance(this.scene, {
spawnEffect: false,
positionAtWorld: {
x: this.x + offset.x,
y: this.y + offset.y,
Expand Down
24 changes: 19 additions & 5 deletions src/game/scenes/world/wave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TutorialStep } from '~type/tutorial';
import { IWorld, WorldEvents, WorldMode } from '~type/world';
import { EntityType } from '~type/world/entities';
import { EnemyVariant } from '~type/world/entities/npc/enemy';
import { PositionAtMatrix } from '~type/world/level';
import {
IWave, WaveAudio, WaveEvents, WaveSavePayload,
} from '~type/world/wave';
Expand Down Expand Up @@ -250,13 +251,26 @@ export class Wave extends Phaser.Events.EventEmitter implements IWave {
this.createEnemy(variant);
}

private createEnemy(variant: EnemyVariant) {
private async createEnemy(variant: EnemyVariant) {
const EnemyInstance = ENEMIES[variant];
const positionAtMatrix: PositionAtMatrix = await this.scene.spawner.getSpawnPosition();
const enemy = new EnemyInstance(this.scene, { positionAtMatrix });
const originAlpha = enemy.alpha;

this.scene.spawner.getSpawnPosition()
.then((positionAtMatrix) => {
new EnemyInstance(this.scene, { positionAtMatrix });
});
enemy.freeze(750);

this.scene.fx.createSpawnEffect(enemy);

enemy.container.setAlpha(0.0);
enemy.setAlpha(0.0);
this.scene.tweens.add({
targets: enemy,
alpha: originAlpha,
duration: 750,
onComplete: () => {
enemy.container.setAlpha(enemy.alpha);
},
});
}

private getEnemyVariant() {
Expand Down
1 change: 0 additions & 1 deletion src/types/world/entities/npc/enemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export type EnemySizeParams = {
};

export type EnemyVariantData = {
spawnEffect?: boolean
positionAtMatrix?: PositionAtMatrix
positionAtWorld?: PositionAtWorld
};
Expand Down

0 comments on commit 386982c

Please sign in to comment.