Skip to content

Commit

Permalink
Travel has been added
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikketer committed Jul 17, 2024
1 parent 52b1e48 commit 94ebc25
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
16 changes: 14 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum States {
Overview,
Island,
AllDead,
Travel,
BoatBattle,
GameOver,
Win
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
})
Expand All @@ -137,4 +149,4 @@ function startGame(initialState?: States) {
switchState(initialState ? initialState : States.Menu)
}

startGame(States.BoatBattle)
startGame()
3 changes: 2 additions & 1 deletion pxt.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"win.ts",
"boatBattle.ts",
"enemyPirate.ts",
"enemy.ts"
"enemy.ts",
"travel.ts"
],
"testFiles": [
"test.ts"
Expand Down
59 changes: 59 additions & 0 deletions travel.ts
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 94ebc25

Please sign in to comment.