Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small changes and fixes to Galactic game #1252

Merged
merged 2 commits into from
Nov 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading