Move the basket and catch the falling stars.
Reach the goal score before you run out of lives. Stars you catch earn points; stars that hit the floor cost lives.
You write these functions. The game calls them when something happens.
onCatch()
Runs every time a star lands in your basket.
function onCatch() {
score = score + 1;
}onMiss()
Runs every time a star hits the floor.
function onMiss() {
lives = lives - 1;
}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.
Press Play and catch a few stars. Every catch runs onCatch, and score = score + 1 adds one point. Every miss runs onMiss and takes a life.
function onCatch() {
score = score + 1;
}Change the number you add. Now every star is worth 5 points.
function onCatch() {
score = score + 5;
}Use if to change the game when something happens. Here, once your score reaches 8 the game jumps to speed 4. The sign >= means "bigger than or equal to".
function onCatch() {
score = score + 1;
if (score >= 8) {
speed = 4;
}
}A counter variable remembers how many you have caught. The % sign gives the remainder after dividing, so catches % 3 === 0 is true on every 3rd catch. Those get a +5 bonus.
let catches = 0;
function onCatch() {
catches = catches + 1;
score = score + 1;
if (catches % 3 === 0) {
score = score + 5;
}
}A miss can change any variable, not just lives. Here a miss costs a life and slows the game down, but Math.max keeps the speed from going below 1.
function onMiss() {
lives = lives - 1;
speed = Math.max(1, speed - 1);
}// ๐ฎ Catch the Stars!
let player = "๐งบ"; // the thing you move
let item = "โญ"; // what falls from the sky
let goal = 10; // reach this score to win
let lives = 3;
let speed = 2; // 1 (slow) to 5 (fast)
function onCatch() {
score = score + 1;
}
function onMiss() {
lives = lives - 1;
}๐ ๏ธ Make your own Catch the Stars game
Game Studio and the full lessons are part of Premium. You can try a free lesson first.