diff --git a/games/Zombie-Rush.js b/games/Zombie-Rush.js new file mode 100644 index 0000000000..c53e261aaa --- /dev/null +++ b/games/Zombie-Rush.js @@ -0,0 +1,372 @@ +/* +@title: Zombie Rush +@author: Arghya Vyas +@description: A simple shooter game where you shoot zombies! +@tags: [zombie, shooter, arcade, game] +@addedOn: 2025-00-00 +*/ + +const player = "p" +const zombie = "z" +const bullet = "b" +const playershootingl = "l" +const playershootingr = "r" +const bgmusic = tune` +285.7142857142857: F4^285.7142857142857 + C4~285.7142857142857, +285.7142857142857: E4^285.7142857142857 + D4~285.7142857142857, +285.7142857142857: C4~285.7142857142857 + G4^285.7142857142857, +285.7142857142857: D4~285.7142857142857 + A4^285.7142857142857, +285.7142857142857: C4~285.7142857142857 + E4^285.7142857142857 + G4^285.7142857142857, +285.7142857142857: D4~285.7142857142857 + F4^285.7142857142857, +285.7142857142857: C4~285.7142857142857 + E4^285.7142857142857, +285.7142857142857: G4^285.7142857142857 + D4~285.7142857142857, +285.7142857142857: A4^285.7142857142857 + C4~285.7142857142857, +285.7142857142857: G4^285.7142857142857 + D4~285.7142857142857, +285.7142857142857: F4^285.7142857142857 + C4~285.7142857142857, +285.7142857142857: E4^285.7142857142857 + D4~285.7142857142857, +285.7142857142857: C4~285.7142857142857, +285.7142857142857: E4^285.7142857142857 + D4~285.7142857142857, +285.7142857142857: F4^285.7142857142857 + C4~285.7142857142857, +285.7142857142857: E4^285.7142857142857 + D4~285.7142857142857, +285.7142857142857: G4^285.7142857142857 + C4~285.7142857142857, +285.7142857142857: A4^285.7142857142857 + D4~285.7142857142857, +285.7142857142857: G4^285.7142857142857 + C4~285.7142857142857, +285.7142857142857: F4^285.7142857142857 + D4~285.7142857142857, +285.7142857142857: E4^285.7142857142857 + C4~285.7142857142857, +285.7142857142857: D4~285.7142857142857, +285.7142857142857: E4^285.7142857142857 + C4~285.7142857142857, +285.7142857142857: F4^285.7142857142857 + D4~285.7142857142857, +285.7142857142857: E4^285.7142857142857 + C4~285.7142857142857, +285.7142857142857: G4^285.7142857142857 + D4~285.7142857142857, +285.7142857142857: A4^285.7142857142857 + C4~285.7142857142857, +285.7142857142857: G4^285.7142857142857 + D4~285.7142857142857, +285.7142857142857: F4^285.7142857142857 + C4~285.7142857142857, +285.7142857142857: E4^285.7142857142857 + D4~285.7142857142857, +285.7142857142857: C4~285.7142857142857, +285.7142857142857: E4^285.7142857142857 + D4~285.7142857142857` +const shootr = tune` +500: G4-500 + F4-500 + E4/500 + D4/500, +15500` +const shootl = tune` +500: F4^500 + E4^500 + D4-500 + C4-500, +15500` +const tutorialbgr = "1" +const tutorialbgl = "2" +const hiddenwall = "w" +const boss = "a" +setLegend( + [ player, bitmap` +................ +................ +................ +................ +................ +................ +......0000...... +......0000...... +......0000...... +.1111.0000...... +...10..00..1111. +....000000001... +.......00...1... +.......00....... +......0..0...... +......0..0......` ], + [ zombie, bitmap` +................ +................ +................ +................ +................ +.......88....... +......DDDD...... +......0D0D...... +......DDDD...... +......000D...... +.......DD....... +......DDD....... +.......DD....... +................ +................ +................` ], + [ bullet, bitmap` +................ +................ +................ +................ +................ +.....9.......... +..........9..... +.......66....... +.......66....... +................ +.....9.......... +..........9..... +................ +................ +................ +................` ], + [ playershootingl, bitmap` +................ +................ +................ +................ +................ +................ +.6....0000...... +......0000...... +.9....0000...... +91111.0000...... +.9.10..00..1111. +..6.000000001... +.......00...1... +.......00....... +......0..0...... +......0..0......` ], +[ playershootingr, bitmap` +................ +................ +................ +................ +................ +................ +......0000...... +......0000...6.. +......0000...... +.1111.0000....9. +...10..00..11119 +....000000001.9. +.......00...1... +.......00....6.. +......0..0...... +......0..0......` ], +[ tutorialbgr, bitmap` +................ +................ +................ +................ +................ +................ +.......00....... +....66.00.66.... +...6006..6006... +...6006..6006... +....66.00.66.... +.......00....... +................ +................ +................ +................` ], +[ tutorialbgl, bitmap` +................ +.......0........ +......000....... +.....0.0.0...... +.......0........ +......333....... +..0...333....0.. +.0..33...33...0. +000033...3300000 +.0..33...33...0. +..0...333....0.. +......333....... +.......0........ +.....0.0.0...... +......000....... +.......0........` ], +[ hiddenwall, bitmap` +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................` ], +[ boss, bitmap` +......8H88...... +...888888H888... +..888HH88888888. +.88HH888888H8H8. +.44444443444444. +.42222443422224. +.42002443420024. +.42002243420024. +.44222243422224. +.44444444344434. +.44444443444344. +.44444444444444. +.40000000000004. +.402C332CC2C004. +.40000000000004. +.44444444444444.` ] +) + +setSolids([player, zombie, tutorialbgr, tutorialbgl, hiddenwall]) + +let level = 0 +const levels = [ + map` +ww..z.z. +21...... +ww....z. +ww.p....`, + map` +....z... +.z.z..z. +p....z.. +..z.z.z. +....z... +..z...z.`, + map` +z..z...... +...z..z..z +z.z.z.z... +z...z..z.. +..zz..zz.z +z....z..z. +..p...z... +....z..z..`, + map` +.......... +...a..a..a +z.z.z.z... +z...z..za. +..zz..zz.z +z....z..z. +..p...z.a. +....z..z..` +] +setMap(levels[level]) +playTune(bgmusic, Infinity) +function animateShoot(p, shootingSprite) { + clearTile(p.x, p.y) + addSprite(p.x, p.y, shootingSprite) + + setTimeout(() => { + const s = getFirst(shootingSprite) + if (s) { + clearTile(s.x, s.y) + addSprite(s.x, s.y, player) + } + }, 150) +} +setPushables({ + [ player ]: [] +}) +addText("Controls", { + x: 0, + y: 4, + color: color`3` +}) +addText("wasd, j&l to shoot", { + x: 1, + y: 14, + color: color`3` +}) + +onInput("s", () => { + getFirst(player).y += 1 +}) +onInput("w", () => { + getFirst(player).y -= 1 +}) +onInput("d", () => { + getFirst(player).x += 1 +}) +onInput("a", () => { + getFirst(player).x -= 1 +}) +onInput("l", () => { // shoot right + const p = getFirst(player) + if (!p) return + + addSprite(p.x + 1, p.y, bullet) + const b = getTile(p.x + 1, p.y).find(s => s.type === bullet) + if (b) b.direction = 1 // right + playTune(shootl) + animateShoot(p, playershootingr) +}) + +onInput("j", () => { // shoot left + const p = getFirst(player) + if (!p) return + + addSprite(p.x - 1, p.y, bullet) + const b = getTile(p.x - 1, p.y).find(s => s.type === bullet) + if (b) b.direction = -1 // left + playTune(shootr) + animateShoot(p, playershootingl) +}) + +function bosshealth() { + const bosses = getAll(boss) + for (const b of bosses) { + if (b.health === undefined) { + b.health = 5 + } + } +} + +afterInput(() => { + const bullets = getAll(bullet) + for (const b of bullets) { + if (b.direction === undefined) { + b.remove() + continue + } + + let hit = getTile(b.x, b.y).find(s => s.type === zombie || s.type === boss) + if (hit) { + if (hit.type === boss) { + hit.health -= 1 + if (hit.health <= 0) { + hit.remove() + } + } else { + hit.remove() + } + b.remove() + continue +} + + b.x += b.direction + + if (b.x === 0 || b.x === width() - 1) { + b.remove() + continue + } else if (b.x < 0 || b.x >= width()) { + b.remove() + continue + } + + hit = getTile(b.x, b.y).find(s => s.type === zombie) + if (hit) { + hit.remove() + b.remove() + } + } + + if (getAll(zombie).length === 0) { + clearText() + level++ + if (level < levels.length) { + setMap(levels[level]) + bosshealth() + } else { + addText("YOU WIN!", { + x: 5, + y: 7, + color: color`6` + }) + } + } +})