🤼 Free · Ages 10+ · JavaScript · No download

How to make a Kabaddi game in JavaScript

Raid! Run into their half on one breath, touch a defender and get back over the line — but don't let two catch you! Play it first, then open it in the Game Studio and change it until it is your own game.

🎮 Controls: arrow keys (or WASD) to run

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 raiderSpeed = 240How fast you run
let breathTime = 6Seconds you can stay in their half (one breath!)
let defenders = 4Players in the other team
let chaseSpeed = 70How fast the defenders chase you
let raids = 6Raids you get
let target = 5Points you need to win
let matColor = [234, 88, 12]

7 ways to change the kabaddi 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: hold your breath longer.आसान: साँस ज़्यादा देर रोकें।
    let breathTime = 9
  2. Run faster.तेज़ दौड़ें।
    let raiderSpeed = 320
  3. Easier: slower defenders.आसान: धीमे डिफ़ेंडर।
    let chaseSpeed = 40
  4. Get more raids.ज़्यादा रेड।
    let raids = 10
  5. Harder: a bigger team.मुश्किल: बड़ी टीम।
    let defenders = 6
  6. Harder: more points to win.मुश्किल: जीत के लिए ज़्यादा अंक।
    let target = 8
  7. Paint the mat a new colour.मैट का रंग बदलें।
    let matColor = [22, 163, 74]

The Kabaddi code (JavaScript)

110 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
// 🤼 Kabaddi — TalentJR Game Studio
// ✏️ Change these numbers, then press ▶ Run!
let raiderSpeed = 240     // how fast you run
let breathTime = 6        // seconds you can stay in their half (one breath!)
let defenders = 4         // players in the other team
let chaseSpeed = 70       // how fast the defenders chase you
let raids = 6             // raids you get
let target = 5            // points you need to win
let matColor = [234, 88, 12]

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

// The mat: their half at the top, your half at the bottom, the middle line between
const LINE = 260
add([rect(560, 440), pos(40, 20), color(...matColor)])
add([rect(560, 6), pos(40, LINE - 3), color(255, 255, 255)])
add([text("THEIR HALF", { size: 16 }), pos(52, LINE - 26), color(255, 255, 255)])
add([text("YOUR HALF", { size: 16 }), pos(52, LINE + 10), color(255, 255, 255)])

// You are the raider (arrow keys)
const raider = tj.player({ x: 296, y: 380, speed: raiderSpeed, mode: "topdown" })
raider.onUpdate(() => {
    raider.pos.x = Math.max(40, Math.min(552, raider.pos.x))     // stay on the mat
    raider.pos.y = Math.max(20, Math.min(412, raider.pos.y))
})

// The defenders wait in their half — and chase you when you come in
for (let i = 0; i < defenders; i++) {
    const home = vec2(80 + i * (460 / defenders), 80 + (i % 2) * 70)
    add([sprite("robot"), pos(home), scale(0.75), color(59, 130, 246), "defender", { tagged: false, home: home }])
}
onUpdate("defender", (d) => {
    if (raider.pos.y < LINE) d.move(raider.pos.sub(d.pos).unit().scale(chaseSpeed))
    d.pos.y = Math.min(d.pos.y, LINE - 50)       // defenders never leave their half
})

// Points, raids left and your breath
const score = tj.score()
let raidsLeft = raids
let raiding = false
let breath = 0
let tags = 0                                     // defenders you touched in this raid
const chant = add([text("", { size: 26 }), pos(width() / 2, 300), anchor("center"), color(255, 255, 255)])
const info = add([text("", { size: 18 }), pos(588, 30), anchor("topright"), color(255, 255, 255)])
function showInfo() {
    info.text = "Raids left " + raidsLeft + " · Target " + target
}
showInfo()

// In their half you keep saying "Kabaddi!" — on ONE breath. Back over the line ends the raid
onUpdate(() => {
    if (raider.pos.y < LINE) {
        if (!raiding) {
            raiding = true
            breath = breathTime
            tags = 0
        }
        breath = breath - dt()
        chant.text = "Kabaddi! Kabaddi! " + Math.ceil(breath)
        if (breath <= 0) endRaid("Out of breath!", false)
    } else if (raiding) {
        if (tags === 0) endRaid("Back home", true)
        else endRaid("+" + tags + (tags === 1 ? " point!" : " points!"), true)
    }
})

// Touch ONE defender to tag them — but if TWO catch you at once (touched or not), you are tackled!
onUpdate(() => {
    if (!raiding) return
    const near = get("defender").filter((d) => d.pos.dist(raider.pos) < 40)
    if (near.length >= 2) endRaid("Tackled!", false)
    else if (near.length === 1 && !near[0].tagged) {
        near[0].tagged = true
        near[0].color = rgb(148, 163, 184)      // grey: touched
        tags = tags + 1
        tj.sound("pop")
    }
})

// The raid ends: safe at home (points!), out of breath or tackled
function endRaid(words, safe) {
    raiding = false
    chant.text = ""
    raidsLeft = raidsLeft - 1
    if (safe && tags > 0) {
        score.add(tags)
        tj.sound("coin")
        get("defender").forEach((d) => {
            if (d.tagged) destroy(d)             // the defenders you touched are out
        })
    } else if (!safe) {
        tj.sound("hit")
        shake(6)
    }
    get("defender").forEach((d) => {            // everyone back to their places
        d.tagged = false
        d.color = rgb(59, 130, 246)
        d.pos = d.home.clone()
    })
    raider.pos = vec2(296, 380)
    say(words)
    showInfo()
    if (score.value >= target || get("defender").length === 0) tj.victory("Kabaddi champion!")
    else if (raidsLeft <= 0) tj.gameOver("No raids left! " + score.value + " of " + target + " points")
}
function say(words) {
    add([text(words, { size: 48 }), pos(width() / 2, 340), anchor("center"), color(255, 255, 255), opacity(1), lifespan(1.2, { fade: 0.5 })])
}

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