-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Initial support for multiple scenes and switching players
Support for player winning or dying, which reloads the game scene, and loads a "Game Over" scene when his lives run out. We pass game options constantly to the scene, which means we now instantiate the players in the start scene. This also necessitates improvements to Peter: - Tracking the player's control configs - Handling level wins
- Loading branch information
1 parent
e6264e9
commit 7e5292a
Showing
6 changed files
with
204 additions
and
40 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { k, BURGERTIME_BLUE } from '../kaboom'; | ||
import { GameSceneOpt } from './GameScene'; | ||
|
||
const { | ||
add, | ||
anchor, | ||
color, | ||
go, | ||
pos, | ||
text, | ||
vec2, | ||
wait, | ||
} = k; | ||
|
||
export default function(deadPlayer: number, opt: GameSceneOpt) { | ||
opt.players.forEach(p=>p.pos = vec2(-20)); | ||
add([ | ||
text(`Player ${deadPlayer+1} Game Over`, { size: 10 }), | ||
pos(k.width()/2, k.height()/2), | ||
color(BURGERTIME_BLUE), | ||
anchor('center'), | ||
]); | ||
wait(4, ()=>go(opt.players.some(p=>p.lives>=0) ? 'game' : 'start', opt)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
import { k } from '../kaboom'; | ||
import { addMenu } from '../objects/Menu'; | ||
import { addMenuButton } from '../objects/MenuButton'; | ||
import { addPeter } from '../objects/Peter'; | ||
|
||
const { | ||
add, | ||
anchor, | ||
color, | ||
go, | ||
onKeyRelease, | ||
pos, | ||
text, | ||
sprite, | ||
vec2, | ||
} = k; | ||
|
||
export default function() { | ||
add([ | ||
text("Press enter to start", { size: 12 }), | ||
pos(vec2(128, 120)), | ||
anchor("center"), | ||
color(255, 255, 255), | ||
sprite('title'), | ||
anchor('center'), | ||
pos(vec2(128, 64)), | ||
]) | ||
addMenu([ | ||
addMenuButton({ text: '1 Player', pos: vec2(128, 120), action: ()=>{ | ||
const players = [ addPeter() ]; | ||
go('game', { players }); | ||
} }), | ||
addMenuButton({ text: '2 Players', pos: vec2(128, 145), action: ()=>{ | ||
const players = [ addPeter(), addPeter() ]; | ||
go('game', { players }); | ||
} }), | ||
]); | ||
|
||
onKeyRelease("enter", ()=>go("game")); | ||
onKeyRelease("space", ()=>go("game")); | ||
}; |