🎯 Free · Ages 10+ · JavaScript · No download

How to make a Slime Blaster game in JavaScript

A shooting game: guard the fence! Move the robot, blast the slimes marching in — big ones need 3 hits. Play it first, then open it in the Game Studio and change it until it is your own game.

🎮 Controls: ↑ ↓ ← → to move · SPACE to fire

The numbers that make the game

At the top of the code are the settings — change one, run the game, and feel the difference. This is how game designers balance a game.

let robotSpeed = 260
let blastSpeed = 700
let slimeSpeed = 70
let slimeEvery = 1.4A new slime every … seconds
let slimePoints = 10
let bigSlimeHits = 3A big slime needs this many hits
let startLives = 3
let target = 150Points to win
let fenceColor = [139, 94, 52]

8 ways to change the slime blaster game

Try them in order. The studio ticks each one off when your change works — and shows a hint if it does not.

  1. Make the robot faster.रोबोट को तेज़ करें।
    let robotSpeed = 400
  2. Make the blasts faster.ब्लास्ट को तेज़ करें।
    let blastSpeed = 1000
  3. Easier: slower slimes.आसान: धीमे स्लाइम।
    let slimeSpeed = 45
  4. Harder: slimes come more often.मुश्किल: स्लाइम जल्दी-जल्दी आएँ।
    let slimeEvery = 0.8
  5. Each slime is worth more points.हर स्लाइम के अंक बढ़ाएँ।
    let slimePoints = 25
  6. Tougher big slimes: more hits.बड़े स्लाइम को ज़्यादा वार चाहिए।
    let bigSlimeHits = 6
  7. More lives.ज़्यादा lives.
    let startLives = 5
  8. Paint the fence a new colour.बाड़ का रंग बदलें।
    let fenceColor = [37, 99, 235]

The Slime Blaster code (JavaScript)

69 lines of real JavaScript, made with TalentJR Game Studio's game library. Lines that start with // explain what the next part does.

Show the whole game code
// 🎯 Slime Blaster — TalentJR Game Studio
// ✏️ Change these numbers, then press ▶ Run!
let robotSpeed = 260
let blastSpeed = 700
let slimeSpeed = 70
let slimeEvery = 1.4      // a new slime every … seconds
let slimePoints = 10
let bigSlimeHits = 3      // a big slime needs this many hits
let startLives = 3
let target = 150          // points to win
let fenceColor = [139, 94, 52]

tj.setup({ background: "grass" })
tj.touchControls("arrows-fire")

// The fence you defend: no slime may get past it
add([rect(8, height()), pos(130, 0), color(...fenceColor)])

const robot = tj.player({ sprite: "robot", x: 40, y: 220, speed: robotSpeed, mode: "topdown" })
const score = tj.score()
const lives = tj.lives(startLives)

// The robot stays behind the fence
robot.onUpdate(() => {
    robot.pos.x = Math.max(0, Math.min(robot.pos.x, 80))
    robot.pos.y = Math.max(50, Math.min(robot.pos.y, height() - 48))
})

// Fire with SPACE (or the A button): a blast flies to the right
tj.onAction("fire", () => {
    add([rect(20, 6), color(250, 204, 21), pos(robot.pos.x + 44, robot.pos.y + 22), area(), move(RIGHT, blastSpeed), offscreen({ destroy: true }), "blast"])
    tj.sound("pop")
})

// Slimes march in from the right. Every 5th one is BIG
let slimeCount = 0
loop(slimeEvery, () => {
    slimeCount = slimeCount + 1
    const big = slimeCount % 5 === 0
    add([sprite("slime"), pos(width(), rand(60, height() - 60)), scale(big ? 1.1 : 0.7), area(), move(LEFT, big ? slimeSpeed * 0.7 : slimeSpeed), "slime", { hp: big ? bigSlimeHits : 1 }])
})

// A blast hits a slime
onCollide("blast", "slime", (blast, slime) => {
    destroy(blast)
    slime.hp = slime.hp - 1
    if (slime.hp <= 0) {
        destroy(slime)
        addKaboom(slime.pos)
        score.add(slimePoints)
        if (score.value >= target) {
            tj.victory("You saved the farm!")
        }
    }
})

// A slime gets past the fence: lose a life
onUpdate("slime", (slime) => {
    if (slime.pos.x < 100) {
        destroy(slime)
        lives.lose()
    }
})

// Every 15 seconds the slimes get faster
loop(15, () => {
    slimeSpeed = slimeSpeed + 15
})

How it works on TalentJR

  1. Play the gameFind out what feels too easy or too hard — that is what you will change.
  2. Open it in the studioThe code is on the left, the game on the right. Press ▶ Run after every change.
  3. Change one thing at a timeA number first, then a new rule, then your own art and title.
  4. Save and shareSign in to keep your game, then share a talentjr.in/play/… link on WhatsApp — friends can play it and make their own version.

More games you can make

← All 19 games and the 4 ways to make games