Skip to content

Commit

Permalink
feat(levels): add level 8
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed May 27, 2024
1 parent 6bfae1e commit aff1fec
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/levels/8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { addCursorKeys, initLevel } from '../helpers'
import { Sprite } from '../types'

export const level = 8
export const title = 'Variables'

function generatePassword() {
const year = new Date().getFullYear()
return (year + level) * 31337
}

export function prescript() {
initLevel(level)
loadSprite(Sprite.key, 'sprites/key.png')

addCursorKeys(
add([sprite(Sprite.player), pos(100, 100), area(), Sprite.player]),
)

const password = generatePassword()
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("What's the password?")])
}

export const script = `
/**
* Variables store data
* 'const' cannot be reassigned, whereas 'let' can be reassigned
*/
const key = get('key')[0]
// password = (current_year + current_level_number) * 31337
let password
key.password = password
`

export function postscript() {}
1 change: 1 addition & 0 deletions src/types/sprite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum Sprite {
exit = 'exit',
key = 'key',
player = 'player',
wall = 'wall',
}

0 comments on commit aff1fec

Please sign in to comment.