Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
neki-dev committed Oct 10, 2023
1 parent 7c6e5ac commit 1f4f3bd
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 39 deletions.
6 changes: 3 additions & 3 deletions src/game/scenes/world/entities/building/building.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export class Building extends Phaser.GameObjects.Image implements IBuilding, ITi
}

public addIndicator() {
if (this.indicator) {
if (this.indicator || !this.active) {
return;
}

Expand Down Expand Up @@ -508,7 +508,7 @@ export class Building extends Phaser.GameObjects.Image implements IBuilding, ITi
this.alertIcon = this.scene.add.image(this.x, this.y, BuildingIcon.ALERT);
this.alertIcon.setDepth(this.depth + 1);

this.alertTween = <Phaser.Tweens.Tween> this.scene.tweens.add({
this.alertTween = this.scene.tweens.add({
targets: this.alertIcon,
alpha: { from: 1.0, to: 0.0 },
duration: 500,
Expand Down Expand Up @@ -538,7 +538,7 @@ export class Building extends Phaser.GameObjects.Image implements IBuilding, ITi
this.upgradeIcon = this.scene.add.image(this.x, this.y, BuildingIcon.UPGRADE);
this.upgradeIcon.setDepth(this.depth + 1);

this.upgradeTween = <Phaser.Tweens.Tween> this.scene.tweens.add({
this.upgradeTween = this.scene.tweens.add({
targets: this.upgradeIcon,
y: { from: this.y, to: this.y - 32 },
alpha: { from: 1.0, to: 0.0 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ export class BuildingAmmunition extends Building implements IBuildingAmmunition

this.on(BuildingEvents.UPGRADE, this.onUpgrade.bind(this));

this.bindTutorialHint(TutorialStep.BUY_AMMO, 'Click to buy ammo', () => this.ammo === 0);
this.bindTutorialHint(
TutorialStep.BUY_AMMO,
this.scene.game.device.os.desktop
? 'Hover and press [F]\nto buy ammo'
: 'Click to buy ammo',
() => this.ammo === 0,
);

this.bindHotKey(CONTROL_KEY.BUILDING_BUY_AMMO, () => this.buyAmmo());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class BuildingTowerFire extends BuildingTower {
this.bindTutorialHint(
TutorialStep.UPGRADE_BUILDING,
this.scene.game.device.os.desktop
? 'Hover and press [E] to upgrade'
? 'Hover and press [E]\nto upgrade'
: 'Click to upgrade',
);

Expand Down
83 changes: 54 additions & 29 deletions src/game/scenes/world/entities/npc/variants/enemy/enemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Enemy extends NPC implements IEnemy {

private isOverlapTarget: boolean = false;

private damageLabel: Nullable<Phaser.GameObjects.Container> = null;
private damageLabel: Nullable<Phaser.GameObjects.Text> = null;

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

Expand Down Expand Up @@ -92,6 +92,7 @@ export class Enemy extends NPC implements IEnemy {
this.body.setCircle((this.width * 0.5) - 2);
this.body.setOffset(2, 2);

this.addDamageLabel();
this.addIndicator({
color: 0xdb2323,
value: () => this.live.health / this.live.maxHealth,
Expand All @@ -112,6 +113,7 @@ export class Enemy extends NPC implements IEnemy {
this.on(NPCEvent.PATH_NOT_FOUND, this.onPathNotFound.bind(this));

this.on(Phaser.GameObjects.Events.DESTROY, () => {
this.removeDamageLabel();
if (this.damageTimer) {
this.damageTimer.destroy();
}
Expand Down Expand Up @@ -159,47 +161,70 @@ export class Enemy extends NPC implements IEnemy {
this.setPosition(position.x, position.y);
}

public onDamage(amount: number): void {
if (this.scene.game.isSettingEnabled(GameSettings.SHOW_DAMAGE)) {
if (this.damageLabel) {
this.damageLabel.destroy();
}
if (this.damageLabelTween) {
this.damageLabelTween.destroy();
}

this.damageLabel = this.scene.add.container(this.body.center.x, this.body.center.y);

this.damageLabel.setDepth(WORLD_DEPTH_GRAPHIC);
private addDamageLabel() {
this.damageLabel = this.scene.add.text(0, 0, '', {
fontSize: '6px',
fontFamily: InterfaceFont.PIXEL_TEXT,
align: 'center',
color: '#fff',
resolution: 2,
});

for (let i = 1; i >= 0; i--) {
const label = this.scene.add.text(i, i, amount.toString(), {
fontSize: '6px',
fontFamily: InterfaceFont.PIXEL_TEXT,
align: 'center',
color: i === 0 ? '#fff' : '#000',
resolution: 2,
});
this.damageLabel.setOrigin(0.5, 0.5);
this.damageLabel.setDepth(WORLD_DEPTH_GRAPHIC);
this.damageLabel.setActive(false);
this.damageLabel.setVisible(false);
}

label.setOrigin(0.5, 0.5);
private updateDamageLabel(amount: number) {
if (!this.damageLabel) {
return;
}

this.damageLabel.add(label);
}
this.damageLabel.setText(amount.toString());
this.damageLabel.setPosition(this.body.center.x, this.body.center.y);
this.damageLabel.setActive(true);
this.damageLabel.setVisible(true);
this.damageLabel.setAlpha(1.0);

if (this.damageLabelTween) {
this.damageLabelTween.reset();
} else {
this.damageLabelTween = this.scene.tweens.add({
targets: this.damageLabel,
alpha: 0.0,
alpha: { from: 1.0, to: 0.0 },
duration: 1000,
delay: 500,
delay: 250,
onComplete: () => {
this.damageLabelTween = null;
if (this.damageLabel) {
this.damageLabel.destroy();
this.damageLabel = null;
if (this.active) {
this.damageLabel.setActive(false);
this.damageLabel.setVisible(false);
} else {
this.damageLabel.destroy();
this.damageLabel = null;
}
}
if (this.damageLabelTween) {
this.damageLabelTween.destroy();
this.damageLabelTween = null;
}
},
});
}
}

private removeDamageLabel() {
if (this.damageLabel && !this.damageLabelTween) {
this.damageLabel.destroy();
this.damageLabel = null;
}
}

public onDamage(amount: number): void {
if (this.scene.game.isSettingEnabled(GameSettings.SHOW_DAMAGE)) {
this.updateDamageLabel(amount);
}

super.onDamage(amount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class EnemyExplosive extends Enemy {
const distance = getIsometricDistance(position, target.getPositionOnGround());

if (distance < radius) {
const damageByDistance = this.damage * (1 - (distance / radius)) * 0.6;
const damageByDistance = this.damage * (1 - (distance / radius)) * 0.7;

target.live.damage(damageByDistance);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class EnemyGhost extends Enemy {

const isVisible = this.scene.builder
.getBuildingsByVariant(BuildingVariant.RADAR)
.some((building) => building.actionsAreaContains(this));
.some((building) => building.active && building.actionsAreaContains(this));

this.setAlpha(isVisible ? 1.0 : 0.5);
}
Expand Down
8 changes: 5 additions & 3 deletions src/game/scenes/world/entities/sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,14 @@ export class Sprite extends Phaser.Physics.Arcade.Sprite implements ISprite {

const positionOnGround = this.getPositionOnGround();
const depth = Level.GetDepth(positionOnGround.y, 1);
const positionOfTop = this.getTopCenter();

this.positionAtMatrix = Level.ToMatrixPosition(positionOnGround);
this.currentBiome = this.scene.level.map.getAt(this.positionAtMatrix);

this.setDepth(depth);

this.container.setDepth(depth + 19);
this.container.setPosition(positionOfTop.x, (positionOfTop?.y ?? 0) - 10);
this.container.setPosition(this.body.center.x, this.body.center.y);
this.container.setAlpha(this.alpha);
this.container.setVisible(this.visible);

Expand Down Expand Up @@ -230,7 +229,10 @@ export class Sprite extends Phaser.Physics.Arcade.Sprite implements ISprite {

bar.setOrigin(0.0, 0.0);

const container = this.scene.add.container(-width / 2, this.indicators.length * -6);
const container = this.scene.add.container(
-width / 2,
-this.body.halfHeight - 10 - (this.indicators.length * 6),
);

container.setSize(body.width, body.height);
container.add([body, bar]);
Expand Down

0 comments on commit 1f4f3bd

Please sign in to comment.