generated from remarkablegames/kaboom-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
494c4c7
commit 3d31bf5
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
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,66 @@ | ||
import { addCursorKeys, clearAllTimers, initLevel } from '../helpers' | ||
import { Cleanup, Sprite } from '../types' | ||
|
||
export const level = 14 | ||
export const title = 'Timer 3' | ||
|
||
const cleanups: Cleanup[] = [clearAllTimers] | ||
|
||
let keys: number | ||
|
||
function getMessage() { | ||
return `Collect ${keys} more key${keys !== 1 ? 's' : ''}` | ||
} | ||
|
||
function addKey() { | ||
add([ | ||
sprite(Sprite.key), | ||
pos(randi(width()), randi(height())), | ||
area(), | ||
anchor('center'), | ||
Sprite.key, | ||
]) | ||
} | ||
|
||
export function prescript() { | ||
keys = 420 | ||
initLevel(level, cleanups) | ||
loadSprite(Sprite.key, 'sprites/key.png') | ||
|
||
addCursorKeys( | ||
add([sprite(Sprite.player), pos(center()), area(), Sprite.player]), | ||
) | ||
|
||
const message = add([text(getMessage())]) | ||
|
||
addKey() | ||
|
||
cleanups.push( | ||
onCollide(Sprite.key, Sprite.player, (key) => { | ||
keys-- | ||
key.destroy() | ||
message.text = getMessage() | ||
|
||
if (keys) { | ||
addKey() | ||
} else { | ||
add([sprite(Sprite.exit), pos(center()), area(), Sprite.exit]) | ||
} | ||
}).cancel, | ||
) | ||
|
||
cleanups.push( | ||
onAdd(Sprite.exit, () => { | ||
if (keys) { | ||
destroyAll(Sprite.exit) | ||
} | ||
}).cancel, | ||
) | ||
} | ||
|
||
export const script = ` | ||
const player = get('player')[0] | ||
const key = get('key')[0] | ||
` | ||
|
||
export function postscript() {} |