From f211ad1be5d30f63787a4431a9a2e40627ee8128 Mon Sep 17 00:00:00 2001 From: sirbread Date: Sun, 29 Sep 2024 00:51:28 -0600 Subject: [PATCH 1/2] Add files via upload --- games/Not-so_space_invaders.js | 224 +++++++++++++++++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 games/Not-so_space_invaders.js diff --git a/games/Not-so_space_invaders.js b/games/Not-so_space_invaders.js new file mode 100644 index 0000000000..a94c391d49 --- /dev/null +++ b/games/Not-so_space_invaders.js @@ -0,0 +1,224 @@ +/* +Dodge the falling obstacles by moving left or right. +Survive as long as you can! +*/ + +// Define the player and obstacle sprites +const player = "p"; +const obstacle = "o"; +const outline = "b"; +const blacktile = "d"; + +// Sprites setup +setLegend( + [player, bitmap` +2000000000000002 +0000000LL0000000 +0000000LL0000000 +0000000LL0000000 +2000000LL0000002 +000000L77L000000 +000000L77L000000 +00000L1771L00000 +2000L117711L0002 +0000L111111L0000 +000L11111111L000 +000L11111111L000 +200LLLLLLLLLL002 +00000LL00LL00000 +0000066006600000 +0000006006000000`], + [obstacle, bitmap` +................ +................ +................ +.......000000... +....0001111110.. +...011L111LL10.. +...01111111L10.. +...01111111110.. +....01L111L110.. +....01111L1110.. +.....01111000... +.....001100..... +.......00....... +................ +................ +................`], + [outline, bitmap` +0..............0 +................ +................ +................ +0..............0 +................ +................ +................ +0..............0 +................ +................ +................ +0..............0 +................ +................ +................`], + [blacktile, bitmap` +2000000000000002 +0000000000000000 +0000000000000000 +0000000000000000 +2000000000000002 +0000000000000000 +0000000000000000 +0000000000000000 +2000000000000002 +0000000000000000 +0000000000000000 +0000000000000000 +2000000000000002 +0000000000000000 +0000000000000000 +0000000000000000`] +); + +// Create game map with an empty space at the bottom for player movement +setMap(map` +ddddd +ddddd +ddddd +ddddd +ddddd +ddddd +ddddd +ddddd +ddddd +ddddd +ddddd +ddddd +pdddd`); + +// Initialize the score +let score = 0; +let obstacleSpeed = 200; // Initial speed of obstacles (in milliseconds) +let spawnInterval = 1000; // Initial spawn interval for obstacles + +// Display the score on the screen +function displayScore() { + // Clear previous score text + clearText(); + + // Add score text in two lines + addText(`Score:`, { x: 0, y: 0, color: color`3` }); + addText(`${score}`, { x: 0, y: 1, color: color`3` }); +} + +// Function to reset the game state +function resetGame() { + score = 0; + obstacleSpeed = 200; + spawnInterval = 1000; + + // Clear the map and display player + setMap(map` + ddddd + ddddd + ddddd + ddddd + ddddd + ddddd + ddddd + ddddd + ddddd + ddddd + ddddd + ddddd + pdddd`); + + displayScore(); + + // Restart intervals + obstacleInterval = setInterval(spawnObstacle, spawnInterval); + gameInterval = setInterval(moveObstacles, obstacleSpeed); + scoreInterval = setInterval(updateScore, 1000); +} + +// Create game loop to update score +function updateScore() { + score++; + displayScore(); + + // Increase speed and spawn rate every 10 points + if (score % 10 === 0) { + obstacleSpeed = Math.max(50, obstacleSpeed - 100); // Decrease fall speed significantly + spawnInterval = Math.max(200, spawnInterval - 200); // Decrease spawn interval significantly + + // Clear and reset intervals with new values + clearInterval(gameInterval); + gameInterval = setInterval(moveObstacles, obstacleSpeed); // Update movement speed + + clearInterval(obstacleInterval); + obstacleInterval = setInterval(spawnObstacle, spawnInterval); // Update spawn rate + } +} + +// Define controls for player movement +onInput("a", () => { + // Move left + const playerSprite = getFirst(player); + if (playerSprite.x > 0) { + // Leave a black tile behind + addSprite(playerSprite.x, playerSprite.y, blacktile); + playerSprite.x -= 1; + } +}); + +onInput("d", () => { + // Move right + const playerSprite = getFirst(player); + if (playerSprite.x < 4) { + // Leave a black tile behind + addSprite(playerSprite.x, playerSprite.y, blacktile); + playerSprite.x += 1; + } +}); + +// Function to randomly spawn obstacles +function spawnObstacle() { + let xPosition = Math.floor(Math.random() * 5); + addSprite(xPosition, 0, obstacle); +} + +// Function to move obstacles down +function moveObstacles() { + getAll(obstacle).forEach(obs => { + obs.y += 1; + // If an obstacle reaches the bottom, remove it + if (obs.y > 11) { + obs.remove(); + } + // Check if the player gets hit + if (obs.x === getFirst(player).x && obs.y === getFirst(player).y) { + endGame(); + } + }); +} + +// End the game if the player is hit +function endGame() { + clearInterval(gameInterval); + clearInterval(obstacleInterval); + clearInterval(scoreInterval); + addText("Game Over", { y: 6, color: color`3` }); + addText(`Final Score: ${score}`, { y: 8, color: color`3` }); + + // Add retry button + addText(`Retry? Press W`, { x: 3, y: 10, color: color`3` }); + onInput("w", () => { + resetGame(); // Reset game on input + }); +} + +// Set initial intervals to keep spawning obstacles and moving them +let obstacleInterval = setInterval(spawnObstacle, spawnInterval); // Spawn every second +let gameInterval = setInterval(moveObstacles, obstacleSpeed); // Move obstacles initially +let scoreInterval = setInterval(updateScore, 1000); // Update score every second From 5d8790bfdf6a4b9615d5df52ba51f475ef0a4169 Mon Sep 17 00:00:00 2001 From: sirbread Date: Sun, 29 Sep 2024 00:52:00 -0600 Subject: [PATCH 2/2] Add files via upload --- games/img/Not-so_space_invaders.png | Bin 0 -> 5705 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 games/img/Not-so_space_invaders.png diff --git a/games/img/Not-so_space_invaders.png b/games/img/Not-so_space_invaders.png new file mode 100644 index 0000000000000000000000000000000000000000..76ecc57f7321915d5141c5c0ebbb1b74e2092b7f GIT binary patch literal 5705 zcmeAS@N?(olHy`uVBq!ia0y~yV7dXs^EjA*A_5zJD+4LU;vjb?hIQv;UIIBR>5jgR z3=A9lx&I`x0{NT;9+AZi419+{nDKc2iWCM0(R-dQjv*CsZ?75h9rc;mda<5!@}?yx z)skafR5o*(9hK@3@ML|F_P!}J_q*k3e z!M?^knUTS~qxwMAsK97=j3x(cxk0`AZ|wKw`~N;(k+f%5r7yz);iUK1j@l;dl~|t_ zC(Q7n<;L#PLjDN-W2W@bu^d;G)er| z`<8k){@<_v|EE5Z+Yr|iF1~(so}Dy9jq{tGyWlCf`+BJPd|rlqir->l-`w2=tRTc6 zUp@MI)$H?Z4EF`9*Xh9%_oLFQXVaM*@;hw9#jCgLy<>cRw4(Imu2;`CGafKMGH-P^ zJl$8smVUm;@IX50{MDoP)^-Ey8pF8QJ?nP;%whPzyYcxecy7{*3%^@q#_*%RCgk2ER8`cikv{4KD8T_x`9UE$(4hAY8pv@7tYGBL{O>&f!Ce>*a@0 zV)^9JQyDYCU>~Z~b{B_cL4|~z$EA#qH8S(}Hf82FLdsO>q&<&|%Q~2`g z*^O)ubRXI4?S-Z5rNF8~s$qM_{~cdoNq>6WU72i#drJQvUs?^#9Whm<#cLQVx_|V0 zuZQM_&Udb9ul literal 0 HcmV?d00001