From 94ebc258194e16827dd293ed6a3e3cc63697087f Mon Sep 17 00:00:00 2001 From: Chris Weed Date: Wed, 17 Jul 2024 14:18:25 -0500 Subject: [PATCH] Travel has been added --- main.ts | 16 +++++++++++++-- pxt.json | 3 ++- travel.ts | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 travel.ts diff --git a/main.ts b/main.ts index 8207938..6467133 100644 --- a/main.ts +++ b/main.ts @@ -20,6 +20,7 @@ enum States { Overview, Island, AllDead, + Travel, BoatBattle, GameOver, Win @@ -88,6 +89,9 @@ function switchState(state: States) { case States.Win: Win.init() break; + case States.Travel: + Travel.init() + break; case States.Menu: default: Menu.init() @@ -97,7 +101,7 @@ function switchState(state: States) { function startGame(initialState?: States) { Map.onSelectIsland((island: Map.Island) => { currentIsland = island - switchState(States.Island) + switchState(States.Travel) }) Map.onWin(() => { switchState(States.Win) @@ -126,6 +130,14 @@ function startGame(initialState?: States) { } }) + Travel.onBoatBattle(() => { + switchState(States.BoatBattle) + }) + Travel.onLandOnIsland(() => { + currentIsland = currentIsland ? currentIsland : Map.islands[0] + switchState(States.Island) + }) + Menu.onStartGame(() => { switchState(States.Overview) }) @@ -137,4 +149,4 @@ function startGame(initialState?: States) { switchState(initialState ? initialState : States.Menu) } -startGame(States.BoatBattle) \ No newline at end of file +startGame() \ No newline at end of file diff --git a/pxt.json b/pxt.json index 738a233..a0d8643 100644 --- a/pxt.json +++ b/pxt.json @@ -28,7 +28,8 @@ "win.ts", "boatBattle.ts", "enemyPirate.ts", - "enemy.ts" + "enemy.ts", + "travel.ts" ], "testFiles": [ "test.ts" diff --git a/travel.ts b/travel.ts new file mode 100644 index 0000000..3f51bb3 --- /dev/null +++ b/travel.ts @@ -0,0 +1,59 @@ +namespace Travel { + let _onBoatBattle: () => void + let _onLandOnIsland: () => void + let _textSprite: Sprite + let _startAnimation: Image[] + let _pirateAnimation: Image[] + let _islandAnimation: Image[] + + export function init() { + const oddsOfBoatBattle = 70 + const result = Math.min(TreasureStats.getTotal() / 1200, oddsOfBoatBattle / 100) * 100 + + scene.setBackgroundColor(0) + scene.setBackgroundImage(assets.image`empty`) + + // Animate! + _textSprite = textsprite.create('Floaty boaty', 0, 14) + _textSprite.x = 80 + _textSprite.y = 60 + + if (result > oddsOfBoatBattle) { + pause(3000) + _textSprite.destroy() + _textSprite = textsprite.create('Thar be pirates!') + _textSprite.x = 80 + _textSprite.y = 60 + pause(2000) + + destroy() + _onBoatBattle() + } else { + pause(3000) + _textSprite.destroy() + _textSprite = textsprite.create('Arrgh, steal thee loot!') + _textSprite.x = 80 + _textSprite.y = 60 + pause(2000) + + destroy() + _onLandOnIsland() + } + } + + function destroy() { + if (_textSprite) { + _textSprite.destroy() + } + scene.setBackgroundImage(assets.image`empty`) + scene.setBackgroundColor(0) + } + + export function onBoatBattle(callback: () => void) { + _onBoatBattle = callback + } + + export function onLandOnIsland(callback: () => void) { + _onLandOnIsland = callback + } +} \ No newline at end of file