From 79781a1ffad2d882418340a0405d6fe68d09afff Mon Sep 17 00:00:00 2001 From: Chris Weed Date: Wed, 17 Jul 2024 15:59:03 -0500 Subject: [PATCH] Updated targetting --- enemy.ts | 9 ++++++--- enemyPirate.ts | 2 +- island.ts | 2 +- main.ts | 2 +- treasureStats.ts | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/enemy.ts b/enemy.ts index 0590ff9..d35a29f 100644 --- a/enemy.ts +++ b/enemy.ts @@ -1,10 +1,13 @@ +// A subset of a pirate, but could be just an item +type EnemyTarget = { sprite: Sprite, health: number, hit: (who: Enemy, amount: number) => void } + class Enemy { public sprite: Sprite public health: number = 1 public riches = 1 protected _speed: number = 10 - protected _currentTarget: Pirate + protected _currentTarget: EnemyTarget protected _nextAttackTime: number = 0 protected _lastAttackTick: number = 0 protected _facing: 'left' | 'right' = 'left' @@ -16,7 +19,7 @@ class Enemy { { x: number, y: number, - target: Pirate, + target: EnemyTarget, sprite: Sprite, riches?: number, speed?: number, @@ -43,7 +46,7 @@ class Enemy { } } - public setCurrentTarget(pirate: Pirate) { + public setCurrentTarget(pirate: EnemyTarget) { if (pirate.health > 0 && this.health > 0) { this._currentTarget = pirate this.sprite.follow(this._currentTarget.sprite, this._speed) diff --git a/enemyPirate.ts b/enemyPirate.ts index c4f5182..abec9cb 100644 --- a/enemyPirate.ts +++ b/enemyPirate.ts @@ -11,7 +11,7 @@ class EnemyPirate extends Enemy { static attackDelayMin: number = 3000 static attackDelayMax: number = 5000 - constructor({ x, y, target, riches }: { x: number, y: number, target?: Pirate, riches?: number }) { + constructor({ x, y, target, riches }: { x: number, y: number, target?: EnemyTarget, riches?: number }) { super({ x, y, target, sprite: sprites.create(assets.animation`Pirate Walk`[0]), riches, speed: 20, minDistanceFromTarget: 10 }) // Most often we spawn to the right, so walk left diff --git a/island.ts b/island.ts index 0f62dff..5395e2b 100644 --- a/island.ts +++ b/island.ts @@ -60,7 +60,7 @@ namespace Island { } } - function retargetEnemies(pirate: Pirate) { + function retargetEnemies(pirate: EnemyTarget) { currentEnemies.forEach((enemy) => { enemy.setCurrentTarget(pirate) }) diff --git a/main.ts b/main.ts index 836a8ac..a4196ad 100644 --- a/main.ts +++ b/main.ts @@ -39,7 +39,7 @@ const version: string = 'v0.7' const debugMode: boolean = false let currentState: States -let currentIsland: Map.Island = Map.islands[2] +let currentIsland: Map.Island = Map.islands[0] let treasureSprite: Sprite console.log('Yarrrgh! Beware of ye monsters in thee code!') diff --git a/treasureStats.ts b/treasureStats.ts index db8ef9a..a6d7db9 100644 --- a/treasureStats.ts +++ b/treasureStats.ts @@ -18,7 +18,7 @@ namespace TreasureStats { let currentPosition: 'left' | 'center' = 'left' export let currentTreasure: TreasureStat = { - onBoat: 151, + onBoat: 0, onIsland: 0, inPocket: 0 }