Game Functions Lab
No magic. See the function, see how it is used, change it, run it.
☰ TABLE OF CONTENTS — jump to a function
move(item, xChange, yChange)
Move any object in any direction. Positive/negative numbers choose the direction.
25 to 5, 50 or -25.place(item, x, y)
Put an object at an exact position.
hide(item) / show(item)
Hide or show keys, treasure, doors and story objects.
setText(textBox, text)
Change any message box.
Explore the cave...
changeNumber(number, amount, display)
One function for score, health, gold, lives or energy.
1, 5 or -1.Score: 0
keepInside(item, gameArea)
Stop a player leaving the game.
touching(item1, item2)
The core collision helper: are two rectangles overlapping?
randomPosition(item, gameArea)
Put treasure somewhere random inside the game.
randomX(item, gameArea)
Choose a random lane for falling rocks, cars or stars.
moveWithKeys(item, speed, up, down, left, right)
One keyboard helper. You choose the keys.
15 to 30, or use w s a d.atEdge(item, gameArea, side)
Ask whether an object reached an edge.
left, top, bottom.moveToward(enemy, target, speed)
Make a simple enemy chase a target.
startCountdown(seconds, display, whenFinished)
Reusable countdown for timed games.
setInterval() before expecting them to write this helper.Time: 5
Ready
randomItem(items)
Pick random loot, questions or story events.
Open the chest...
countItem(items, itemName)
Count repeated items, such as 3 crystals.
Crystals: ?
removeItems(items, itemName, amount)
Trade or spend several copies of an item.
hasAllItems(inventory, neededItems)
Check a recipe that needs several different items.
Checking...
findTouching(item, items)
Check one object against a whole list.
moveIfClear(item, dx, dy, walls, gameArea)
Try a move; if any wall is hit, undo it.
trackKeys() / keyDown(keys, key)
Know which keys are being HELD, needed for Pong/platformers.
applyGravity(item, ySpeed, gravity)
Gravity makes vertical speed increase every game loop.
standingOnAny() / landOnPlatforms()
Check whether the player can jump, and stop falling on platforms.
createSprite(gameArea, picture, x, y, size)
Create bullets, coins or enemies while the game is running.