Run, jump, stomp the baddies, and design your own level.
Reach the flag ๐ (or the goal score) without running out of lives. Collect coins, jump over gaps, and stomp enemies by landing on top of them.
You write these functions. The game calls them when something happens.
onCoin()
Runs every time you pick up a coin.
function onCoin() {
score = score + 1;
}onStomp()
Runs when you land on top of an enemy.
function onStomp() {
score = score + 5;
}onHit()
Runs when an enemy touches you from the side, or you fall into a pit. You respawn at the start with a moment of safety.
function onHit() {
lives = lives - 1;
}onFlag() optional
Runs when you reach the flag, just before you win.
function onFlag() {
score = score + 100;
}Variables at the top of your code are the game's settings. Change a value, press Play, and see what happens.
Each step shows code you can add to the end of your game's code. A function or variable written later replaces the earlier one, so you never have to delete anything.
Run to the right, jump the walls and gaps, and reach the flag. The level is just a list of text rows near the bottom of the code.
function onCoin() {
score = score + 1;
}jumpPower changes the whole feel of the game.
let jumpPower = 3;The game reads jumpPower every moment, so you can change it while you play. Here every stomp makes your jump a little higher (up to 4).
function onStomp() {
score = score + 3;
jumpPower = Math.min(4, jumpPower + 1);
}Replace the level with your own. Every row must be the same length (at least 8 characters, up to 60) with 4 to 14 rows. Put solid ground (#) under the flag. Keep gaps 3 wide or less and walls 2 tall or less so it's fair.
let level = [
"............",
"............",
"....ooo.....",
"@.......e..F",
"############",
];// ๐ Platformer!
let player = "๐ง";
let enemy = "๐พ";
let goal = 9999; // reach this score to win (or just reach the flag!)
let lives = 3;
let jumpPower = 2; // 1 to 4: how high you jump
// The map. Each row is a piece of text:
// . empty air # a solid block o a coin
// e an enemy F the flag (reach it to win) @ where you start
let level = [
"....................................",
"....................................",
"....................................",
".........ooo..............ooo.......",
"....................................",
"....................................",
"@....o......#......e....#...o...e..F",
"#################..##########..#####",
];
function onCoin() {
score = score + 1;
}
function onStomp() {
score = score + 5;
}
function onHit() {
lives = lives - 1;
}๐ ๏ธ Make your own Platformer game
Game Studio and the full lessons are part of Premium.