Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
neki-dev committed Nov 3, 2023
1 parent 9d24135 commit d6af7b5
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 68 deletions.
23 changes: 22 additions & 1 deletion src/game/scenes/world/entities/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import { Crystal } from '~entity/crystal';
import { Sprite } from '~entity/sprite';
import { Assets } from '~lib/assets';
import { getClosestByIsometricDistance, isPositionsEqual } from '~lib/dimension';
import { Environment } from '~lib/environment';
import { progressionLinear, progressionQuadratic } from '~lib/progression';
import { Tutorial } from '~lib/tutorial';
import { eachEntries } from '~lib/utils';
import { Particles } from '~scene/world/effects';
import { Level } from '~scene/world/level';
import { GameEvents, GameSettings } from '~type/game';
import { GameEvents, GameFlag, GameSettings } from '~type/game';
import { TutorialStep } from '~type/tutorial';
import { IWorld, WorldEvents, WorldMode } from '~type/world';
import { IParticles, ParticlesTexture } from '~type/world/effects';
Expand Down Expand Up @@ -482,6 +483,26 @@ export class Player extends Sprite implements IPlayer {
this.scene.game.sound.play(audio);
}

if (
this.scene.game.isSettingEnabled(GameSettings.EFFECTS)
&& Environment.GetFlag(GameFlag.BLOOD)
) {
new Particles(this, {
key: 'blood',
texture: ParticlesTexture.BIT_SOFT,
dynamic: true,
params: {
duration: 200,
followOffset: this.getBodyOffset(),
lifespan: { min: 100, max: 250 },
scale: { start: 1.0, end: 0.25 },
speed: 60,
maxAliveParticles: 6,
tint: 0xdd1e1e,
},
});
}

super.onDamage(amount);
}

Expand Down
41 changes: 3 additions & 38 deletions src/game/scenes/world/entities/shot/ball/ball.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Phaser from 'phaser';

import { SHOT_BALL_DAMAGE_SPREAD_FACTOR, SHOT_BALL_DAMAGE_SPREAD_MAX_DISTANCE } from '~const/world/entities/shot';
import { Assets } from '~lib/assets';
import { getIsometricDistance } from '~lib/dimension';
import { Particles } from '~scene/world/effects';
Expand Down Expand Up @@ -40,10 +39,8 @@ export class ShotBall extends Phaser.Physics.Arcade.Image implements IShotBall {

private altitude: number = 0;

private spread: boolean = false;

constructor(scene: IWorld, params: ShotParams, {
audio, color, spread = false, glow = false, scale = 1.0,
audio, color, glow = false, scale = 1.0,
}: ShotBallData) {
super(scene, 0, 0, ShotTexture.BALL);
scene.add.existing(this);
Expand All @@ -53,7 +50,6 @@ export class ShotBall extends Phaser.Physics.Arcade.Image implements IShotBall {
this.glow = glow;
this.params = params;
this.audio = audio;
this.spread = spread;

this.setActive(false);
this.setVisible(false);
Expand Down Expand Up @@ -151,40 +147,9 @@ export class ShotBall extends Phaser.Physics.Arcade.Image implements IShotBall {
}
}

private hit(target: IEnemy) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public hit(target: IEnemy) {
this.stop();

const { damage, freeze } = this.params;

if (freeze && target.live.armour <= 0) {
target.freeze(freeze, true);
}

if (damage) {
if (this.spread) {
this.spreadDamage(target, damage * SHOT_BALL_DAMAGE_SPREAD_FACTOR);
}

if (target.active) {
target.live.damage(damage);
}
}
}

private spreadDamage(target: IEnemy, damage: number) {
const position = target.getBottomFace();

this.scene.getEntities<IEnemy>(EntityType.ENEMY).forEach((enemy) => {
if (enemy.active && enemy !== target) {
const distance = getIsometricDistance(position, enemy.getBottomFace());

if (distance < SHOT_BALL_DAMAGE_SPREAD_MAX_DISTANCE) {
const damageByDistance = damage * (1 - (distance / SHOT_BALL_DAMAGE_SPREAD_MAX_DISTANCE));

enemy.live.damage(damageByDistance);
}
}
});
}

private stop() {
Expand Down
57 changes: 56 additions & 1 deletion src/game/scenes/world/entities/shot/ball/variants/fire.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { SHOT_BALL_DAMAGE_SPREAD_FACTOR, SHOT_BALL_DAMAGE_SPREAD_MAX_DISTANCE } from '~const/world/entities/shot';
import { getIsometricDistance } from '~lib/dimension';
import { Particles } from '~scene/world/effects';
import { GameSettings } from '~type/game';
import { IWorld } from '~type/world';
import { ParticlesTexture } from '~type/world/effects';
import { EntityType } from '~type/world/entities';
import { IEnemy } from '~type/world/entities/npc/enemy';
import { ShotBallAudio, ShotData, ShotParams } from '~type/world/entities/shot';

import { ShotBall } from '../ball';
Expand All @@ -10,7 +17,55 @@ export class ShotBallFire extends ShotBall {
audio: ShotBallAudio.FIRE,
color: 0xff5400,
glow: true,
spread: true,
});
}

public hit(target: IEnemy) {
super.hit(target);

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

new Particles(target, {
key: 'fire-mini',
texture: ParticlesTexture.BIT_SOFT,
dynamic: true,
params: {
duration: lifespan,
followOffset: target.getBodyOffset(),
color: [0xfacc22, 0xf89800, 0xf83600, 0x9f0404],
colorEase: 'quad.out',
lifespan: { min: lifespan / 2, max: lifespan },
scale: { start: scale, end: scale * 0.2 },
alpha: { start: 1.0, end: 0.0 },
speed: 80,
},
});
}

if (this.params.damage) {
this.spreadDamage(target, this.params.damage * SHOT_BALL_DAMAGE_SPREAD_FACTOR);

if (target.active) {
target.live.damage(this.params.damage);
}
}
}

private spreadDamage(target: IEnemy, damage: number) {
const position = target.getBottomFace();

this.scene.getEntities<IEnemy>(EntityType.ENEMY).forEach((enemy) => {
if (enemy.active && enemy !== target) {
const distance = getIsometricDistance(position, enemy.getBottomFace());

if (distance < SHOT_BALL_DAMAGE_SPREAD_MAX_DISTANCE) {
const damageByDistance = damage * (1 - (distance / SHOT_BALL_DAMAGE_SPREAD_MAX_DISTANCE));

enemy.live.damage(damageByDistance);
}
}
});
}
}
9 changes: 9 additions & 0 deletions src/game/scenes/world/entities/shot/ball/variants/frozen.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IWorld } from '~type/world';
import { IEnemy } from '~type/world/entities/npc/enemy';
import { ShotBallAudio, ShotData, ShotParams } from '~type/world/entities/shot';

import { ShotBall } from '../ball';
Expand All @@ -12,4 +13,12 @@ export class ShotBallFrozen extends ShotBall {
glow: true,
});
}

public hit(target: IEnemy) {
super.hit(target);

if (this.params.freeze && target.live.armour <= 0) {
target.freeze(this.params.freeze, true);
}
}
}
35 changes: 35 additions & 0 deletions src/game/scenes/world/entities/shot/ball/variants/simple.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Environment } from '~lib/environment';
import { Particles } from '~scene/world/effects';
import { GameSettings, GameFlag } from '~type/game';
import { IWorld } from '~type/world';
import { ParticlesTexture } from '~type/world/effects';
import { IEnemy } from '~type/world/entities/npc/enemy';
import { ShotBallAudio, ShotData, ShotParams } from '~type/world/entities/shot';

import { ShotBall } from '../ball';
Expand All @@ -11,4 +16,34 @@ export class ShotBallSimple extends ShotBall {
color: 0xfff985,
});
}

public hit(target: IEnemy) {
super.hit(target);

if (
this.scene.game.isSettingEnabled(GameSettings.EFFECTS)
&& Environment.GetFlag(GameFlag.BLOOD)
) {
const scale = Math.min(2.0, target.displayWidth / 22);

new Particles(target, {
key: 'blood',
texture: ParticlesTexture.BIT_SOFT,
dynamic: true,
params: {
duration: 200,
followOffset: target.getBodyOffset(),
lifespan: { min: 100, max: 250 },
scale: { start: scale, end: scale * 0.25 },
speed: 60,
maxAliveParticles: 6,
tint: 0xdd1e1e,
},
});
}

if (this.params.damage) {
target.live.damage(this.params.damage);
}
}
}
29 changes: 2 additions & 27 deletions src/game/scenes/world/entities/sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ import { WORLD_COLLIDE_SPEED_FACTOR, WORLD_DEPTH_GRAPHIC } from '~const/world';
import { Indicator } from '~entity/addons/indicator';
import { Live } from '~entity/addons/live';
import { isPositionsEqual } from '~lib/dimension';
import { Environment } from '~lib/environment';
import { Particles } from '~scene/world/effects';
import { Level } from '~scene/world/level';
import { GameFlag, GameSettings } from '~type/game';
import { ILive, LiveEvents } from '~type/live';
import { IWorld } from '~type/world';
import { ParticlesTexture } from '~type/world/effects';
import { EntityType } from '~type/world/entities';
import { IIndicator } from '~type/world/entities/indicator';
import {
Expand Down Expand Up @@ -345,30 +341,9 @@ export class Sprite extends Phaser.Physics.Arcade.Sprite implements ISprite {
this.positionDebug.strokePath();
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this
public onDamage(amount: number) {
if (
!this.scene.game.isSettingEnabled(GameSettings.EFFECTS)
|| !Environment.GetFlag(GameFlag.BLOOD)
) {
return;
}
const scale = Math.min(2.0, this.displayWidth / 22);

new Particles(this, {
key: 'blood',
texture: ParticlesTexture.BIT_SOFT,
dynamic: true,
params: {
duration: 200,
followOffset: this.getBodyOffset(),
lifespan: { min: 100, max: 250 },
scale: { start: scale, end: scale * 0.25 },
speed: 60,
maxAliveParticles: 6,
tint: 0xdd1e1e,
},
});
//
}

public onDead() {
Expand Down
1 change: 0 additions & 1 deletion src/types/world/entities/shot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ export type ShotBallData = ShotData & {
audio: ShotBallAudio
color: number
glow?: boolean
spread?: boolean
};

0 comments on commit d6af7b5

Please sign in to comment.