Skip to content

Commit

Permalink
Updated targetting
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikketer committed Jul 17, 2024
1 parent 78cd664 commit 79781a1
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions enemy.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -16,7 +19,7 @@ class Enemy {
{
x: number,
y: number,
target: Pirate,
target: EnemyTarget,
sprite: Sprite,
riches?: number,
speed?: number,
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion enemyPirate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion island.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace Island {
}
}

function retargetEnemies(pirate: Pirate) {
function retargetEnemies(pirate: EnemyTarget) {
currentEnemies.forEach((enemy) => {
enemy.setCurrentTarget(pirate)
})
Expand Down
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!')
Expand Down
2 changes: 1 addition & 1 deletion treasureStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace TreasureStats {
let currentPosition: 'left' | 'center' = 'left'

export let currentTreasure: TreasureStat = {
onBoat: 151,
onBoat: 0,
onIsland: 0,
inPocket: 0
}
Expand Down

0 comments on commit 79781a1

Please sign in to comment.