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
b991364
commit ae20f3f
Showing
6 changed files
with
164 additions
and
81 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 |
---|---|---|
@@ -1,42 +1,73 @@ | ||
import { | ||
addExit, | ||
addPlayer, | ||
addText, | ||
loadExit, | ||
loadKey, | ||
registerPasswordCheck, | ||
registerPlayerMovement, | ||
loadBlock, | ||
registerDisableMovement, | ||
registerWinCondition, | ||
} from '../templates' | ||
|
||
export const level = 18 | ||
export const title = 'JSON.stringify' | ||
export const hint = '{ level: _, year: _ }' | ||
|
||
const password = JSON.stringify({ level, year: new Date().getFullYear() }) | ||
export const title = 'Methods' | ||
export const hint = 'Call the methods in a for loop' | ||
|
||
export const prescript = ` | ||
${loadExit()} | ||
${loadKey()} | ||
${addPlayer({ pos: '100, 100' })} | ||
add([sprite('key'), pos(center()), area(), 'key', { password: '${password}' }]) | ||
${loadBlock()} | ||
${addPlayer({ pos: '95, 100' })} | ||
${addExit()} | ||
${registerPlayerMovement()} | ||
${registerDisableMovement()} | ||
${registerWinCondition(level)} | ||
${registerPasswordCheck(password)} | ||
${addText('Stringify the password')} | ||
${addText('Exit the maze')} | ||
const player = get('player')[0] | ||
player.moveTo = () => {} | ||
const map = [ | ||
'#########', | ||
'# #', | ||
'####### #', | ||
'# #', | ||
'# #######', | ||
'# #', | ||
'####### #', | ||
'# #', | ||
'#########', | ||
] | ||
addLevel(map, { | ||
tileWidth: 64, | ||
tileHeight: 64, | ||
tiles: { | ||
'#': () => [ | ||
sprite('block'), | ||
area(), | ||
body({ isStatic: true }), | ||
], | ||
} | ||
}) | ||
` | ||
|
||
export const script = ` | ||
/** | ||
* JSON.stringify() converts data into a string | ||
* A method is a function defined within an object | ||
*/ | ||
const key = get('key')[0] | ||
const player = get('player')[0] | ||
const SPEED = 300 | ||
player.moveUp = function() { this.move(0, -SPEED) } | ||
player.moveLeft = function() { this.move(-SPEED, 0) } | ||
player.moveDown = function() { this.move(0, SPEED) } | ||
player.moveRight = function() { this.move(SPEED, 0) } | ||
// password = JSON string of object containing "level" and "year" | ||
let password | ||
player.moveRight() | ||
` | ||
|
||
key.password = password | ||
export const postscript = ` | ||
const exit = get('exit')[0] | ||
if (exit) { | ||
exit.moveTo(95, 480) | ||
} | ||
` |
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
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,52 @@ | ||
import { | ||
addPlayer, | ||
addText, | ||
loadExit, | ||
loadKey, | ||
registerPasswordCheck, | ||
registerPlayerMovement, | ||
registerWinCondition, | ||
} from '../templates' | ||
|
||
export const level = 22 | ||
export const title = 'Rejected Promise' | ||
export const hint = 'key.promise.catch(...)' | ||
|
||
const password = btoa(String(Date.now())) | ||
|
||
export const prescript = ` | ||
${loadExit()} | ||
${loadKey()} | ||
${addPlayer({ pos: '100, 100' })} | ||
add([sprite('key'), pos(center()), area(), 'key', { promise: Promise.reject('${password}') }]) | ||
${registerPlayerMovement()} | ||
${registerWinCondition(level)} | ||
${registerPasswordCheck(password)} | ||
${addText('Catch the Promise')} | ||
` | ||
|
||
export const script = ` | ||
/** | ||
* A Promise produces a value in the future | ||
* If a Promise failed, it will produce a rejected value | ||
*/ | ||
const key = get('key')[0] | ||
// example of failed Promise | ||
const examplePromise = Promise.reject('some value') | ||
examplePromise.catch((value) => { | ||
console.log(value) | ||
key.password = value | ||
}) | ||
// set \`key.password\` to the rejected value of \`key.promise\` | ||
console.log('is promise?', isPromise(key.promise)) | ||
function isPromise(value) { | ||
return value instanceof Promise | ||
} | ||
` |