diff --git a/main.ts b/main.ts index 6467133..836a8ac 100644 --- a/main.ts +++ b/main.ts @@ -20,6 +20,7 @@ enum States { Overview, Island, AllDead, + TreasureIsland, Travel, BoatBattle, GameOver, @@ -38,7 +39,7 @@ const version: string = 'v0.7' const debugMode: boolean = false let currentState: States -let currentIsland: Map.Island +let currentIsland: Map.Island = Map.islands[2] let treasureSprite: Sprite console.log('Yarrrgh! Beware of ye monsters in thee code!') @@ -72,7 +73,7 @@ function switchState(state: States) { currentState = state switch (currentState) { case States.Overview: - Map.init(Map.islands) + Map.init({ islands: Map.islands, currentIsland }) break; case States.Island: Island.init({ island: currentIsland }) @@ -90,7 +91,10 @@ function switchState(state: States) { Win.init() break; case States.Travel: - Travel.init() + Travel.init({ targetIsland: currentIsland }) + break; + case States.TreasureIsland: + TreasureIsland.init() break; case States.Menu: default: @@ -100,15 +104,26 @@ function switchState(state: States) { function startGame(initialState?: States) { Map.onSelectIsland((island: Map.Island) => { - currentIsland = island - switchState(States.Travel) + console.log('Current ' + currentIsland.id + ":" + island.id) + if (currentIsland && island.id !== currentIsland.id) { + currentIsland = island + switchState(States.Travel) + console.log('And now ' + currentIsland.id + ':' + island.id) + } else if (island.id === 0) { + currentIsland = island + // Re-entering your own island does nothing. + switchState(States.Overview) + } else { + currentIsland = island + // If you re-select the same island you don't floatyboaty + switchState(States.Island) + } }) Map.onWin(() => { switchState(States.Win) }) Island.onLeaveIsland(() => { - currentIsland = undefined switchState(States.Overview) }) Island.onAllDead(() => { @@ -120,11 +135,17 @@ function startGame(initialState?: States) { }) BoatBattle.onWin(() => { - switchState(States.Overview) + if (currentIsland.id === 0) { + switchState(States.TreasureIsland) + } else { + switchState(States.Island) + } }) BoatBattle.onAllDead(() => { if (PirateLives.currentPirateCount <= 0) { switchState(States.GameOver) + } else if (currentIsland.id === 0) { + switchState(States.TreasureIsland) } else { switchState(States.Overview) } @@ -135,7 +156,16 @@ function startGame(initialState?: States) { }) Travel.onLandOnIsland(() => { currentIsland = currentIsland ? currentIsland : Map.islands[0] - switchState(States.Island) + if (currentIsland.id === 0) { + // Our own Island + switchState(States.TreasureIsland) + } else { + switchState(States.Island) + } + }) + + TreasureIsland.onComplete(() => { + switchState(States.Overview) }) Menu.onStartGame(() => { diff --git a/map.ts b/map.ts index cca5b13..6730f6e 100644 --- a/map.ts +++ b/map.ts @@ -53,17 +53,6 @@ namespace Map { // We can't select the island too quickly after seeing this scene if (control.millis() - _leftIslandTick < _selectIslandDelay) return - // Do special if we select our own island - if (_islands[currentSelectedIslandIndex].id === 0) { - TreasureStats.currentTreasure = { - onBoat: 0, - onIsland: TreasureStats.getTotal(), - inPocket: 0 - } - TreasureStats.show({}) - return - } - destroy() _onSelectIsland(_islands[currentSelectedIslandIndex]) @@ -87,7 +76,7 @@ namespace Map { renderIslandStats(islands[currentSelectedIslandIndex]) } - export function init(islands: Array) { + export function init({ islands, currentIsland }: { islands: Array, currentIsland: Island }) { // Give us a second before allowing us to select an island _leftIslandTick = control.millis() _islands = islands @@ -121,7 +110,7 @@ namespace Map { controller.player1.A.addEventListener(ControllerButtonEvent.Pressed, selectIsland) // Initial render of the cursor - renderCursor(islands[currentSelectedIslandIndex], cursor) + renderCursor(currentIsland ? currentIsland : islands[currentSelectedIslandIndex], cursor) // And selected island renderIslandStats(islands[currentSelectedIslandIndex]) // And the owner flags diff --git a/pxt.json b/pxt.json index a0d8643..2894dd3 100644 --- a/pxt.json +++ b/pxt.json @@ -29,7 +29,8 @@ "boatBattle.ts", "enemyPirate.ts", "enemy.ts", - "travel.ts" + "travel.ts", + "treasureIsland.ts" ], "testFiles": [ "test.ts" diff --git a/travel.ts b/travel.ts index 332f9b8..2a88772 100644 --- a/travel.ts +++ b/travel.ts @@ -6,10 +6,17 @@ namespace Travel { let _pirateAnimation: Image[] let _islandAnimation: Image[] - export function init() { + export function init({ targetIsland }: { targetIsland: Map.Island }) { // Probably should have done this better... oh well const oddsOfBoatBattle = 80 - const result = Math.min(TreasureStats.currentTreasure.onBoat / 300, oddsOfBoatBattle / 100) * 100 + let result = Math.min(TreasureStats.currentTreasure.onBoat / 300, oddsOfBoatBattle / 100) * 100 + + console.log('Target island ' + targetIsland.id + ': ' + TreasureStats.currentTreasure.onBoat) + + // You will ALWAYS get a pirate battle if you travel to your island with any amount of cash + if (TreasureStats.currentTreasure.onBoat > 150 && targetIsland.id === 0) { + result = 100 + } scene.setBackgroundColor(0) scene.setBackgroundImage(assets.image`empty`) @@ -32,7 +39,8 @@ namespace Travel { } else { pause(3000) _textSprite.destroy() - _textSprite = textsprite.create('Arrgh, steal thee loot!') + const text = targetIsland.id === 0 ? 'Ye hid yer booty!' : 'Arrgh, steal thee loot!' + _textSprite = textsprite.create(text) _textSprite.x = 80 _textSprite.y = 60 pause(2000) diff --git a/treasureIsland.ts b/treasureIsland.ts new file mode 100644 index 0000000..4cd288e --- /dev/null +++ b/treasureIsland.ts @@ -0,0 +1,22 @@ +namespace TreasureIsland { + let _onComplete: () => void + + export function init() { + // Do special if we select our own island + TreasureStats.currentTreasure = { + onBoat: 0, + onIsland: TreasureStats.getTotal(), + inPocket: 0 + } + TreasureStats.show({}) + + destroy() + _onComplete() + } + + export function onComplete(callback: () => void) { + _onComplete = callback + } + + function destroy() {} +} diff --git a/treasureStats.ts b/treasureStats.ts index 25cd534..f9ad3ff 100644 --- a/treasureStats.ts +++ b/treasureStats.ts @@ -18,7 +18,7 @@ namespace TreasureStats { let currentPosition: 'left' | 'center' = 'left' export let currentTreasure: TreasureStat = { - onBoat: 0, + onBoat: 151, onIsland: 0, inPocket: 0 }