From da603572b2e87d1cf39ea36729e7c0613591952a Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 27 May 2024 02:16:37 -0400 Subject: [PATCH] feat(levels): add level 9 --- src/levels/9.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/levels/9.ts diff --git a/src/levels/9.ts b/src/levels/9.ts new file mode 100644 index 0000000..cfdb1f9 --- /dev/null +++ b/src/levels/9.ts @@ -0,0 +1,46 @@ +import { addCursorKeys, initLevel } from '../helpers' +import { Sprite } from '../types' + +export const level = 9 +export const title = 'Loops' + +const password = Array.from(Array(42).keys()) + .map(() => 'answer') + .join('') + +export function prescript() { + initLevel(level) + loadSprite(Sprite.key, 'sprites/key.png') + + addCursorKeys( + add([sprite(Sprite.player), pos(100, 100), area(), Sprite.player]), + ) + + add([sprite(Sprite.key), pos(center()), area(), Sprite.key, { password }]) + + onCollide(Sprite.key, Sprite.player, (key) => { + if (key.password === password) { + key.destroy() + add([sprite(Sprite.exit), pos(500, 500), area(), Sprite.exit]) + } else { + debug.log('Incorrect password') + } + }) + + add([text('Another password?')]) +} + +export const script = ` +/** + * Loops repeat a block of code + */ + +const key = get('key')[0] + +// password = 'answer' repeated 42 times +let password = 'answer' + 'answer' + +key.password = password +` + +export function postscript() {}