From 99575a4a440cda3ab1ba6a180118cdb702984eaa Mon Sep 17 00:00:00 2001 From: Aman Sharma Date: Sat, 25 Jan 2025 11:08:56 +0530 Subject: [PATCH 1/2] Sprig App - game1 --- games/game1.js | 173 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 games/game1.js diff --git a/games/game1.js b/games/game1.js new file mode 100644 index 0000000000..31dfdd85c8 --- /dev/null +++ b/games/game1.js @@ -0,0 +1,173 @@ +/* +@title: Push Box Challenge +@tags: ['tutorial'] +@addedOn: 2022-07-26 + +This is a simple tutorial game where you move a box to its goal. +The goal is to push the box to the correct location. +*/ + +// Define the sprites used in the game +const playerSprite = "p"; +const boxSprite = "b"; +const goalSprite = "g"; +const wallSprite = "w"; + +// Assign bitmap art to each sprite +setLegend( + [ playerSprite, bitmap` +................ +................ +................ +.......0........ +.....00.000..... +....0.....00.... +....0.0.0..0.... +....0......0.... +....0......0.... +....00....0..... +......00000..... +......0...0..... +....000...000... +................ +................ +................`], + [ boxSprite, bitmap` +................ +................ +................ +...88888888888.. +...8....8....8.. +...8....8....8.. +...8....8....8.. +...8....8....8.. +...88888888888.. +...8....8....8.. +...8....8....8.. +...8....8....8.. +...8....8....8.. +...88888888888.. +................ +................`], + [ goalSprite, bitmap` +................ +................ +................ +....444444...... +...44....44..... +...4......4..... +...4.......4.... +...4.......4.... +...4.......4.... +...44......4.... +....4......4.... +....44....44.... +.....444444..... +................ +................ +................`], + [ wallSprite, bitmap` +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000`] +); + +// Define the levels for the game +let currentLevelIndex = 0; +const gameLevels = [ + map` +..p. +.b.g +....`, + map` +p.. +.b. +..g`, + map` +p.wg +.bw. +..w. +..w.`, + map` +p... +...b +...b +.bbg`, + map` +... +.p. +...`, + map` +p.w. +.bwg +.... +..bg` +]; + +// Set the initial map to the first level +setMap(gameLevels[currentLevelIndex]); + +// Define solid objects +setSolids([playerSprite, boxSprite, wallSprite]); + +// Configure the player to not push other objects +setPushables({ + [playerSprite]: [] +}); + +// Player movement controls +onInput("w", () => { + getFirst(playerSprite).y -= 1; +}); + +onInput("a", () => { + getFirst(playerSprite).x -= 1; +}); + +onInput("d", () => { + getFirst(playerSprite).x += 1; +}); + +onInput("s", () => { + getFirst(playerSprite).y += 1; +}); + +// Reset level on "j" input +onInput("j", () => { + const levelMap = gameLevels[currentLevelIndex]; + if (levelMap !== undefined) { + clearText(""); + setMap(levelMap); + } +}); + +// After each input, check the game's progress +afterInput(() => { + const totalGoals = tilesWith(goalSprite).length; + const goalsCovered = tilesWith(goalSprite, boxSprite).length; + + // If all goals are covered, move to the next level + if (goalsCovered === totalGoals) { + currentLevelIndex++; + + const nextLevelMap = gameLevels[currentLevelIndex]; + if (nextLevelMap !== undefined) { + setMap(nextLevelMap); + } else { + addText("You win!", { y: 4, color: color`3` }); + } + } +}); From a6a58e2479796d9f689bcfd0cfe5a2bad9b85e95 Mon Sep 17 00:00:00 2001 From: Mare Cosmin <147330889+Cosmin-Mare@users.noreply.github.com> Date: Mon, 27 Jan 2025 17:53:34 +0200 Subject: [PATCH 2/2] Update game1.js --- games/game1.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/games/game1.js b/games/game1.js index 31dfdd85c8..cc9c067eaa 100644 --- a/games/game1.js +++ b/games/game1.js @@ -1,10 +1,8 @@ /* @title: Push Box Challenge -@tags: ['tutorial'] -@addedOn: 2022-07-26 - -This is a simple tutorial game where you move a box to its goal. -The goal is to push the box to the correct location. +@author: 89Aman +@tags: [] +@addedOn: 2025-01-27 */ // Define the sprites used in the game