🧱 Free · Ages 10+ · JavaScript · No download

How to make a Brick Breaker game in JavaScript

Bounce the ball with your paddle and break every brick — 3 levels. Play it first, then open it in the Game Studio and change it until it is your own game.

🎮 Controls: ← → to move the paddle (or A / D)

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 paddleSpeed = 420
let paddleWidth = 110
let paddleColor = [242, 106, 27]
let ballSpeed = 300
let speedUpPerLevel = 60The ball is faster on every new level
let brickRows = 3
let brickPoints = 10
let levels = 3Break all the bricks this many times to win
let startLives = 3

7 ways to change the brick breaker game

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

  1. Easier: make the paddle wider.आसान: paddle चौड़ा करें।
    let paddleWidth = 160
  2. Make the paddle faster.paddle को तेज़ करें।
    let paddleSpeed = 600
  3. Harder: a faster ball.मुश्किल: तेज़ गेंद।
    let ballSpeed = 400
  4. More rows of bricks.ईंटों की ज़्यादा पंक्तियाँ।
    let brickRows = 5
  5. Each brick is worth more points.हर ईंट के अंक बढ़ाएँ।
    let brickPoints = 25
  6. More levels before you win.जीतने से पहले ज़्यादा levels।
    let levels = 5
  7. Paint the paddle a new colour.paddle का रंग बदलें।
    let paddleColor = [59, 130, 246]

The Brick Breaker code (JavaScript)

98 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
// 🧱 Brick Breaker — TalentJR Game Studio
// ✏️ Change these numbers, then press ▶ Run!
let paddleSpeed = 420
let paddleWidth = 110
let paddleColor = [242, 106, 27]
let ballSpeed = 300
let speedUpPerLevel = 60  // the ball is faster on every new level
let brickRows = 3
let brickPoints = 10
let levels = 3            // break all the bricks this many times to win
let startLives = 3

tj.setup({ background: "night" })
tj.touchControls("leftright")

const score = tj.score()
const lives = tj.lives(startLives)
let level = 1
const levelLabel = add([text("Level 1", { size: 22 }), pos(width() / 2, 14), anchor("top"), color(255, 255, 255)])

// The paddle — arrow keys (or A / D) move it
const paddle = add([rect(paddleWidth, 16, { radius: 8 }), pos(width() / 2 - paddleWidth / 2, 440), area(), color(...paddleColor), "paddle"])
paddle.onUpdate(() => {
    if (tj.isDown("left")) paddle.move(-paddleSpeed, 0)
    if (tj.isDown("right")) paddle.move(paddleSpeed, 0)
    paddle.pos.x = Math.max(0, Math.min(width() - paddleWidth, paddle.pos.x))
})

// The ball waits on the paddle for 1 second, then flies
const ball = add([rect(16, 16, { radius: 8 }), pos(0, 0), area(), color(255, 255, 255), "ball"])
let velocity = vec2(0, 0)
let waiting = true
function serve() {
    waiting = true
    velocity = vec2(rand(-0.6, 0.6), -1).unit().scale(ballSpeed + (level - 1) * speedUpPerLevel)
    wait(1, () => {
        waiting = false
    })
}
serve()

// The ball moves and bounces off the sides and the top — miss it and you lose a life
ball.onUpdate(() => {
    if (waiting) {
        ball.pos = vec2(paddle.pos.x + paddleWidth / 2 - 8, 422)
        return
    }
    ball.move(velocity)
    if (ball.pos.x < 0 || ball.pos.x > width() - 16) {
        velocity.x = -velocity.x                       // bounce off the sides
        ball.pos.x = Math.max(0, Math.min(width() - 16, ball.pos.x))
    }
    if (ball.pos.y < 0) velocity.y = Math.abs(velocity.y)   // bounce off the top
    if (ball.pos.y > height()) {                       // missed it!
        lives.lose()
        serve()
    }
})

// Hit the paddle: the edges send the ball sideways
ball.onCollide("paddle", () => {
    const hit = (ball.pos.x + 8 - (paddle.pos.x + paddleWidth / 2)) / (paddleWidth / 2)
    velocity = vec2(hit, -1).unit().scale(velocity.len())
    tj.sound("pop")
})

// The bricks: more rows on every level
const COLORS = [[239, 68, 68], [250, 204, 21], [74, 222, 128], [59, 130, 246], [236, 72, 153]]
function buildBricks() {
    for (let row = 0; row < brickRows + level - 1; row++) {
        for (let col = 0; col < 10; col++) {
            add([rect(58, 20, { radius: 4 }), pos(12 + col * 62, 60 + row * 26), area(), color(...COLORS[row % COLORS.length]), "brick"])
        }
    }
}
buildBricks()

// Hit a brick: it breaks and you get points
ball.onCollide("brick", (brick) => {
    destroy(brick)
    velocity.y = -velocity.y
    score.add(brickPoints)
    tj.sound("coin")
    if (get("brick").length === 0) nextLevel()
})

// Every brick gone: the next level (or you win)
function nextLevel() {
    if (level >= levels) {
        tj.victory("You broke every brick! 🎉")
        return
    }
    level = level + 1
    levelLabel.text = "Level " + level
    buildBricks()
    serve()
}

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