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 4, 2023
1 parent a0cdfd0 commit f837136
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 82 deletions.
Binary file added src/assets/audio/building/electro.mp3
Binary file not shown.
21 changes: 13 additions & 8 deletions src/game/scenes/world/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DIFFICULTY } from '~const/world/difficulty';
import { BUILDING_TILE } from '~const/world/entities/building';
import { BUILDINGS } from '~const/world/entities/buildings';
import { LEVEL_MAP_PERSPECTIVE, LEVEL_MAP_TILE } from '~const/world/level';
import { Analytics } from '~lib/analytics';
import { isPositionsEqual } from '~lib/dimension';
import { phrase } from '~lib/lang';
import { progressionLinear } from '~lib/progression';
Expand Down Expand Up @@ -74,15 +75,19 @@ export class Builder extends Phaser.Events.EventEmitter implements IBuilder {
}

public update() {
if (this.isCanBuild()) {
if (this.isBuild) {
this.updateSupposedPosition();
this.updateBuildInstance();
} else {
this.open();
try {
if (this.isCanBuild()) {
if (this.isBuild) {
this.updateSupposedPosition();
this.updateBuildInstance();
} else {
this.open();
}
} else if (this.isBuild) {
this.close();
}
} else if (this.isBuild) {
this.close();
} catch (error) {
Analytics.TrackWarn('Failed builder update', error as TypeError);
}
}

Expand Down
15 changes: 10 additions & 5 deletions src/game/scenes/world/entities/building/building.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BUILDING_TILE } from '~const/world/entities/building';
import { LEVEL_MAP_PERSPECTIVE } from '~const/world/level';
import { Indicator } from '~entity/addons/indicator';
import { Live } from '~entity/addons/live';
import { Analytics } from '~lib/analytics';
import { Assets } from '~lib/assets';
import { progressionQuadratic, progressionLinear } from '~lib/progression';
import { Tutorial } from '~lib/tutorial';
Expand Down Expand Up @@ -153,12 +154,16 @@ export class Building extends Phaser.GameObjects.Image implements IBuilding, ITi
}

public update() {
this.updateOutline();
this.updateIndicators();
try {
this.updateOutline();
this.updateIndicators();

// Catch focus by camera moving
if (this.toFocus) {
this.focus();
// Catch focus by camera moving
if (this.toFocus) {
this.focus();
}
} catch (error) {
Analytics.TrackWarn('Failed building update', error as TypeError);
}
}

Expand Down
18 changes: 13 additions & 5 deletions src/game/scenes/world/entities/building/variants/electro.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { DIFFICULTY } from '~const/world/difficulty';
import { LEVEL_MAP_PERSPECTIVE } from '~const/world/level';
import { Analytics } from '~lib/analytics';
import { progressionLinear } from '~lib/progression';
import { Building } from '~scene/world/entities/building';
import { IWorld } from '~type/world';
import { EntityType } from '~type/world/entities';
import {
BuildingAudio,
BuildingCategory,
BuildingEvents,
BuildingIcon,
Expand Down Expand Up @@ -63,12 +65,14 @@ export class BuildingElectro extends Building implements IBuilding {
public update() {
super.update();

if (!this.isActionAllowed()) {
return;
try {
if (this.isActionAllowed()) {
this.attack();
this.pauseActions();
}
} catch (error) {
Analytics.TrackWarn('Failed electro building update', error as TypeError);
}

this.attack();
this.pauseActions();
}

public getInfo() {
Expand Down Expand Up @@ -149,6 +153,10 @@ export class BuildingElectro extends Building implements IBuilding {
}
});

if (this.scene.game.sound.getAll(BuildingAudio.ELECTRO).length === 0) {
this.scene.game.sound.play(BuildingAudio.ELECTRO);
}

if (this.area) {
this.area.setActive(true);
this.area.setVisible(true);
Expand Down
13 changes: 8 additions & 5 deletions src/game/scenes/world/entities/building/variants/generator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DIFFICULTY } from '~const/world/difficulty';
import { Building } from '~entity/building';
import { Analytics } from '~lib/analytics';
import { Tutorial } from '~lib/tutorial';
import { TutorialStep } from '~type/tutorial';
import { IWorld } from '~type/world';
Expand Down Expand Up @@ -47,12 +48,14 @@ export class BuildingGenerator extends Building {
public update() {
super.update();

if (!this.isActionAllowed()) {
return;
try {
if (this.isActionAllowed()) {
this.generateResource();
this.pauseActions();
}
} catch (error) {
Analytics.TrackWarn('Failed generator building update', error as TypeError);
}

this.generateResource();
this.pauseActions();
}

public getTopFace() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DIFFICULTY } from '~const/world/difficulty';
import { Building } from '~entity/building';
import { Analytics } from '~lib/analytics';
import { getClosestByIsometricDistance } from '~lib/dimension';
import { progressionLinear } from '~lib/progression';
import { Tutorial } from '~lib/tutorial';
Expand Down Expand Up @@ -55,8 +56,12 @@ export class BuildingTower extends Building implements IBuildingTower {
public update() {
super.update();

if (this.isCanAttack()) {
this.attack();
try {
if (this.isCanAttack()) {
this.attack();
}
} catch (error) {
Analytics.TrackWarn('Failed tower building update', error as TypeError);
}
}

Expand Down
23 changes: 14 additions & 9 deletions src/game/scenes/world/entities/npc/npc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { WORLD_DEPTH_GRAPHIC } from '~const/world';
import { NPC_PATH_FIND_RATE } from '~const/world/entities/npc';
import { LEVEL_MAP_PERSPECTIVE } from '~const/world/level';
import { Sprite } from '~entity/sprite';
import { Analytics } from '~lib/analytics';
import { isPositionsEqual, getIsometricAngle, getIsometricDistance } from '~lib/dimension';
import { Level } from '~scene/world/level';
import { IWorld } from '~type/world';
Expand Down Expand Up @@ -66,18 +67,22 @@ export class NPC extends Sprite implements INPC {
public update() {
super.update();

if (this.isCanPursuit()) {
if (this.getDistanceToTarget() <= this.pathFindTriggerDistance) {
this.resetPath();
this.isPathPassed = true;
try {
if (this.isCanPursuit()) {
if (this.getDistanceToTarget() <= this.pathFindTriggerDistance) {
this.resetPath();
this.isPathPassed = true;
} else {
this.findPathToTarget();
this.moveByPath();
this.isPathPassed = false;
}
} else {
this.findPathToTarget();
this.moveByPath();
this.setVelocity(0, 0);
this.isPathPassed = false;
}
} else {
this.setVelocity(0, 0);
this.isPathPassed = false;
} catch (error) {
Analytics.TrackWarn('Failed NPC update', error as TypeError);
}
}

Expand Down
15 changes: 10 additions & 5 deletions src/game/scenes/world/entities/npc/variants/assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ASSISTANT_PATH_BREAKPOINT, ASSISTANT_TILE_SIZE, ASSISTANT_WEAPON } from
import { NPC } from '~entity/npc';
import { ShotBallFire } from '~entity/shot/ball/variants/fire';
import { ShotLazer } from '~entity/shot/lazer';
import { Analytics } from '~lib/analytics';
import { Assets } from '~lib/assets';
import { getClosestByIsometricDistance, getIsometricDistance } from '~lib/dimension';
import { progressionQuadratic } from '~lib/progression';
Expand Down Expand Up @@ -63,12 +64,16 @@ export class Assistant extends NPC implements IAssistant {
public update() {
super.update();

if (this.isPathPassed) {
this.setVelocity(0, 0);
}
try {
if (this.isPathPassed) {
this.setVelocity(0, 0);
}

if (this.isCanAttack()) {
this.attack();
if (this.isCanAttack()) {
this.attack();
}
} catch (error) {
Analytics.TrackWarn('Failed assistant update', error as TypeError);
}
}

Expand Down
17 changes: 11 additions & 6 deletions src/game/scenes/world/entities/npc/variants/enemy/enemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '~const/world/entities/enemy';
import { Building } from '~entity/building';
import { NPC } from '~entity/npc';
import { Analytics } from '~lib/analytics';
import { Assets } from '~lib/assets';
import { progressionLinear, progressionQuadratic } from '~lib/progression';
import { GameSettings } from '~type/game';
Expand Down Expand Up @@ -124,13 +125,17 @@ export class Enemy extends NPC implements IEnemy {
public update() {
super.update();

if (this.isOverlapTarget) {
this.setVelocity(0, 0);
} else if (this.isPathPassed) {
this.moveTo(this.scene.player.getBottomFace());
}
try {
if (this.isOverlapTarget) {
this.setVelocity(0, 0);
} else if (this.isPathPassed) {
this.moveTo(this.scene.player.getBottomFace());
}

this.isOverlapTarget = false;
this.isOverlapTarget = false;
} catch (error) {
Analytics.TrackWarn('Failed enemy update', error as TypeError);
}
}

public overlapTarget() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ENEMY_HEAL_MULTIPLIER, ENEMY_HEAL_TIMESTAMP_PAUSE } from '~const/world/entities/enemy';
import { Analytics } from '~lib/analytics';
import { IWorld } from '~type/world';
import { EnemyVariantData, EnemyTexture } from '~type/world/entities/npc/enemy';

Expand All @@ -23,8 +24,13 @@ export class EnemyBerserk extends Enemy {
}

public update() {
this.heal();
super.update();

try {
this.heal();
} catch (error) {
Analytics.TrackWarn('Failed berserk enemy update', error as TypeError);
}
}

private heal() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Analytics } from '~lib/analytics';
import { IWorld } from '~type/world';
import { BuildingVariant } from '~type/world/entities/building';
import { EnemyVariantData, EnemyTexture } from '~type/world/entities/npc/enemy';
Expand Down Expand Up @@ -25,6 +26,14 @@ export class EnemyGhost extends Enemy {
public update() {
super.update();

try {
this.updateVisible();
} catch (error) {
Analytics.TrackWarn('Failed ghost enemy update', error as TypeError);
}
}

private updateVisible() {
const isVisible = this.scene.builder
.getBuildingsByVariant(BuildingVariant.RADAR)
.some((building) => building.actionsAreaContains(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ENEMY_REGENERATION_EFFECT_COLOR, ENEMY_REGENERATION_EFFECT_DURATION, ENEMY_REGENERATION_RADIUS,
} from '~const/world/entities/enemy';
import { LEVEL_MAP_PERSPECTIVE } from '~const/world/level';
import { Analytics } from '~lib/analytics';
import { getIsometricDistance } from '~lib/dimension';
import { IWorld } from '~type/world';
import { EntityType } from '~type/world/entities';
Expand Down Expand Up @@ -41,11 +42,21 @@ export class EnemyTelepath extends Enemy {
public update() {
super.update();

if (this.regenerateArea.visible) {
const position = this.getBottomFace();
try {
this.updateArea();
} catch (error) {
Analytics.TrackWarn('Failed telepth enemy update', error as TypeError);
}
}

this.regenerateArea.setPosition(position.x, position.y);
private updateArea() {
if (!this.regenerateArea.visible) {
return;
}

const position = this.getBottomFace();

this.regenerateArea.setPosition(position.x, position.y);
}

public onDamage(amount: number) {
Expand Down
21 changes: 13 additions & 8 deletions src/game/scenes/world/entities/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { LEVEL_MAP_PERSPECTIVE } from '~const/world/level';
import { Crystal } from '~entity/crystal';
import { Sprite } from '~entity/sprite';
import { Analytics } from '~lib/analytics';
import { Assets } from '~lib/assets';
import { getClosestByIsometricDistance, isPositionsEqual } from '~lib/dimension';
import { progressionLinear, progressionQuadratic } from '~lib/progression';
Expand Down Expand Up @@ -184,16 +185,20 @@ export class Player extends Sprite implements IPlayer {
public update() {
super.update();

this.findPathToCrystal();
this.drawPathToCrystal();
try {
this.findPathToCrystal();
this.drawPathToCrystal();

if (!this.live.isDead()) {
this.dustEffect?.emitter.setDepth(this.depth - 1);
if (!this.live.isDead()) {
this.dustEffect?.emitter.setDepth(this.depth - 1);

this.updateMovement();
this.updateVelocity();
this.updateVisible();
this.updateStamina();
this.updateMovement();
this.updateVelocity();
this.updateVisible();
this.updateStamina();
}
} catch (error) {
Analytics.TrackWarn('Failed player update', error as TypeError);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/game/scenes/world/entities/shot/ball/ball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,17 @@ export class ShotBall extends Phaser.Physics.Arcade.Image implements IShotBall {
}

public update() {
try {
this.updateFlyDistance();
} catch (error) {
Analytics.TrackWarn('Failed ball shot update', error as TypeError);
}
}

private updateFlyDistance() {
if (!this.params.maxDistance || !this.startPosition) {
this.stop();

return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/scenes/world/entities/shot/lazer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class ShotLazer extends Phaser.GameObjects.Line implements IShotLazer {
this.updateLine();
this.processing();
} catch (error) {
Analytics.TrackWarn('Failed lazer update', error as TypeError);
Analytics.TrackWarn('Failed lazer shot update', error as TypeError);
}
}

Expand Down
Loading

0 comments on commit f837136

Please sign in to comment.