Skip to content

Commit

Permalink
Small changes and fixes to Galactic game (#1252)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas <[email protected]>
  • Loading branch information
polypixeldev and LucasHT22 authored Nov 19, 2023
1 parent 8f214ea commit 1f3579f
Showing 1 changed file with 24 additions and 34 deletions.
58 changes: 24 additions & 34 deletions games/galactic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,9 @@ onInput("k", () => {
playTune(buildTune);
} else {
newMap = "how";
if (currentMap == "planet") {
exportedMap = exportMap();
}
}
});

Expand Down Expand Up @@ -1135,20 +1138,6 @@ function refreshMap() {
newMap = null;
setMap(maps[currentMap]);
clearText();

// Load sprites back from map
if (currentMap == "planet" && exportedMap) {
for (let x = 0; x < exportedMap.length; x++) {
const row = exportedMap[x];
for (let y = 0; y < row.length; y++) {
const col = row[y];
clearTile(x, y);
for (let sprite of col) {
addSprite(x, y, sprite.type);
}
}
}
}
} else {
return;
}
Expand All @@ -1160,6 +1149,21 @@ function refreshMap() {
if (currentMap == "wood") displayWood();
if (currentMap == "stone") displayStone();
if (currentMap == "gameover") displayGameover();

// Load sprites back from map
if (currentMap == "planet" && exportedMap) {
for (let x = 0; x < exportedMap.length; x++) {
const row = exportedMap[x];
for (let y = 0; y < row.length; y++) {
const col = row[y];
clearTile(x, y);
for (let sprite of col) {
addSprite(x, y, sprite.type);
}
}
}
exportedMap = null;
}
}

afterInput(() => {
Expand All @@ -1173,12 +1177,8 @@ function checkWood() {
const woodRocket = tilesWith(wood, rocket).length > 0;

if (woodRocket) {
if (Math.random() < 0.3) {
playTune(errTune);
} else {
woodScore++;
playTune(doneTune);
}
woodScore++;
playTune(doneTune);

const rocketSprite = getFirst(rocket);
const x = rocketSprite.x;
Expand All @@ -1201,12 +1201,8 @@ function checkStone() {
const stoneRocket = tilesWith(stone, rocket).length > 0;

if (stoneRocket) {
if (Math.random() < 0.3) {
playTune(errTune);
} else {
stoneScore++;
playTune(doneTune);
}
stoneScore++;
playTune(doneTune);

const rocketSprite = getFirst(rocket);
const x = rocketSprite.x;
Expand Down Expand Up @@ -1375,7 +1371,7 @@ async function displayAnimation() {
if (currentMap != "animation") return;

clearText();
addText("So he set out", {
addText("So she set out", {
x: 3,
y: 5,
color: color`2`,
Expand Down Expand Up @@ -1457,9 +1453,6 @@ function displayWood() {
if (Math.random() < 0.3) {
diff = 2;
}
if (Math.random() < 0.05) {
diff = 3;
}
woodSprite.y += diff;
} else {
woodScore--;
Expand All @@ -1477,7 +1470,7 @@ function displayWood() {
const y = Math.round(Math.random()) + Math.round(Math.random()) + 1;
addSprite(randomX, y, wood);
}
}, 500);
}, 600);

checkWood();
}
Expand All @@ -1504,9 +1497,6 @@ function displayStone() {
if (Math.random() < 0.3) {
diff = 2;
}
if (Math.random() < 0.05) {
diff = 3;
}
stoneSprite.y += diff;
} else {
stoneScore--;
Expand Down

1 comment on commit 1f3579f

@vercel
Copy link

@vercel vercel bot commented on 1f3579f Nov 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sprig – ./

sprig-git-main.hackclub.dev
sprig-beta.hackclub.dev
sprig.hackclub.com
gamelab.hackclub.com

Please sign in to comment.