Blast waves of aliens before they land.
Reach the goal score before you run out of lives. Shoot the aliens, dodge their bombs, and don't let any reach the bottom.
You write these functions. The game calls them when something happens.
onHit()
Runs every time you destroy an alien.
function onHit() {
score = score + 10;
}onDamage()
Runs when a bomb hits you or an alien reaches the bottom.
function onDamage() {
lives = lives - 1;
}onWave(n)
Runs when you wipe out a whole wave. n is the number of the wave you just beat.
function onWave(n) {
// a bonus for beating a wave?
}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.
Move under the aliens and fire. Each alien you destroy runs onHit.
function onHit() {
score = score + 10;
}Allow more shots at once, and make the aliens drop fewer bombs.
let maxBullets = 5;
let danger = 0.05;A counter can make a rule apply only some of the time. Here you only lose a life on every second hit, because the first one just dents your armour.
let hits = 0;
function onDamage() {
hits = hits + 1;
if (hits % 2 === 0) {
lives = lives - 1;
}
}onWave gets the wave number n, and you can change any setting there. Here each wave you beat scores 100 and lets you have one more shot in the air at once (up to 6).
function onWave(n) {
score = score + 100;
maxBullets = Math.min(6, maxBullets + 1);
}// ๐ Space Battle!
let ship = "๐";
let alien = "๐พ";
let goal = 100; // reach this score to win
let lives = 3;
let speed = 2; // 1 (slow) to 5 (fast)
let maxBullets = 3; // how many shots can be flying at once
let danger = 0.1; // 0 to 1: how often aliens drop bombs
function onHit() {
score = score + 10;
}
function onDamage() {
lives = lives - 1;
}
// n is the wave you just beat
function onWave(n) {
// a bonus for beating a wave?
}๐ ๏ธ Make your own Space Battle game
Game Studio and the full lessons are part of Premium.