adds win and loose messages to stroke fighter
This commit is contained in:
parent
4cd8d9c699
commit
d8225999b0
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
import kaboom from 'kaboom'
|
||||
import StrokeFighterBattleScene from './StrokeFighterBattleScene.js'
|
||||
import StrokeFighterEndScene from './StrokeFighterEndScene.js'
|
||||
import StrokeFighterStartScene from './StrokeFighterStartScene.js'
|
||||
import StrokeFighterGameOverScene from './StrokeFighterGameOverScene.js'
|
||||
|
||||
/**
|
||||
* creates and initializes the rowing games
|
||||
|
|
@ -46,7 +46,7 @@ export function createRowingGames (rootComponent, canvasElement, clientWidth, cl
|
|||
let activeScene
|
||||
k.scene('strokeFighterBattle', (args) => { activeScene = StrokeFighterBattleScene(k, args) })
|
||||
k.scene('strokeFighterStart', (args) => { activeScene = StrokeFighterStartScene(k, args) })
|
||||
k.scene('strokeFighterGameOver', (args) => { activeScene = StrokeFighterGameOverScene(k, args) })
|
||||
k.scene('strokeFighterEnd', (args) => { activeScene = StrokeFighterEndScene(k, args) })
|
||||
|
||||
k.go('strokeFighterStart')
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ export default function StrokeFighterBattleScene (k, args) {
|
|||
]
|
||||
|
||||
let trainingTime = args?.trainingTime || 0
|
||||
let playerLifes = args?.gameOver ? 0 : PLAYER_LIFES
|
||||
let playerLifes = args?.gameState === 'LOST' ? 0 : args?.playerLifes ? args?.playerLifes : PLAYER_LIFES
|
||||
|
||||
const ui = k.add([
|
||||
k.fixed(),
|
||||
|
|
@ -65,7 +65,7 @@ export default function StrokeFighterBattleScene (k, args) {
|
|||
k.origin('center')
|
||||
])
|
||||
|
||||
if (args?.gameOver) {
|
||||
if (args?.gameState === 'LOST') {
|
||||
const shield = k.add([
|
||||
k.sprite('shield1'),
|
||||
k.scale(0.5),
|
||||
|
|
@ -116,9 +116,21 @@ export default function StrokeFighterBattleScene (k, args) {
|
|||
playerLifes -= 1
|
||||
drawPlayerLifes()
|
||||
if (playerLifes <= 0) {
|
||||
k.go('strokeFighterGameOver', {
|
||||
trainingTime
|
||||
})
|
||||
// if we already won the game before, go back to win message without possibility for overtime
|
||||
if (args?.gameState === 'WON') {
|
||||
k.go('strokeFighterEnd', {
|
||||
trainingTime,
|
||||
gameState: 'WON',
|
||||
overtimePossible: false
|
||||
})
|
||||
// if we did not win or lose the game the game before, go to loose message with possibility for overtime
|
||||
} else {
|
||||
k.go('strokeFighterEnd', {
|
||||
trainingTime,
|
||||
gameState: 'LOST',
|
||||
overtimePossible: true
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -231,6 +243,26 @@ export default function StrokeFighterBattleScene (k, args) {
|
|||
if (trainingTimeRounded !== newTrainingTimeRounded) {
|
||||
timer.text = `${secondsToTimeString(newTrainingTimeRounded)} / ${k.debug.fps()}fps`
|
||||
trainingTimeRounded = newTrainingTimeRounded
|
||||
if (trainingTimeRounded >= TARGET_TIME) {
|
||||
// if we already lost the game before, go back to loose message without possibility for overtime
|
||||
if (args?.gameState === 'LOST') {
|
||||
k.go('strokeFighterEnd', {
|
||||
trainingTime,
|
||||
playerLifes,
|
||||
gameState: 'LOST',
|
||||
overtimePossible: false
|
||||
})
|
||||
}
|
||||
// if we did not win or loose the game before, go to win message with possibility for overtime
|
||||
if (!(args?.gameState)) {
|
||||
k.go('strokeFighterEnd', {
|
||||
trainingTime,
|
||||
playerLifes,
|
||||
gameState: 'WON',
|
||||
overtimePossible: true
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
/*
|
||||
Open Rowing Monitor, https://github.com/laberning/openrowingmonitor
|
||||
|
||||
Implements the Start Screen of the Stroke Fighter Game
|
||||
Implements the Game Over Screen of the Stroke Fighter Game
|
||||
*/
|
||||
|
||||
import addSpaceBackground from './SpaceBackground.js'
|
||||
|
|
@ -10,8 +10,9 @@ import addSpaceBackground from './SpaceBackground.js'
|
|||
/**
|
||||
* Creates the main scene of Storke Fighter
|
||||
* @param {import('kaboom').KaboomCtx} k Kaboom Context
|
||||
* @param {Object} args the game state
|
||||
*/
|
||||
export default function StrokeFighterGameOverScene (k, args) {
|
||||
export default function StrokeFighterEndScene (k, args) {
|
||||
addSpaceBackground(k)
|
||||
|
||||
k.add([
|
||||
|
|
@ -19,11 +20,19 @@ export default function StrokeFighterGameOverScene (k, args) {
|
|||
k.pos(k.width() / 2, 50),
|
||||
k.origin('center')
|
||||
])
|
||||
k.add([
|
||||
k.text('Game Over', { size: 40 }),
|
||||
k.pos(k.width() / 2, 180),
|
||||
k.origin('center')
|
||||
])
|
||||
if (args?.gameState === 'LOST') {
|
||||
k.add([
|
||||
k.text('Game Over', { size: 40 }),
|
||||
k.pos(k.width() / 2, 180),
|
||||
k.origin('center')
|
||||
])
|
||||
} else {
|
||||
k.add([
|
||||
k.text('You win!', { size: 40 }),
|
||||
k.pos(k.width() / 2, 180),
|
||||
k.origin('center')
|
||||
])
|
||||
}
|
||||
k.add([
|
||||
k.sprite('playerShip2_orange'),
|
||||
k.scale(0.5),
|
||||
|
|
@ -36,20 +45,34 @@ export default function StrokeFighterGameOverScene (k, args) {
|
|||
k.pos(k.width() / 2, 440),
|
||||
k.origin('center')
|
||||
])
|
||||
k.add([
|
||||
k.text('... or keep rowing to finish your workout', { size: 18 }),
|
||||
k.pos(k.width() / 2, 550),
|
||||
k.origin('center')
|
||||
])
|
||||
|
||||
if (args?.overtimePossible) {
|
||||
if (args?.gameState === 'LOST') {
|
||||
k.add([
|
||||
k.text('or keep rowing to continue your workout', { size: 18 }),
|
||||
k.pos(k.width() / 2, 550),
|
||||
k.origin('center')
|
||||
])
|
||||
} else {
|
||||
k.add([
|
||||
k.text('or keep rowing for an insane challenge', { size: 18 }),
|
||||
k.pos(k.width() / 2, 550),
|
||||
k.origin('center')
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
restartButton.onClick(() => {
|
||||
console.log('click')
|
||||
k.go('strokeFighterStart')
|
||||
})
|
||||
|
||||
let motionDetectionEnabled = false
|
||||
k.wait(5, () => {
|
||||
motionDetectionEnabled = true
|
||||
})
|
||||
if (args?.overtimePossible) {
|
||||
k.wait(5, () => {
|
||||
motionDetectionEnabled = true
|
||||
})
|
||||
}
|
||||
|
||||
let lastStrokeState = 'DRIVING'
|
||||
function appState (appState) {
|
||||
|
|
@ -66,10 +89,7 @@ export default function StrokeFighterGameOverScene (k, args) {
|
|||
}
|
||||
|
||||
function driveFinished (metrics) {
|
||||
k.go('strokeFighterBattle', {
|
||||
gameOver: true,
|
||||
trainingTime: args?.trainingTime
|
||||
})
|
||||
k.go('strokeFighterBattle', args)
|
||||
}
|
||||
|
||||
return {
|
||||
Loading…
Reference in New Issue