diff --git a/games/Fortress-Fighter.js b/games/Fortress-Fighter.js index 12cd7e8768..7e1bd50c31 100644 --- a/games/Fortress-Fighter.js +++ b/games/Fortress-Fighter.js @@ -9,33 +9,94 @@ https://sprig.hackclub.com/gallery/getting_started @addedOn: 2025-00-00 */ -const player = "p" +const player1 = "5" +const player2 = "6" +const player3 = "7" +const player4 = "8" const enemy = "e" +const enemy2 = "d" const background = "b" const blast1 = "1" const blast2 = "2" +const blast3 = "3" +const blast4 = "4" const castle = "c" - +const marker = "m" +const walkway = "w" setLegend( - [ player, bitmap` -....99999999.... -...9955555599... -..995555555599.. -.99555555555599. -9955555555555599 -9555555555555559 -9555555555555559 -9555555555555559 -9555555555555559 -9555555555555559 -9555555555555559 -9955555555555599 -.99555555555599. -..995555555599.. -...9955555599... -....99999999....` ], + [ player1, bitmap` +.......33....... +...LL113311LL... +..LL11133111LL.. +.LL1111331111LL. +LL111113311111LL +L11111133111111L +L11111133111111L +L11111133111111L +L11111133111111L +L11111133111111L +L11111133111111L +LL111113311111LL +.LL1111331111LL. +..LL11111111LL.. +...LL111111LL... +....LLLLLLLL....` ], + [ + player2, bitmap` +....LLLLLLLL.... +...LL111111LL... +..LL11111111LL.. +.LL1111111111LL. +LL111111111111L. +L11111111111111. +L11111111111111. +L113333333333333 +L113333333333333 +L11111111111111. +L11111111111111. +LL111111111111L. +.LL1111111111LL. +..LL11111111LL.. +...LL111111LL... +....LLLLLLLL....` ], + [ + player3, bitmap` +....LLLLLLLL.... +...LL111111LL... +..LL11111111LL.. +.LL1111331111LL. +LL111113311111LL +L11111133111111L +L11111133111111L +L11111133111111L +L11111133111111L +L11111133111111L +L11111133111111L +LL111113311111LL +.LL1111331111LL. +..LL11133111LL.. +...LL113311LL... +.......33.......` ], + [ + player4, bitmap` +....LLLLLLLL.... +...LL111111LL... +..LL11111111LL.. +.LL1111111111LL. +.L111111111111LL +.11111111111111L +.11111111111111L +333333333333311L +333333333333311L +.11111111111111L +.11111111111111L +.L111111111111LL +.LL1111111111LL. +..LL11111111LL.. +...LL111111LL... +....LLLLLLLL....` ], [ enemy, bitmap` @@ -55,26 +116,80 @@ setLegend( ..333..3.3.3.33. .33.3..3.3.33.3. 33..3..3.3..3.33`], +[ + enemy2, + bitmap` +......3....33... +.3....3.3.3...3. +..3..3..3.3..33. +...3333333333... +3..33.3333.33... +.3.333...33.333. +.3.3333333333... +..3333.333.33.3. +...3333..33333.. +3.33.33...333.3. +.3.3..33...333.. +...3333333333... +.333333333333... +...33..3.3.3.3.. +.33.3.3.3..3..3. +......3..3..3...`], [ - castle, + blast3, bitmap` -LLL11LL11LL11LLL -LLL11LL11LL11LLL -LL111111111111LL -1111111111111111 -1111LLLLLLLL1111 -LL11LLLLLLLL11LL -LL11LLLLLLLL11LL -1111LLLLLLLL1111 -1111LLLLLLLL1111 -LL11LLLLLLLL11LL -LL11LLLLLLLL11LL -1111LLLLLLLL1111 -1111111111111111 -LL111111111111LL -LLL11LL11LL11LLL -LLL11LL11LL11LLL`], - +................ +................ +................ +................ +.9.99.9.99.9.99. +9999999999999999 +9755577777757579 +9777557555575579 +9555777777777779 +9575557757777559 +9999999999999999 +.99.9.99.9.99.9. +................ +................ +................ +................`], + [ + blast4, + bitmap` +.....999999..... +....99557799.... +....9975759..... +.....9557599.... +....99575599.... +.....957579..... +....99777799.... +....9977579..... +.....9575799.... +....99775799.... +.....977579..... +....99777599.... +....9977579..... +.....9575599.... +....99577799.... +.....999999.....`], + [marker, bitmap` +................ +................ +................ +................ +................ +................ +.....999999..... +.....999999..... +.....999999..... +.....999999..... +................ +................ +................ +................ +................ +................`], [ blast1, bitmap` @@ -113,6 +228,42 @@ LLL11LL11LL11LLL`], ...97557555759.. ..99975777599... ..9.99999999.99.`], + [ walkway, bitmap` +LL111111111111LL +LL111111111111LL +LL111111111111LL +LL111111111111LL +LL111111111111LL +LL111111111111LL +LL111111111111LL +LL111111111111LL +LL111111111111LL +LL111111111111LL +LL111111111111LL +LL111111111111LL +LL111111111111LL +LL111111111111LL +LL111111111111LL +LL111111111111LL` ], + [ + castle, + bitmap` +LLL11LL11LL11LLL +LLL11LL11LL11LLL +LL111111111111LL +1111111111111111 +1111LLLLLLLL1111 +LL11LLLLLLLL11LL +LL11LLLLLLLL11LL +1111LLLLLLLL1111 +1111LLLLLLLL1111 +LL11LLLLLLLL11LL +LL11LLLLLLLL11LL +1111LLLLLLLL1111 +1111111111111111 +LL111111111111LL +LLL11LL11LL11LLL +LLL11LL11LL11LLL`], [ background, bitmap` @@ -132,23 +283,25 @@ DDD4DD44DDDDDD4D 44DDDDD4444D4D4D D4444D4DD44D44DD DDDD44DDDD4DD4DD`], - ) +) + let level = 0 let health = 10 -let ticks = 0 +let score= 0 +let direction = 1 const levels = [map` -bbbbbbbbbb -bbbbbbbbbb -bbbbbbbbbb -bbbbbbbbbb -bbbbbbbbbb -bbbbbbbbbb -bbbbbbbbbb -bbbbbbbbbb -bbbbbbbbbb +wbbbbbbbbw +wbbbbbbbbw +wbbbbbbbbw +wbbbbbbbbw +wbbbbbbbbw +wbbbbbbbbw +wbbbbbbbbw +wbbbbbbbbw +wbbbbbbbbw bbbbbbbbbb`] const currentLevel = levels[level] @@ -163,8 +316,8 @@ addText("Health: 10", { color: color `2` }); - -addSprite(8, 9, player) +addSprite(8, 9, marker) +addSprite(8, 9, player1) addSprite(0,9,castle) addSprite(1,9,castle) addSprite(2,9,castle) @@ -176,81 +329,298 @@ addSprite(7,9,castle) addSprite(8,9,castle) addSprite(9,9,castle) - onInput("w", () => { - if (gameRunning === true) { - if (getFirst(player).y > 0) { - getFirst(player).y-=1 - } + if (gameRunning === true) { + if (direction === 1){ + if (getFirst(marker).y > 0) { + getFirst(marker).y-=1 } +} +} }) onInput("s", () => { - if (gameRunning === true) { - if (getFirst(player).y < 10) { - getFirst(player).y-=-1 - } + if (gameRunning === true) { + if (direction === 3){ + if (getFirst(marker).y < 9) { + getFirst(marker).y+=1 } +} +} }) -onInput("d", () => { - if (gameRunning === true) { - if (getFirst(player).x < 8) { - getFirst(player).x-=-1 - } +onInput("a", () => { + if (gameRunning === true) { + if (direction === 4){ + if (getFirst(marker).x > 1) { + getFirst(marker).x-=1 } +} +} }) -onInput("a", () => { - if (gameRunning === true) { - if (getFirst(player).x > 1) { - getFirst(player).x-=1 - } +onInput("d", () => { + if (gameRunning === true) { + if (direction === 2){ + if (getFirst(marker).x < 8) { + getFirst(marker).x+=1 } +} +} }) - onInput("l",() => { +onInput("w", () => { + if (gameRunning === true) { + if (direction === 1){ + if (getFirst(player1).y > 0) { + getFirst(player1).y-=1 + direction = 1 + } + }else{ + if (direction === 2){ + if (getFirst(player2).y > 0) { + } + addSprite(getFirst(player2).x,getFirst(player2).y,player1) + getFirst(player2).remove() + direction = 1 + }else{ + if (direction === 3){ + if (getFirst(player3).y > 0) { + } + addSprite(getFirst(player3).x,getFirst(player3).y,player1) + getFirst(player3).remove() + direction = 1 + }else{ + if (direction === 4){ + if (getFirst(player4).y > 0) { + } + addSprite(getFirst(player4).x,getFirst(player4).y,player1) + getFirst(player4).remove() + direction = 1 + } + } + } + } + } + }) + + onInput("s", () => { if (gameRunning === true) { - if (getFirst(player).x < 9) { - let l = getFirst(player) - addSprite(l.x+1, l.y, blast1) + if (direction === 3){ + if (getFirst(player3).y < 9) { + getFirst(player3).y+=1 + direction = 3 + } + }else{ + if (direction === 2){ + if (getFirst(player2).y < 9) { + } + addSprite(getFirst(player2).x,getFirst(player2).y,player3) + getFirst(player2).remove() + direction = 3 + }else{ + if (direction === 1){ + if (getFirst(player1).y < 9) { + } + addSprite(getFirst(player1).x,getFirst(player1).y,player3) + getFirst(player1).remove() + direction = 3 + }else{ + if (direction === 4){ + if (getFirst(player4).y < 9) { + } + addSprite(getFirst(player4).x,getFirst(player4).y,player3) + getFirst(player4).remove() + direction = 3 + } + } + } } } -}) - + }) -onInput("j",() => { - if (gameRunning === true) { - if (getFirst(player).x > 0) { - let j = getFirst(player) - addSprite(j.x-1, j.y, blast1) + onInput("d", () => { + if (gameRunning === true) { + if (direction === 2){ + if (getFirst(player2).x < 8) { + getFirst(player2).x+=1 + direction = 2 + } + }else{ + if (direction === 3){ + if (getFirst(player3).x < 8) { + } + addSprite(getFirst(player3).x,getFirst(player3).y,player2) + getFirst(player3).remove() + direction = 2 + }else{ + if (direction === 1){ + if (getFirst(player1).x < 8) { + } + addSprite(getFirst(player1).x,getFirst(player1).y,player2) + getFirst(player1).remove() + direction = 2 + }else{ + if (direction === 4){ + if (getFirst(player4).x < 8) { + } + addSprite(getFirst(player4).x,getFirst(player4).y,player2) + getFirst(player4).remove() + direction = 2 + } + } + } } - } -}) + } + }) + onInput("a", () => { + if (gameRunning === true) { + if (direction === 4){ + if (getFirst(player4).x > 1) { + getFirst(player4).x-=1 + direction = 4 + } + }else{ + if (direction === 3){ + if (getFirst(player3).x > 1) { + } + addSprite(getFirst(player3).x,getFirst(player3).y,player4) + getFirst(player3).remove() + direction = 4 + }else{ + if (direction === 1){ + if (getFirst(player1).x > 1) { + } + addSprite(getFirst(player1).x,getFirst(player1).y,player4) + getFirst(player1).remove() + direction = 4 + }else{ + if (direction === 2){ + if (getFirst(player2).x > 1) { + } + addSprite(getFirst(player2).x,getFirst(player2).y,player4) + getFirst(player2).remove() + direction = 4 + } + } + } + } + } + }) -onInput("i",() => { - if (gameRunning === true) { - if (getFirst(player).y > 0) { - let i = getFirst(player) - addSprite(i.x, i.y-1, blast2) + onInput("k", () => { + if (gameRunning === true) { + if (direction === 4){ + if (getFirst(player4).x > 0) { + let j = getFirst(player4) + addSprite(j.x-1, j.y, blast1) } - } -}) + + }else{ + if (direction === 3){ + if (getFirst(player3).y < 9) { + let j = getFirst(player3) + addSprite(j.x, j.y+1, blast2) + } + + }else{ + if (direction === 1){ + if (getFirst(player1).y < 8) { + let j = getFirst(player1) + addSprite(j.x, j.y-1, blast2) + } + }else{ + if (direction === 2){ + if (getFirst(player2).y < 8) { + let j = getFirst(player2) + addSprite(j.x+1, j.y, blast1) + } + } + } + } + } + } + }) + + onInput("l", () => { + if (gameRunning === true) { + if (direction === 4){ + if (getFirst(player4).x > 2) { + + let j = getFirst(player4) + addSprite(j.x-1, j.y, blast3) + addSprite(j.x-2, j.y, blast3) + addSprite(j.x-3, j.y, blast3) + }else if (getFirst(player4).x === 2){ + let j = getFirst(player4) + addSprite(j.x-1, j.y, blast3) + addSprite(j.x-2, j.y, blast3) + }else if (getFirst(player4).x === 1){ + let j = getFirst(player4) + addSprite(j.x-1, j.y, blast3) + } + + }else{ + if (direction === 3){ + if (getFirst(player3).y < 7) { + let j = getFirst(player3) + addSprite(j.x, j.y+1, blast4) + addSprite(j.x, j.y+2, blast4) + addSprite(j.x, j.y+3, blast4) + }else if (getFirst(player3).y === 7){ + let j = getFirst(player3) + addSprite(j.x, j.y+1, blast4) + addSprite(j.x, j.y+2, blast4) + }else if (getFirst(player3).y === 8){ + let j = getFirst(player3) + addSprite(j.x, j.y+1, blast4) + } + + }else{ + if (direction === 1){ + if (getFirst(player1).y > 2) { + let j = getFirst(player1) + addSprite(j.x, j.y-1, blast4) + addSprite(j.x, j.y-2, blast4) + addSprite(j.x, j.y-3, blast4) + }else if (getFirst(player1).y === 2){ + let j = getFirst(player1) + addSprite(j.x, j.y-1, blast4) + addSprite(j.x, j.y-2, blast4) + }else if (getFirst(player1).y === 1){ + let j = getFirst(player1) + addSprite(j.x, j.y-1, blast4) + } + }else{ + if (direction === 2){ + if (getFirst(player2).x < 7) { + let j = getFirst(player2) + addSprite(j.x+1, j.y, blast3) + addSprite(j.x+2, j.y, blast3) + addSprite(j.x+3, j.y, blast3) + }else if (getFirst(player2).x === 7){ + let j = getFirst(player2) + addSprite(j.x+1, j.y, blast3) + addSprite(j.x+2, j.y, blast3) + }else if (getFirst(player2).x === 8){ + let j = getFirst(player2) + addSprite(j.x+1, j.y, blast3) + } + } + } + } + } + } + }) + -onInput("k",() => { - if (gameRunning === true) - if (getFirst(player).y < 9) { - let k = getFirst(player) - addSprite(k.x, k.y+1, blast2) - } -}) let onOff = 0 function spawnEnemy() { - if (ticks < 25) { + if (score < 500) { if(onOff === 0) { let x = Math.floor(Math.random() * 10) let y = 0 @@ -267,7 +637,9 @@ let x = Math.floor(Math.random() * 10) } function moveEnemy() { - let enemies = getAll(enemy) + let enemies = getAll(enemy).concat(getAll(enemy2)) + if(score < 500){ + if(onOff === 0){ for (let i = 0; i < enemies.length; i++) { if(enemies[i].y < 9) { enemies[i].y +=1 @@ -276,15 +648,32 @@ function moveEnemy() { enemies[i].x+=1 }else{ enemies[i].x-=1 + } + } } } + }else{ + for (let i = 0; i < enemies.length; i++) { + if(enemies[i].y < 9) { + enemies[i].y +=1 + } else { + if(enemies[i].x < 5) { + enemies[i].x+=1 + }else{ + enemies[i].x-=1 + } + } + } } } function checkHit() { - const hits = tilesWith(enemy, player).length - if(hits === 1) { + const playerNumbers = {1: player1, 2: player2, 3: player3, 4: player4} + const hits = tilesWith(enemy, playerNumbers[direction]).length + if(hits > 0) { health = health - 1 + let x = playerNumbers[direction].x + let y = playerNumbers[direction].y addText("Health: " + health + " ", { x: 1, y: 1, @@ -294,9 +683,8 @@ function checkHit() { } function destroyEnemy() { -let enemies = getAll(enemy) -let blasts = getAll(blast1).concat(getAll(blast2)) - +let enemies = getAll(enemy).concat(getAll(enemy2)) +let blasts = getAll(blast1).concat(getAll(blast2)).concat(getAll(blast3)).concat(getAll(blast4)) for (let e = 0; e < blasts.length; e++) { for (let i = 0; i < enemies.length; i++) { @@ -306,6 +694,7 @@ let blasts = getAll(blast1).concat(getAll(blast2)) let y = enemies[i].y enemies[i].remove() blasts[e].remove() + score += 1 } } } @@ -313,8 +702,10 @@ let blasts = getAll(blast1).concat(getAll(blast2)) } + + function removeBlasts() { -let blasts = getAll(blast1).concat(getAll(blast2)) +let blasts = getAll(blast1).concat(getAll(blast2)).concat(getAll(blast3)).concat(getAll(blast4)) for (let b of blasts) { b.remove() @@ -323,7 +714,7 @@ b.remove() function castleCrusher() { let castles = getAll(castle) -let enemies = getAll(enemy) +let enemies = getAll(enemy).concat(getAll(enemy2)) for (let c of castles) { for (let e of enemies) { @@ -349,14 +740,12 @@ for (let e of enemies) { var gameLoop = setInterval(() => { castleCrusher() destroyEnemy() - checkHit() moveEnemy() checkHit() - destroyEnemy() removeBlasts() spawnEnemy() - ticks = ticks +1 - addText("score: " + ticks, { + score += 1 + addText("Score: " + score, { x: 1, y: 2, color: color`2` @@ -375,4 +764,4 @@ addText("Game over", { color: color`2` }); } -}, 500) +}, 500) \ No newline at end of file diff --git a/games/img/Fortress-Fighter.png b/games/img/Fortress-Fighter.png index eafee3137e..3190979ad8 100644 Binary files a/games/img/Fortress-Fighter.png and b/games/img/Fortress-Fighter.png differ