Skip to content

Commit

Permalink
Fixed effects
Browse files Browse the repository at this point in the history
  • Loading branch information
neki-dev committed Nov 3, 2023
1 parent b4cc813 commit 9d24135
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 23 deletions.
31 changes: 22 additions & 9 deletions src/game/scenes/world/effects/particles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Particles implements IParticles {
constructor(
parent: IParticlesParent,
{
key, position, texture, params, replay = true,
key, position, texture, params, dynamic, replay = false,
}: ParticlesData,
) {
this.scene = parent.scene;
Expand All @@ -47,18 +47,26 @@ export class Particles implements IParticles {
position?.x ?? 0,
position?.y ?? 0,
texture,
params,
{
...params,
follow: dynamic ? parent : undefined,
},
);
this.emitter.setDepth(WORLD_DEPTH_EFFECT);
this.emitter.setDepth(
position?.y ?? parent?.y ?? WORLD_DEPTH_EFFECT,
);

this.destroy = this.destroy.bind(this);
this.update = this.update.bind(this);

this.parent.once(Phaser.GameObjects.Events.DESTROY, this.destroy);

this.parent.on(Phaser.GameObjects.Events.DESTROY, () => {
this.destroy();
});
if (dynamic) {
this.scene.events.on(Phaser.Scenes.Events.UPDATE, this.update);
}

if (params.duration) {
this.emitter.on(Phaser.GameObjects.Particles.Events.COMPLETE, () => {
this.destroy();
});
this.emitter.once(Phaser.GameObjects.Particles.Events.COMPLETE, this.destroy);
}
}

Expand All @@ -67,5 +75,10 @@ export class Particles implements IParticles {
this.emitter.destroy();

this.parent.off(Phaser.GameObjects.Events.DESTROY, this.destroy);
this.scene.events.off(Phaser.Scenes.Events.UPDATE, this.update);
}

private update() {
this.emitter.setDepth(this.parent.depth);
}
}
2 changes: 1 addition & 1 deletion src/game/scenes/world/entities/npc/npc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ export class NPC extends Sprite implements INPC {
new Particles(this, {
key: 'freeze',
texture: ParticlesTexture.BIT_SOFT,
dynamic: true,
params: {
duration: lifespan,
follow: this,
followOffset: this.getBodyOffset(),
color: [0xffffff, 0x8cf9ff, 0x00f2ff],
colorEase: 'quad.out',
Expand Down
3 changes: 2 additions & 1 deletion src/game/scenes/world/entities/npc/variants/enemy/enemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ export class Enemy extends NPC implements IEnemy {
new Particles(this, {
key: 'fire',
texture: ParticlesTexture.BIT_SOFT,
dynamic: true,
replay: true,
params: {
follow: this,
followOffset: this.getBodyOffset(),
duration,
color: [0xfacc22, 0xf89800, 0xf83600, 0x9f0404],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ export class EnemyTelepath extends Enemy {
enemy.live.addHealth(healthAmount);

if (this.scene.game.isSettingEnabled(GameSettings.EFFECTS)) {
new Particles(this, {
new Particles(enemy, {
key: 'regeneration',
texture: ParticlesTexture.PLUS,
replay: false,
dynamic: true,
params: {
follow: enemy,
followOffset: {
x: 0,
y: -enemy.displayHeight,
Expand Down
2 changes: 1 addition & 1 deletion src/game/scenes/world/entities/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,8 @@ export class Player extends Sprite implements IPlayer {
this.dustEffect = new Particles(this, {
key: 'dust',
texture: ParticlesTexture.BIT,
dynamic: true,
params: {
follow: this,
followOffset: {
x: 0,
y: -this.gamut * this.scaleY * 0.5,
Expand Down
2 changes: 1 addition & 1 deletion src/game/scenes/world/entities/shot/ball/ball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export class ShotBall extends Phaser.Physics.Arcade.Image implements IShotBall {
this.effect = new Particles(this, {
key: 'glow',
texture: ParticlesTexture.GLOW,
dynamic: true,
params: {
follow: this,
scale: 0.2 * this.scale,
alpha: { start: 1.0, end: 0.0 },
lifespan: 20000 / this.params.speed,
Expand Down
10 changes: 6 additions & 4 deletions src/game/scenes/world/entities/shot/lazer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,19 @@ export class ShotLazer extends Phaser.GameObjects.Line implements IShotLazer {
}

if (this.scene.game.isSettingEnabled(GameSettings.EFFECTS)) {
const lifespan = Math.min(100, this.displayWidth * 2);
const lifespan = this.target.displayWidth * 5;
const scale = Math.min(2.25, this.target.displayWidth / 18);

new Particles(this, {
new Particles(this.target, {
key: 'lazer',
texture: ParticlesTexture.BIT_SOFT,
dynamic: true,
params: {
duration: lifespan,
follow: this.target,
followOffset: this.target.getBodyOffset(),
lifespan: { min: lifespan / 2, max: lifespan },
scale: { start: 1.0, end: 0.25 },
scale: { start: scale, end: scale * 0.2 },
alpha: { start: 1.0, end: 0.0 },
speed: 80,
tint: 0xb136ff,
},
Expand Down
5 changes: 3 additions & 2 deletions src/game/scenes/world/entities/sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,17 @@ export class Sprite extends Phaser.Physics.Arcade.Sprite implements ISprite {
) {
return;
}
const scale = Math.min(2.0, this.displayWidth / 22);

new Particles(this, {
key: 'blood',
texture: ParticlesTexture.BIT_SOFT,
dynamic: true,
params: {
duration: 200,
follow: this,
followOffset: this.getBodyOffset(),
lifespan: { min: 100, max: 250 },
scale: { start: 1.0, end: 0.5 },
scale: { start: scale, end: scale * 0.25 },
speed: 60,
maxAliveParticles: 6,
tint: 0xdd1e1e,
Expand Down
6 changes: 5 additions & 1 deletion src/types/world/effects/particles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export interface IParticles {
destroy(): void
}

export interface IParticlesParent extends Phaser.GameObjects.GameObject {
export interface IParticlesParent extends
Phaser.GameObjects.GameObject,
Phaser.GameObjects.Components.Transform,
Phaser.GameObjects.Components.Depth {
readonly scene: IWorld

/**
Expand All @@ -37,6 +40,7 @@ export type ParticlesData = {
key?: string
position?: PositionAtWorld
texture: ParticlesTexture
dynamic?: boolean
replay?: boolean
params: Phaser.Types.GameObjects.Particles.ParticleEmitterConfig
};

0 comments on commit 9d24135

Please sign in to comment.