diff --git a/boatBattle.ts b/boatBattle.ts index 4c82d97..6b53ae4 100644 --- a/boatBattle.ts +++ b/boatBattle.ts @@ -12,19 +12,19 @@ namespace BoatBattle { let _currentTime = _timeAllowed let _lastTick = 0 let _isDone = false - const _boundingBox: number[] = [0, 10, 160, 120] + const _boundingBox: number[] = [0, 10, 160, 100] const _enemyBoatBox: number[] = [0, 10, 160, 60] export function init() { scene.setBackgroundColor(6) - scene.setBackgroundImage(assets.image`empty`) + scene.setBackgroundImage(assets.image`Boat Battle`) _currentTime = _timeAllowed _lastTick = control.millis() // Spawn the players - player1 = new Pirate({ control: controller.player1, playerNumber: 0, onAttack: onPirateAttack, onDie: onPirateDeath, topBoundary: _boundingBox[1], statLocation: player1StatLocation }) - player2 = new Pirate({ control: controller.player2, playerNumber: 1, onAttack: onPirateAttack, onDie: onPirateDeath, topBoundary: _boundingBox[1], statLocation: player2StatLocation }) + player1 = new Pirate({ control: controller.player1, playerNumber: 0, onAttack: onPirateAttack, onDie: onPirateDeath, boundaries: _boundingBox, statLocation: player1StatLocation }) + player2 = new Pirate({ control: controller.player2, playerNumber: 1, onAttack: onPirateAttack, onDie: onPirateDeath, boundaries: _boundingBox, statLocation: player2StatLocation }) // Spawn the enemies! // Based on the amount of treasure you have, more enemies will appear! @@ -43,6 +43,8 @@ namespace BoatBattle { const enemyPirate = new EnemyPirate({ x: locX, y: locY, target: Math.pickRandom([player1, player2]) }) enemies.push(enemyPirate) }) + + PirateLives.show() } export function render() { @@ -59,16 +61,11 @@ namespace BoatBattle { } if (_currentTime <= 0 && !_isDone && enemies.some((enemy) => enemy.health > 0)) { - _isDone = true - console.log('Game over!') - pause(1000) - - destory() - _onAllDeadCallback() + checkIfOver() } } - export function destory() { + export function destroy() { player1.destroy() player2.destroy() enemies.forEach((e) => e.destroy()) @@ -93,19 +90,40 @@ namespace BoatBattle { } }) - checkIfWin() + checkIfOver() } - function onPirateDeath() {} + function onPirateDeath() { + checkIfOver() + } - function checkIfWin() { + function checkIfOver() { const anyAlive = enemies.some((enemy) => enemy.health > 0) + const allPlayersDead = player1.health <= 0 && player2.health <= 0 + if (allPlayersDead || _currentTime <= 0) { + _isDone = true + pause(1500) + + game.showLongText('Thar enemy has taken thee boat! Luckily they\'ve accepted you to join their crew!', DialogLayout.Center) + + TreasureStats.currentTreasure = { + onBoat: TreasureStats.currentTreasure.onBoat + TreasureStats.currentTreasure.inPocket, + onIsland: 0, + inPocket: 0 + } + PirateLives.updatePirateCount(-2) + + destroy() + _onAllDeadCallback() + } + if (!anyAlive) { _isDone = true - console.log("you dit it!") - pause(1000) + pause(1500) + + game.showLongText('Ye have warded off the enemy pirates! For now...', DialogLayout.Center) - destory() + destroy() _onWinCallback() } } diff --git a/enemy.ts b/enemy.ts index 5353670..0590ff9 100644 --- a/enemy.ts +++ b/enemy.ts @@ -1,29 +1,40 @@ class Enemy { - static speed = 10 - public sprite: Sprite public health: number = 1 public riches = 1 + protected _speed: number = 10 protected _currentTarget: Pirate protected _nextAttackTime: number = 0 protected _lastAttackTick: number = 0 protected _facing: 'left' | 'right' = 'left' protected _isAttacking: boolean = false protected _lastDirectionTick: number = 0 + protected _minDistanceFromTarget: number = 30 - constructor({ x, y, target, sprite, riches }: { x: number, y: number, target: Pirate, sprite: Sprite, riches?: number }) { - this.sprite = sprite - this.sprite.x = x - this.sprite.y = y + constructor({ x, y, target, sprite, riches, speed, minDistanceFromTarget }: + { + x: number, + y: number, + target: Pirate, + sprite: Sprite, + riches?: number, + speed?: number, + minDistanceFromTarget?: number + }) { + this.sprite = sprite + this.sprite.x = x + this.sprite.y = y - this.riches = riches != null ? riches : 1 + this.riches = riches != null ? riches : 1 + this._speed = speed != null ? speed : 10 + this._minDistanceFromTarget = minDistanceFromTarget != null ? minDistanceFromTarget : 30 - // On initial spawn they are quick to attack! - this._nextAttackTime = Math.randomRange(Militia.attackDelayMin / 2, Militia.attackDelayMax / 2) - this._lastAttackTick = control.millis() + // On initial spawn they are quick to attack! + this._nextAttackTime = Math.randomRange(Militia.attackDelayMin / 2, Militia.attackDelayMax / 2) + this._lastAttackTick = control.millis() - this._currentTarget = target + this._currentTarget = target } public destroy() { @@ -35,13 +46,13 @@ class Enemy { public setCurrentTarget(pirate: Pirate) { if (pirate.health > 0 && this.health > 0) { this._currentTarget = pirate - this.sprite.follow(this._currentTarget.sprite, Enemy.speed) + this.sprite.follow(this._currentTarget.sprite, this._speed) } } protected walk(direction?: 'left' | 'right') { this._facing = direction ? direction : this._facing - this.sprite.follow(this._currentTarget.sprite, Enemy.speed) + this.sprite.follow(this._currentTarget.sprite, this._speed) } protected hit(damage: number) { @@ -67,13 +78,13 @@ class Enemy { // Check your distance from the target randomly if ((control.millis() - this._lastDirectionTick) > Militia.directionChangeInterval) { this._lastDirectionTick = control.millis() - if (Math.abs(Utils.getDistance( + if (Utils.getDistance( { x: this.sprite.x, y: this.sprite.y }, { x: this._currentTarget.sprite.x, y: this._currentTarget.sprite.y } - )) < 30) { + ) <= this._minDistanceFromTarget) { this.sprite.follow(this._currentTarget.sprite, 0) } else { - this.sprite.follow(this._currentTarget.sprite, Enemy.speed) + this.sprite.follow(this._currentTarget.sprite, this._speed) } } diff --git a/enemyPirate.ts b/enemyPirate.ts index ada9ab3..c4f5182 100644 --- a/enemyPirate.ts +++ b/enemyPirate.ts @@ -8,11 +8,11 @@ class EnemyPirate extends Enemy { // static parrySound: music.SoundEffect = music.createSoundEffect(WaveShape.Noise, 5000, 5000, 255, 0, 100, SoundExpressionEffect.Vibrato, InterpolationCurve.Curve) static directionChangeInterval: number = 1000 - static attackDelayMin: number = 4000 - static attackDelayMax: number = 6000 + static attackDelayMin: number = 3000 + static attackDelayMax: number = 5000 constructor({ x, y, target, riches }: { x: number, y: number, target?: Pirate, riches?: number }) { - super({ x, y, target, sprite: sprites.create(assets.animation`Pirate Walk`[0]), riches }) + 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 this.walk('left') @@ -38,10 +38,11 @@ class EnemyPirate extends Enemy { super.render() // Attack randomly - if ((control.millis() - this._lastAttackTick) > this._nextAttackTime) { - this._lastAttackTick = control.millis() - this._nextAttackTime = Math.randomRange(EnemyPirate.attackDelayMin, EnemyPirate.attackDelayMax) - this.attack() + if ((control.millis() - this._lastAttackTick) > this._nextAttackTime + && Utils.getDistance(this.sprite, this._currentTarget.sprite) < 10) { + this._lastAttackTick = control.millis() + this._nextAttackTime = Math.randomRange(EnemyPirate.attackDelayMin, EnemyPirate.attackDelayMax) + this.attack() } } @@ -68,7 +69,7 @@ class EnemyPirate extends Enemy { protected attack() { super.attack() - // Play the fire animation + // Play the swing animation if (this._facing === 'right') { animation.runImageAnimation( this.sprite, @@ -89,11 +90,10 @@ class EnemyPirate extends Enemy { setTimeout(() => { // Make sure we didn't die in this tiny delay: if (this.health > 0 && this._currentTarget && this.sprite) { - // bigCrash or sonar.... - music.play(music.melodyPlayable(music.bigCrash), music.PlaybackMode.InBackground) + music.play(Pirate.parrySound, music.PlaybackMode.InBackground) // Check to see that our target is in range and fire the hit - if (Math.abs(this.sprite.y - this._currentTarget.sprite.y) < 20) { + if (Utils.getDistance(this.sprite, this._currentTarget.sprite) < 15) { this._currentTarget.hit(this, 1) } } diff --git a/images.g.ts b/images.g.ts index c54edda..aede759 100644 --- a/images.g.ts +++ b/images.g.ts @@ -514,6 +514,129 @@ d d a a a c c d d . . . . . . . . . 5 5 5 4 . . . . . 4 4 . . . . . . . . . . . +`; + case "image18": + case "Boat Battle":return img` +................................................................................................................................................................ +................................................................................................................................................................ +................................................................................................................................................................ +eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.............................. +eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee............................ +eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.......................... +8e888e88888888e888e88888888e88e888888888e8888e88888e88888888888e888888e8888888e88888888888888e88e88888888e8888888888e8888888e88888eeeeee........................ +8e888e88888888e888e88888888e88e888888888e8888e88888e88888888888e88888ee8888888e88888888888888e88e88888888e8888888888e8888888e8888888eeeeeef..................... +8e888e88888888e888e88888888e88e888888888e8888e88888e88888888888e88888e88888888e88888888888888e88e88888888e888888888888888888e8888d888eeeeeeeef.................. +88888e88888888e888e88888888888e888888888e8888e88888e88888888888e88888e88888888e88888888888888888e88888888e888888888888888888e88888ddde88eeeeeeeff............... +8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888e8dddeeeeeeefff............ +ddddddddddddddddddddd88ddddddddddddddddddddddddddd8888888dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd88888888888ed8eeeeee8f........... +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888e8dd8eeeeeeef......... +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888e888dedeeeeeeef....... +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888ddddddddddddddddddddddddddddddd88888888888e8888edd8eeeeeee...... +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888dddd8888888888e8888e8eeeeee.... +8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888dd8888888888888e888eeeeee.. +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888d888888888888e88888eeeeee +8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888ddddddddddddddd888888888dd8888888888888888e8eeee +88888888888888888888888888888888888888d888888dd8dddd8888888888888888888888ddddddddddddddddd888dddddddddddddddddd888888888888888888888888888888888888888888e888ee +ddddddddd88ddddddddd8ddd888888dd888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888ddddd8888888888888ef +88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888ef +88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888ef +88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888ef +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888f +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888dd8d88888888888888888888888f +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888dddd88888888888888888f +8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888ddd88888888888888f +8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888dddd8888888888f +88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888dd88888888f +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888f +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888f +dddddddddd88888888888dddddddddddddddddd8888888888888888888888888888888888888888888888888888888888ddddddddddddddd888dddddddddddd88888888888888888888888888888888f +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888f +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888f +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888f +dddddddddddddddddddddd8d8888ddddddd888888ddddddddddddddddddddddddddddddddddd88888888888888888888888888888888888888888888888888888888888888888888888888888888888f +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888f +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888ddddddddd888888ddd888888f +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888f +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888f +88ddddddddd8dddddddd8dddddddddddddddddd888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888f +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888f +88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888ddddddddddddd88888888888888888888888888888888ff +8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888fff +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888dd888888fffff +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888ddd88888ffffffff +dddddd8dddddddddddddddd8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888ddd88888fffffffffff +88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888dddd888888fffffffffffff +888888888888888888888888888888888888888888888888888888888888888888888888888888888888dd88dddddddddddddddddddddddd8888888888888888888888888888888888ffffffffffffff +8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888ddddddddddddddd888888888888888888fffffffffffffff +8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888ffffffffffffffffff +88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888ffffffffffffffffffff +888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888fffffffffffffffffffff. +dd888888888888888888888888ddd88888dddddddddddddddd888dddddddddddddddddddddd8888888888888888888888888888888888888888888888888888888888888fffffffffffffffffffffff. +88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888fffffffffffffffffffffff... +8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888fffffffffffffffffffffffff..... +8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888fffffffffffffffffffffffffff...... +ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +fffffffffffffffffffffffffffffffff8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +ffffffffffffffffffffffffffffff8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +ffffffffffffffffffffffffff8888888ddddddddd888888888888888888dddddddd8888888ddddddddddddddddddddd8dddddddddddddd888888888888888888888dddd88dddddddddddddddddddddd +ffffffffffffffffffffffff8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +ffffffffffffffffffffff888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +ffffffffffffffffffff88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +ffffffffffffffffff8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +fffffffffffffff8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +ffffffffffffff88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +fffffffffffff888888ddddddddddddddddd8888888888888888888ddddddddddd8888888888888ddd888888888888888888888888888888888888888888888888888888888888888888888888888888 +........fff88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +.....fff88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +...ff88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +..f8888888dddddddddd888888ddddddddddddd888888ddd8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +.f88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888dd8888888888888dddddd88ddddddddddddddd +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888ddddddddddddddddddddddddddddddddddddddddd8888888888888888888888888888ddddddddddddddd888888ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +f888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +ee88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888d888ddddddd8888ddddddddddddd888888ddd88 +feee888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +feeeeee888dddddddddddddddddddddddd888dddddddddd88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +feeeeeeee8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +eeeeeeeeeeee8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +ffeeeeeeeeeeee88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +ffffeeeeeeeeeeeee888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888ddddddddd888ddddddddddd +fffffffeeeeeeeeeeee888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +fffffffffeeeeeeeeeeee888888888888888888888888888dddddd88888888888888888888888888888ddddddddd88888888888888888888888888888888888888888888888888888888888888888888 +fffffffffffeeeeeeeeeeeee8ddddddddddddddddddddddd8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +ffffffffffffeeeeeeeeeeeeee88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +fffffffffffffffeeeeeeeeeeeeee88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +..ffffffffffffffffeeeeeeeeeeeee888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 +....fffffffffffffffffeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee +.....fffffffffffffffffffeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee +.......fffffffffffffffffffeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee +..........fffffffffffffffffffeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee +.............ffffffffffffffffffeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee +...............fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +..................ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +.....................fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +.........................fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +............................ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +..............................ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +..................................ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff `; } return null; diff --git a/island.ts b/island.ts index 3ce8019..0f62dff 100644 --- a/island.ts +++ b/island.ts @@ -288,8 +288,8 @@ namespace Island { TreasureStats.show({ combination: ['pocket'], location: 'center' }) PirateLives.show() - player1 = new Pirate({ control: controller.player1, playerNumber: 0, onAttack: onPirateAttack, onDie: onPirateDeath, topBoundary: _boundingBox[1], statLocation: player1StatLocation }) - player2 = new Pirate({ control: controller.player2, playerNumber: 1, onAttack: onPirateAttack, onDie: onPirateDeath, topBoundary: _boundingBox[1], statLocation: player2StatLocation }) + player1 = new Pirate({ control: controller.player1, playerNumber: 0, onAttack: onPirateAttack, onDie: onPirateDeath, boundaries: _boundingBox, statLocation: player1StatLocation }) + player2 = new Pirate({ control: controller.player2, playerNumber: 1, onAttack: onPirateAttack, onDie: onPirateDeath, boundaries: _boundingBox, statLocation: player2StatLocation }) music.play(music.createSong(assets.song`Invading Them Landlubbers`), music.PlaybackMode.LoopingInBackground) diff --git a/main.ts b/main.ts index 103ec8d..8207938 100644 --- a/main.ts +++ b/main.ts @@ -119,7 +119,11 @@ function startGame(initialState?: States) { switchState(States.Overview) }) BoatBattle.onAllDead(() => { - switchState(States.Overview) + if (PirateLives.currentPirateCount <= 0) { + switchState(States.GameOver) + } else { + switchState(States.Overview) + } }) Menu.onStartGame(() => { diff --git a/militia.ts b/militia.ts index 6c92440..d8b8db3 100644 --- a/militia.ts +++ b/militia.ts @@ -118,6 +118,7 @@ class Militia extends Enemy { // Check to see that our target is in range and fire the hit if (Math.abs(this.sprite.y - this._currentTarget.sprite.y) < 20) { + // scene.cameraShake(2, 500) this._currentTarget.hit(this, 1) } } diff --git a/pirate.ts b/pirate.ts index 9268732..b2a7e13 100644 --- a/pirate.ts +++ b/pirate.ts @@ -33,7 +33,7 @@ class Pirate { private isAttacking?: 'left' | 'right' private isGettingHurt?: boolean = false private isParrying?: 'left' | 'right' - private _topBoundary: number = 0 + private _boundaries: number[] = [0, 0, 160, 120] private _lastAttackTick: number = 0 private _isAttackingTimeout: number private _statLocation: number[] = [0,0] @@ -57,17 +57,17 @@ class Pirate { return this.facing } - constructor({ control, playerNumber, onAttack, onDie, topBoundary, statLocation }: { + constructor({ control, playerNumber, onAttack, onDie, boundaries, statLocation }: { control: controller.Controller, playerNumber: 0 | 1, onAttack: (T: AttackCallbackParams) => void, onDie: (T: { pirate: Pirate }) => void, - topBoundary: number, + boundaries: number[], statLocation: number[] }) { this.health = 3 this.facing = 'right' - this._topBoundary = topBoundary + this._boundaries = boundaries this._statLocation = statLocation this._onDieCallback = onDie @@ -123,9 +123,12 @@ class Pirate { } this.sprite.z = this.sprite.y - // Brute force boundaries for the island - if (this.sprite.y < this._topBoundary) { - this.sprite.y = this._topBoundary + // Brute force boundaries + if (this.sprite.y < this._boundaries[1]) { + this.sprite.y = this._boundaries[1] + } + if (this.sprite.y > this._boundaries[3]) { + this.sprite.y = this._boundaries[3] } } @@ -141,6 +144,7 @@ class Pirate { this.health -= damage this.isGettingHurt = true + scene.cameraShake(2, 500) // Setting to a character animation state that we don't have a rule for @@ -250,6 +254,7 @@ class Pirate { // 8 pixel image, 2 pixel margin s.x = this._statLocation[0] + (index * s.width + 2) s.y = this._statLocation[1] + s.z = 120 return s }) } diff --git a/utils.ts b/utils.ts index 56afb5e..05638e1 100644 --- a/utils.ts +++ b/utils.ts @@ -19,7 +19,7 @@ namespace Utils { const dx = pointB.x - pointA.x; const dy = pointB.y - pointA.y; - return Math.sqrt(dx * dx + dy * dy); + return Math.abs(Math.sqrt(dx * dx + dy * dy)); } export function swapAnimationColors(anim: Image[], fromColor: number, toColor: number) {