Skip to content

Commit

Permalink
add new score system & adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Yrahcaz7 committed Feb 10, 2024
1 parent 9013126 commit a8d407b
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 59 deletions.
Binary file modified images/title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions js/enemies.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@

const SLIME = {BIG: 600, SMALL: 601, PRIME: 602}, FRAGMENT = 603;

const ENEMY_NAMES = {
[SLIME.BIG]: "big slime",
[SLIME.SMALL]: "small slime",
[SLIME.PRIME]: "prime slime",
[FRAGMENT]: "fragment of time",
};

const ENEMY_WORTH = {
[SLIME.BIG]: 100,
[SLIME.SMALL]: 50,
[SLIME.PRIME]: 500,
[FRAGMENT]: 1000,
};

const ATTACK = 700, DEFEND = 701, BUFF = 702;

const INTENT = {[ATTACK]: "<#f44>attack</#f44> you", [DEFEND]: "<#58f>defend</#58f> itself", [BUFF]: "buff itself"};
Expand Down
25 changes: 16 additions & 9 deletions js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ String.prototype.randomize = function() {
return arr.join("");
};

/**
* Returns the value of an interval at the current time.
* @param {number} period - the period of the interval function.
* @param {number} mag - the magnitude of the interval. Defaults to `1`.
*/
function interval(period, mag = 1) {
return (Math.abs((new Date().getTime() % (2000 * period * mag) / (1000 * period)) - mag) * mag) - mag;
};

/**
* Returns a boolean indicating whether the middleground layers are hidden.
*/
Expand Down Expand Up @@ -138,6 +129,22 @@ const get = {
if (game.artifacts.includes(2)) extra += 2;
return extra;
},
/**
* Gets the score factors.
*/
scoreFactors() {
let factors = [];
for (const key in game.kills) {
if (Object.hasOwnProperty.call(game.kills, key)) {
const amt = game.kills[+key];
if (+key === FRAGMENT) factors.push(["killed the " + ENEMY_NAMES[+key], amt * ENEMY_WORTH[+key]]);
else factors.push(["killed " + amt + " " + ENEMY_NAMES[+key] + (amt > 1 ? "s" : ""), amt * ENEMY_WORTH[+key]]);
};
};
factors.push(["saved " + game.gold + " gold", Math.floor(game.gold / 5)]);
if (game.health > 0) factors.push(["saved " + game.health + " health", game.health * 5]);
return factors;
},
};

/**
Expand Down
137 changes: 105 additions & 32 deletions js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ let global = {
map: [],
traveled: [],
seed: "" + (Math.round(new Date().getTime() * (Math.random() + 0.001)) % 1000000).toString().randomize(),
}, actionTimer = -1, notif = [-1, 0, "", 0], menuLocation = MENU.TITLE, menuSelect = 0, enemyPos = [], handPos = [], paths = {}, gameWon = false;
}, actionTimer = -1, notif = [-1, 0, "", 0], menuLocation = MENU.TITLE, menuSelect = 0, enemyPos = [], handPos = [], paths = {}, winAnim = 0;

/**
* Pushes a popup.
Expand Down Expand Up @@ -329,7 +329,7 @@ function selection() {
return;
};
// game end
if (game.select[0] === GAME_OVER && game.select[1] == 204) {
if ((game.select[0] === GAME_OVER || game.select[0] === GAME_FIN) && game.select[1] == 50) {
if (action === ENTER) {
restartRun();
actionTimer = 2;
Expand Down Expand Up @@ -1183,40 +1183,113 @@ function updateVisuals() {
};
graphics.popups();
if (game.select[0] === GAME_OVER) {
if (game.select[1] > 204) game.select[1] = 204;
const num = Math.floor(game.select[1]).toString(16);
draw.rect("#000000" + (num.length < 2 ? "0" : "") + num);
if (game.select[1] < 204) {
game.select[1] += 10;
ctx.globalAlpha = game.select[1] / 64;
if (game.select[1] < 50) game.select[1]++;
draw.rect("#000");
const factors = get.scoreFactors();
let text = "GAME OVER\n\nDIFFICULTY: ";
if (game.artifacts.includes(0)) text += "<#fcf050>DETERMINATION</#fcf050>";
else if (game.difficulty) text += "HARD";
else text += "EASY";
text += "\n\nTOP FLOOR: " + game.floor;
let len = factors.length;
if (game.difficulty) len += 4;
draw.lore(200 - 2, 100 - (len + 17) * 2.75, text, {"color": "#f00", "text-align": CENTER});
draw.lore(200 - 2, 100 + (len + 15) * 2.75, "PRESS ENTER TO START A NEW RUN", {"color": "#f00", "text-align": CENTER});
text = "";
for (let index = 0; index < factors.length; index++) {
text += factors[index][0] + ":\n";
};
if (game.difficulty) {
if (game.artifacts.includes(0) && game.kills[FRAGMENT]) text += "\nbase score:\n\n<#fcf050>DETERMINATION</#fcf050> bonus:\n\ntotal score:";
else text += "\nbase score:\n\n<#0f0>hard difficulty bonus:</#0f0>\n\ntotal score:";
} else {
text += "\ntotal score:";
};
draw.lore(125, 100 - (len - 7) * 2.75, text, {"color": "#f00", "text-small": true});
text = "";
let totalScore = 0;
for (let index = 0; index < factors.length; index++) {
if (factors[index][1] == 1) {
text += "1 point\n";
totalScore++;
} else {
text += factors[index][1] + " points\n";
totalScore += factors[index][1];
};
};
if (game.difficulty) {
text += "\n" + totalScore + " points";
if (game.artifacts.includes(0) && game.kills[FRAGMENT]) {
totalScore *= 3;
text += "\n\n<#fcf050>3x multiplier</#fcf050>";
} else {
totalScore *= 2;
text += "\n\n<#0f0>2x multiplier</#0f0>";
};
text += "\n\n" + totalScore + " points";
} else {
if (game.artifacts.includes(0)) draw.lore(200 - 2, 53, "GAME OVER\n\nDIFFICULTY: <#fcf050>DETERMINATION</#fcf050>\n\nTOP FLOOR: " + game.floor + "\n\nPRESS ENTER TO START A NEW RUN", {"color": "#f00", "text-align": CENTER});
else draw.lore(200 - 2, 53, "GAME OVER\n\nDIFFICULTY: " + (game.difficulty ? "HARD" : "EASY") + "\n\nTOP FLOOR: " + game.floor + "\n\nPRESS ENTER TO START A NEW RUN", {"color": "#f00", "text-align": CENTER});
text += "\n" + totalScore + " points";
};
draw.lore(275, 100 - (len - 7) * 2.75, text, {"color": "#f00", "text-align": LEFT, "text-small": true});
ctx.globalAlpha = 1;
} else if (game.select[0] === GAME_FIN) {
if (game.select[1] > 255) game.select[1] = 255;
const num = Math.floor(game.select[1]).toString(16);
draw.rect("#000000" + (num.length < 2 ? "0" : "") + num);
if (game.select[1] < 255) game.select[1] += 10;
else {
save();
loaded = false;
game.select = [GAME_WON, 0];
actionTimer = 4;
gameWon = true;
setInterval(() => {
clearCanvas();
let num = Math.round(interval(4/3, 2));
draw.image(victorious, 168, 42 + num, victorious.width * 2, victorious.height * 2);
draw.rect("#0004");
if (game.artifacts.includes(0)) draw.lore(200 - 2, 50, "YOU BEAT THE GAME <#fcf050>WITH DETERMINATION</#fcf050>\n\nThank you for playing!\n\nMore content coming soon, such as:<s>\n- More cards!\n- More enemies!\n- A new area!\n- And much more!<b>\n\nPRESS ENTER TO START A NEW RUN", {"color": "#0f0", "text-align": CENTER});
else draw.lore(200 - 2, 50, "YOU BEAT THE GAME ON " + (game.difficulty ? "<#f00>HARD MODE!</#f00>" : "EASY MODE!") + "\n\nThank you for playing!\n\nMore content coming soon, such as:<s>\n- More cards!\n- More enemies!\n- A new area!\n- And much more!<b>\n\nPRESS ENTER TO START A NEW RUN", {"color": "#0f0", "text-align": CENTER});
if (actionTimer <= -1) {
if (action === ENTER) restartRun();
} else actionTimer -= 0.1;
}, 10);
if (game.select[1] < 50) {
ctx.globalAlpha = game.select[1] / 50;
game.select[1]++;
};
draw.rect("#000");
draw.image(victorious, 168, 42 + Math.round(Math.abs(winAnim - 4) - 2), victorious.width * 2, victorious.height * 2);
winAnim += Math.random() * 0.05 + 0.05;
if (winAnim >= 8) winAnim -= 8;
draw.rect("#0004");
const factors = get.scoreFactors();
let text = "YOU BEAT THE GAME ";
if (game.artifacts.includes(0)) text += "<#fcf050>WITH DETERMINATION</#fcf050>";
else if (game.difficulty) text += "ON <#f00>HARD MODE!</#f00>";
else text += "ON EASY MODE!";
text += "\n\nThank you for playing!\n\nMore content is coming soon!";
let len = factors.length;
if (game.difficulty) len += 4;
draw.lore(200 - 2, 100 - (len + 17) * 2.75, text, {"color": "#0f0", "text-align": CENTER});
draw.lore(200 - 2, 100 + (len + 15) * 2.75, "PRESS ENTER TO START A NEW RUN", {"color": "#0f0", "text-align": CENTER});
text = "";
for (let index = 0; index < factors.length; index++) {
text += factors[index][0] + ":\n";
};
if (game.difficulty) {
if (game.artifacts.includes(0)) text += "\nbase score:\n\n<#fcf050>DETERMINATION</#fcf050> bonus:\n\ntotal score:";
else text += "\nbase score:\n\n<#f00>hard difficulty bonus:</#f00>\n\ntotal score:";
} else {
text += "\ntotal score:";
};
draw.lore(125, 100 - (len - 7) * 2.75, text, {"color": "#0f0", "text-small": true});
text = "";
let totalScore = 0;
for (let index = 0; index < factors.length; index++) {
if (factors[index][1] == 1) {
text += "1 point\n";
totalScore++;
} else {
text += factors[index][1] + " points\n";
totalScore += factors[index][1];
};
};
if (game.difficulty) {
text += "\n" + totalScore + " points";
if (game.artifacts.includes(0)) {
totalScore *= 3;
text += "\n\n<#fcf050>3x multiplier</#fcf050>";
} else {
totalScore *= 2;
text += "\n\n<#f00>2x multiplier</#f00>";
};
text += "\n\n" + totalScore + " points";
} else {
text += "\n" + totalScore + " points";
};
} else if (game.select[0] === GAME_WON && !gameWon) {
game.select = [GAME_FIN, 0];
draw.lore(275, 100 - (len - 7) * 2.75, text, {"color": "#0f0", "text-align": LEFT, "text-small": true});
ctx.globalAlpha = 1;
};
if (game.artifacts.includes(0) && game.floor == 10 && transition < 100) transition++;
};
Expand Down
29 changes: 13 additions & 16 deletions js/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const draw = {
};
return space;
};
// print multi-line right aligned text
// print special multi-line text
if (str.includes("\n") && position !== RIGHT) {
let array = str.split("\n");
let space = 0;
Expand Down Expand Up @@ -196,7 +196,7 @@ const draw = {
"text-small": small,
});
} else if (position === LEFT) {
draw.char(char, x + (((a - enterIndex) - len + 1) * (small ? 3 : 6)), y + (enters * (small ? 5.5 : 11)), {
draw.char(char, x + (((a - enterIndex) - len) * (small ? 3 : 6)), y + (enters * (small ? 5.5 : 11)), {
"color": color,
"highlight-color": highlight,
"text-small": small,
Expand Down Expand Up @@ -296,7 +296,7 @@ const draw = {
};
draw.imageSector(bar.health_full, 0, 0, cutoff + 1, 12, x, y + 65);
draw.imageSector(bar.health_empty, cutoff + 1, 0, 64 - (cutoff + 1), 12, x + (cutoff + 1), y + 65);
draw.lore(x + 25, y + 67, health, {"text-align": LEFT});
draw.lore(x + 31, y + 67, health, {"text-align": LEFT});
draw.lore(x + 34, y + 67, maxHealth);
if (!shield || !maxShield) return;
percentage = shield / maxShield;
Expand All @@ -308,7 +308,7 @@ const draw = {
};
draw.imageSector(bar.shield_full, 0, 0, cutoff + 1, 12, x, y + 76);
draw.imageSector(bar.shield_empty, cutoff + 1, 0, 64 - (cutoff + 1), 12, x + (cutoff + 1), y + 76);
draw.lore(x + 25, y + 78, shield, {"text-align": LEFT});
draw.lore(x + 31, y + 78, shield, {"text-align": LEFT});
draw.lore(x + 34, y + 78, maxShield);
},
/**
Expand Down Expand Up @@ -702,10 +702,10 @@ const graphics = {
let img = icon[key.endsWith("s") && !key.endsWith("ss") ? key.slice(0, -1) : key];
if (game.shield) {
draw.image(img, x + 23, y + 104);
draw.lore(x + 34, y + 112, game.eff[key], {"color": "#fff", "text-align": LEFT});
draw.lore(x + 40, y + 112, game.eff[key], {"color": "#fff", "text-align": LEFT});
} else {
draw.image(img, x + 23, y + 93);
draw.lore(x + 34, y + 101, game.eff[key], {"color": "#fff", "text-align": LEFT});
draw.lore(x + 40, y + 101, game.eff[key], {"color": "#fff", "text-align": LEFT});
};
x += 17;
};
Expand Down Expand Up @@ -747,7 +747,7 @@ const graphics = {
};
draw.imageSector(bar.energy_full, 0, 0, cutoff + 1, 32, x, y + 16);
draw.imageSector(bar.energy_empty, cutoff + 1, 0, 32 - (cutoff + 1), 32, x + (cutoff + 1), y + 16);
draw.lore(x + 9, y + 28, energy, {"text-align": LEFT});
draw.lore(x + 15, y + 28, energy, {"text-align": LEFT});
draw.lore(x + 18, y + 28, get.maxEnergy());
},
/**
Expand Down Expand Up @@ -778,10 +778,10 @@ const graphics = {
if (select.eff[key]) {
if (select.shield) {
draw.image(img, x, y + 89);
draw.lore(x + 11, y + 97, select.eff[key], {"color": "#fff", "text-align": LEFT});
draw.lore(x + 17, y + 97, select.eff[key], {"color": "#fff", "text-align": LEFT});
} else {
draw.image(img, x, y + 78);
draw.lore(x + 11, y + 86, select.eff[key], {"color": "#fff", "text-align": LEFT});
draw.lore(x + 17, y + 86, select.eff[key], {"color": "#fff", "text-align": LEFT});
};
x += 17;
};
Expand Down Expand Up @@ -1007,7 +1007,7 @@ const graphics = {
};
draw.lore(1, 12 - infPos, 'Source can be found at "https://github.com/Yrahcaz7/Dungeon-of-Souls"', {"color": "#f44", "text-small": true});
if (infLimit > 0) {
draw.lore(360, 26, "Scrollable", {"color": "#fff", "text-align": LEFT});
draw.lore(360, 32, "Scrollable", {"color": "#fff", "text-align": LEFT});
draw.image(arrows, 367, 22);
};
},
Expand Down Expand Up @@ -1125,19 +1125,16 @@ const graphics = {
const enemy = game.enemies[game.select[1]];
const enemyType = enemy.type;
const pos = enemyPos[game.select[1]];
let coords = [], name = "";
let coords = [], name = ENEMY_NAMES[enemyType];
if (enemyType === SLIME.SMALL) {
coords = [19, 36, 26, 28];
name = "small slime";
} else if (enemyType === SLIME.BIG || (enemyType === SLIME.PRIME && primeAnim != -1 && primeAnim < 5)) {
coords = [5, 26, 54, 38];
name = "big slime";
} else if (enemyType === SLIME.PRIME) {
coords = [0, 7, 64, 57];
name = "prime slime";
} else if (enemyType === FRAGMENT && (primeAnim == -1 || primeAnim > 18)) {
coords = [7, 6, 50, 58];
name = "fragment of time";
};
if (coords) {
if (game.select[1] !== game.enemyNum) info.intent();
Expand All @@ -1146,7 +1143,7 @@ const graphics = {
draw.lore(pos[0] + 31, pos[1] + coords[1] - 7.5, name, {"color": "#fff", "text-align": CENTER, "text-small": true});
const exAtt = enemy.getExtraAttackPower();
const exDef = enemy.getExtraDefendPower();
if (left) draw.lore(pos[0] + coords[0] - 5.5, pos[1] + coords[1] - 2, "ATK: " + enemy.attackPower + (exAtt ? "+" + exAtt : "") + "\nDEF: " + enemy.defendPower + (exDef ? "+" + exDef : ""), {"color": "#fff", "text-align": LEFT, "text-small": true});
if (left) draw.lore(pos[0] + coords[0] - 2.5, pos[1] + coords[1] - 2, "ATK: " + enemy.attackPower + (exAtt ? "+" + exAtt : "") + "\nDEF: " + enemy.defendPower + (exDef ? "+" + exDef : ""), {"color": "#fff", "text-align": LEFT, "text-small": true});
else draw.lore(pos[0] + coords[0] + coords[2] + 3, pos[1] + coords[1] - 2, "ATK: " + enemy.attackPower + (exAtt ? "+" + exAtt : "") + "\nDEF: " + enemy.defendPower + (exDef ? "+" + exDef : ""), {"color": "#fff", "text-small": true});
let x = coords[0] - 5.5, y = coords[1] - 1;
for (const key in game.enemies[game.select[1]].eff) {
Expand Down Expand Up @@ -1366,7 +1363,7 @@ const graphics = {
draw.image(extra.end, 22, 179);
if (game.mapSelect == -1) draw.image(select.round, 21, 178);
draw.lore(1, 1, "floor " + game.floor + " - " + game.gold + " gold", {"color": "#f44"});
draw.lore(393, 1, "seed: " + game.seed, {"color": "#fff", "text-align": LEFT});
draw.lore(399, 1, "seed: " + game.seed, {"color": "#fff", "text-align": LEFT});
};
// calculate nodes
let store = [];
Expand Down
3 changes: 1 addition & 2 deletions js/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ function fixSelect(item) {
else if (item == "confirm_exit") return CONFIRM_EXIT;
else if (item == "options") return OPTIONS;
else if (item == "game_over") return GAME_OVER;
else if (item == "game_fin") return GAME_FIN;
else if (item == "game_won") return GAME_WON;
else if (item == "game_fin" || item == "game_won" || item == GAME_WON) return GAME_FIN;
else if (item == "confirm_restart") return CONFIRM_RESTART;
else if (item == "welcome") return WELCOME;
else return -1;
Expand Down

0 comments on commit a8d407b

Please sign in to comment.