diff --git a/games/Dodge-Ball.js b/games/Dodge-Ball.js new file mode 100644 index 0000000000..c6476f4a2a --- /dev/null +++ b/games/Dodge-Ball.js @@ -0,0 +1,681 @@ +/* +@title: Dogdge Ball +@author: ikane(on slack) +@tags: ['multiplayer'] +@addedOn: 2025-10-18 + +Controls: + +Player1 controls(red): WS to move up and down, D to shoot red balls. +Player2 controls(blue): IK to move up and down, J to shoot balls. +To continue the battle please click on A (WARNING: This will ONLY work if round has ended). + +Objective: + +The objective of the game is hit your opponent with your balls and to dodge the opponent's balls. +*/ + + +const melody = tune` +500: E5~500 + C4~500 + D4~500 + E4~500 + F4~500, +500: F4/500 + A5-500 + G5-500 + F5-500 + E5~500, +500: D4~500 + F4/500 + F5-500 + A5-500 + G5^500, +500: E4~500 + F4/500 + F5-500 + G5-500 + A5-500, +500: F4/500 + F5/500 + B4~500, +500: D4~500 + F4/500 + A5-500 + G5-500 + F5-500, +500: E4~500 + F4/500 + F5-500 + A5-500 + G5^500, +500: F4/500 + F5-500 + A5-500 + G5-500 + A4~500, +500: D4~500 + F4/500 + F5/500 + B4~500, +500: E4~500 + F4/500 + F5-500 + G5-500 + A5-500, +500: F4/500 + A5-500 + F5-500 + G5^500 + D5~500, +500: D4~500 + F4/500 + A5-500 + G5-500 + F5-500, +500: F4/500 + E4~500 + F5/500 + D5~500, +500: F4/500 + A5-500 + G5-500 + F5-500 + C5~500, +500: F4/500 + D4~500 + F5-500 + A5-500 + G5^500, +500: F4/500 + E4~500 + F5-500 + G5-500 + A5-500, +500: A5^500 + C4~500 + D4~500 + E4~500 + A4~500, +500: F4/500 + D4~500 + A5-500 + G5-500 + F5-500, +500: F4/500 + E4~500 + F5-500 + A5-500 + G5^500, +500: F4/500 + F5-500 + G5-500 + A5-500 + C5~500, +500: F4/500 + D4~500 + F5/500 + D5~500 + E5^500, +500: F4/500 + E4~500 + A5-500 + G5-500 + F5-500, +500: F4/500 + F5-500 + A5-500 + G5^500 + D5~500, +500: F4/500 + D4~500 + F5-500 + G5-500 + A5-500, +500: F4/500 + E4~500 + F5/500 + B4~500, +500: F4/500 + A5-500 + G5-500 + F5-500 + A4~500, +500: F4/500 + D4~500 + F5-500 + A5-500 + G5^500, +500: F4/500 + E4~500 + F5-500 + G5-500 + A5-500, +500: F4/500 + F5/500 + B4~500, +500: F4/500 + D4~500 + A5-500 + G5-500 + F5-500, +500: F4/500 + E4~500 + F5-500 + A5-500 + G5^500, +500: F4/500 + D4~500 + F5-500 + G5-500 + A5-500` + + + +playTune(melody) + + +const player1 = "p"; +const player2 = "y"; +const ball = "b"; +const bball = "m" +const wall = "f"; +const ground = "g"; +const outline = "x"; +const outline1 = "1"; +const outline2 = "2"; +const outline3 = "3"; +const outline4 = "4"; +const walloutline = "h"; +const outlinex = "z"; +const lineconectiontop = "0"; +const lineconectionbellow = "5"; +const leftoutline = "8"; +const rightoutline = "7"; +const bottomoutline = "9"; +const background = "6"; + +setLegend( + [player1, bitmap` +................ +....33333333.... +...3333333333... +..333333333333.. +.33333333333333. +.33333333333333. +.33333333333333. +.33333333333333. +.33333333333333. +.33333333333333. +.33333333333333. +.33333333333333. +..333333333333.. +...3333333333... +....33333333.... +................`], + [player2, bitmap` +................ +....55555555.... +...5555555555... +..555555555555.. +.55555555555555. +.55555555555555. +.55555555555555. +.55555555555555. +.55555555555555. +.55555555555555. +.55555555555555. +.55555555555555. +..555555555555.. +...5555555555... +....55555555.... +................`], + [ball, bitmap` +................ +....33333333.... +...3322222233... +..322333333223.. +.33232222223233. +.32322333322323. +.32323322332323. +.32323233232323. +.32323233232323. +.32323322332323. +.32322333322323. +.33232222223233. +..322333333223.. +...3322222233... +....33333333.... +................`], + [bball, bitmap ` +................ +....55555555.... +...5522222255... +..522555555225.. +.55255555555255. +.52555222255525. +.52552222225525. +.52552222225525. +.52552222225525. +.52552222225525. +.52555222255525. +.55255555555255. +..522555555225.. +...5522222255... +....55555555.... +................`], + [wall, bitmap ` +................ +................ +................ +................ +................ +................ +......2222...... +......2772...... +......2772...... +......2222...... +................ +................ +................ +................ +................ +................`], + [ground, bitmap` +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................`], + [outline, bitmap` +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +.......60.......`], + [outline1, bitmap ` +1111606060606060 +1116060606060606 +11606........... +1606............ +606............. +06.............. +60.............. +06.............. +60.............. +06.............. +60.............. +06.............. +60.............. +06.............. +60.............. +06..............`], + [outline2, bitmap` +06.............. +60.............. +06.............. +60.............. +06.............. +60.............. +06.............. +60.............. +06.............. +60.............. +06.............. +606............. +1606............ +11606........... +1116060606060606 +1111606060606060`], + [outline3, bitmap` +..............60 +..............06 +..............60 +..............06 +..............60 +..............06 +..............60 +..............06 +..............60 +..............06 +..............60 +.............606 +............6061 +...........60611 +6060606060606111 +0606060606061111`], + [outline4, bitmap ` +0606060606061111 +6060606060606111 +...........60611 +............6061 +.............606 +..............60 +..............06 +..............60 +..............06 +..............60 +..............06 +..............60 +..............06 +..............60 +..............06 +..............60`], + [outlinex, bitmap ` +6060606060606060 +0606060606060606 +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................`], + [walloutline, bitmap ` +6060606060606060 +0606060606060606 +................ +................ +................ +................ +......2222...... +......2772...... +......2772...... +......2222...... +................ +................ +................ +................ +................ +................`], + [lineconectiontop, bitmap ` +6060606060606060 +0606060606060606 +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +.......60.......`], + [lineconectionbellow, bitmap ` +.......60....... +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +.......60....... +.......06....... +0606060606060606 +6060606060606060`], + [leftoutline, bitmap ` +..............60 +..............06 +..............60 +..............06 +..............60 +..............06 +..............60 +..............06 +..............60 +..............06 +..............60 +..............06 +..............60 +..............06 +..............60 +..............06`], + [rightoutline, bitmap ` +60.............. +06.............. +60.............. +06.............. +60.............. +06.............. +60.............. +06.............. +60.............. +06.............. +60.............. +06.............. +60.............. +06.............. +60.............. +06..............`], + [bottomoutline, bitmap ` +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +................ +0606060606060606 +6060606060606060`], + [background, bitmap` +4477777777777777 +7447777777777777 +7747777777777777 +7747777777777777 +7744447777777777 +7777774777777777 +7777774777777777 +7777774474777777 +7777777444477777 +7777777777747777 +7777777777747777 +7777777777744777 +7777777777774477 +7777777777777447 +7777777777777773 +7777777777777773`], +); + +let level = 0 +let level2 = 1 +let level3 = 2 +const levels = [ + map ` +1zzzz0zzzz4 +7ggggxgggg8 +7ggggxgg.g8 +7.p..x.gy.8 +7ggggxgggg8 +7ggggxgggg8 +29999599993`, +] + + + + +const currentLevel = levels[level]; +setMap(currentLevel); + +setSolids([player1, player2]) + +setBackground(background) + + + + + + +//spawn balls +function spawnBlueballs() { + let p2x = getFirst(player2).x; + let p2y = getFirst(player2).y; + addSprite(p2x - 1, p2y, bball); +} + +function spawnRedballs() { + let p1x = getFirst(player1).x; + let p1y = getFirst(player1).y; + addSprite(p1x + 1, p1y, ball); +} + +//move the balls +function moveredBalls() { + let balls = getAll(ball); + + for (let i = 0; i < balls.length; i++) { + balls[i].x += 1; + } +} + +function moveblueBalls() { + let bballs = getAll(bball); + + for (let m = 0; m < bballs.length; m++) { + bballs[m].x -= 1; + } +} + +//despawn balls +function despawnredBalls() { + let balls = getAll(ball); + + for (let i = 0; i < balls.length; i++) { + // Check if ball is off-screen (x > 7 or x < 0) + if (balls[i].x == 9|| balls[i].x < 0) { + balls[i].remove(); + } + } +} + +function despawnblueBalls() { + let bballs = getAll(bball); + + for (let m = 0; m < bballs.length; m++) { + // Despawn when off screen (too far right OR too far left) + if (bballs[m].x > 11 || bballs[m].x < 3) { + bballs[m].remove(); + } + } +} + + +//check hit +function checkHitred() { + let bballs = getAll(bball); + let y = getFirst(player1); + + for (let m = 0; m < bballs.length; m++) { + if (bballs[m].x == y.x && bballs[m].y == y.y) { + return true; + } + } + + return false; +} + +function checkHitblue() { + let balls = getAll(ball); + let y = getFirst(player2); + + for (let i = 0; i < balls.length; i++) { + if (balls[i].x == y.x && balls[i].y == y.y) { + return true; + } + } + + return false; +} + + +//wins +var bluepoints = 0 +var redpoints = 0 + +function redwins() { + clearText(); + redpoints++; + addText("RED WINS", { + x: 2, + y: 5, + color: color`3` + }); + addText("Click A to restart", { + x: 1, + y: 6, + color: color`0` + }); + addText("Blue: " + bluepoints, { + x: 1, + y: 10, + color: color`5` + }); + gamerunning = false + addText("Red: " + redpoints, { + x: 12, + y: 10, + color: color`3` + }); +}; + + +function killballs() { + const balls = getAll(ball); + + balls.forEach(ball => { + ball.remove(); + }); + + const bballs = getAll(bball); + + bballs.forEach(bball => { + bball.remove(); + }); +} + + +function bluewins() { + clearText(); + bluepoints++; + killballs() + addText("BLUE WINS", { + x: 2, + y: 5, + color: color`5` + }); + addText("Click A to restart", { + x: 1, + y: 6, + color: color`0` + }); + addText("Blue: " + bluepoints, { + x: 1, + y: 10, + color: color`5` + }); + + addText("Red: " + redpoints, { + x: 12, + y: 10, + color: color`3` + }); +} + + + + + +var gameRunning = true + +var gameLoop = setInterval(() => { + moveredBalls(); + despawnredBalls(); + despawnblueBalls(); + moveblueBalls(); + + if (checkHitblue()) { + redwins(); + + gameRunning = false + }; + if (checkHitred()) { + bluewins(); + + gameRunning = false + }; + + } +, 150); + +//Reset mechanics + +onInput("a", () => { + if(gameRunning == false) { + clearText(); + gameRunning = true; + setMap(currentLevel); + } +}) + + + + +//controls and stop controls +onInput("w", () => { + getFirst(player1).y -= 1 +}) + +onInput("s", () => { + getFirst(player1).y += 1 +}) + +onInput("d", () => { + if (gameRunning == true) { + spawnRedballs(); + despawnblueBalls() + } +}) + +onInput("s", () => { + if (gameRunning == false) { + getFirst(player1).y -= 1; + } +}); + +onInput("w", () => { + if (gameRunning == false) { + getFirst(player1).y += 1; + } +}); + +onInput("i", () => { + getFirst(player2).y -= 1 +}) + +onInput("k", () => { + getFirst(player2).y += 1 +}) + +onInput("j", () => { + if (gameRunning == true) { + spawnBlueballs(); + despawnblueBalls(); + } +}) + +onInput("k", () => { + if (gameRunning == false) { + getFirst(player2).y -= 1; + } +}); + +onInput("i", () => { + if (gameRunning == false) { + getFirst(player2).y += 1; + } +}); +