Skip to content

Commit

Permalink
feat(levels): add level 9
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed May 27, 2024
1 parent aff1fec commit da60357
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/levels/9.ts
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit da60357

Please sign in to comment.