aboutsummaryrefslogtreecommitdiffstats
path: root/html
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2025-09-04 21:20:17 -0400
committerelioat <elioat@tilde.institute>2025-09-04 21:20:17 -0400
commitb6cbc346a2f9e355df4aad8582209833405e9104 (patch)
treeb0c5b15e2f2bdae0de271222f9b810f4aaafb927 /html
parentc0e3997fae5b50137afd7761cd01ab0e89138788 (diff)
downloadtour-b6cbc346a2f9e355df4aad8582209833405e9104.tar.gz
*
Diffstat (limited to 'html')
-rw-r--r--html/strata/game.js77
1 files changed, 71 insertions, 6 deletions
diff --git a/html/strata/game.js b/html/strata/game.js
index 8c197b9..4b0d767 100644
--- a/html/strata/game.js
+++ b/html/strata/game.js
@@ -100,7 +100,7 @@ const loadPatterns = async () => {
};
});
- image.src = `./png_16x16/pattern_${patternNumber}_16x16.png`;
+ image.src = `./webp_16x16/pattern_${patternNumber}_16x16.webp`;
loadPromises.push(loadPromise);
}
@@ -194,7 +194,8 @@ const CardType = {
HEALTH_DOWN: 'health_down',
CURSE: 'curse',
CLEAR_CURSE: 'clear_curse',
- CLEAR_BUFF: 'clear_buff'
+ CLEAR_BUFF: 'clear_buff',
+ MAGNET: 'magnet'
};
/**
@@ -557,7 +558,7 @@ const generateGrid = () => {
}
// Place random cards with 50% probability per cell (more punishing)
- const cardTypes = [CardType.HEALTH_UP, CardType.HEALTH_DOWN, CardType.CURSE, 'BUFF_HEALTH_PER_LEVEL', 'BUFF_REDUCED_PENALTY', CardType.CLEAR_CURSE, CardType.CLEAR_BUFF];
+ const cardTypes = [CardType.HEALTH_UP, CardType.HEALTH_DOWN, CardType.CURSE, 'BUFF_HEALTH_PER_LEVEL', 'BUFF_REDUCED_PENALTY', CardType.CLEAR_CURSE, CardType.CLEAR_BUFF, CardType.MAGNET];
// First pass: place cards with 50% probability
let gridWithCards = grid.map(cell => {
@@ -587,6 +588,9 @@ const generateGrid = () => {
case CardType.CLEAR_BUFF:
probabilityModifier = 8;
break;
+ case CardType.MAGNET:
+ probabilityModifier = 0; // Magnets don't affect base probability, they override it
+ break;
}
// 10% chance for card to be persistent
@@ -635,6 +639,9 @@ const generateGrid = () => {
case CardType.CLEAR_BUFF:
probabilityModifier = 8;
break;
+ case CardType.MAGNET:
+ probabilityModifier = 0; // Magnets don't affect base probability, they override it
+ break;
}
// 10% chance for card to be persistent
@@ -651,12 +658,63 @@ const generateGrid = () => {
};
/**
+ * Apply magnet effects to row cells
+ * Magnets make the cell to their left have 100% probability, others 0%
+ * If multiple magnets exist, leftmost gets priority
+ */
+const applyMagnetEffects = (rowCells) => {
+ // Find all magnet cards in the row
+ const magnets = rowCells.filter(cell => cell.card && cell.card.type === CardType.MAGNET);
+
+ if (magnets.length === 0) {
+ return rowCells; // No magnets, return unchanged
+ }
+
+ // Sort magnets by column (leftmost first)
+ const sortedMagnets = magnets.sort((a, b) => a.col - b.col);
+
+ // Check if any magnet can have an effect (not at left edge)
+ const validMagnets = sortedMagnets.filter(magnet => magnet.col > 0);
+
+ if (validMagnets.length === 0) {
+ // All magnets are at left edge, so they do nothing
+ return rowCells;
+ }
+
+ // Reset all probabilities to 0
+ let modifiedCells = rowCells.map(cell => ({ ...cell, currentProbability: 0 }));
+
+ // Apply magnet effects (only process valid magnets)
+ for (const magnet of validMagnets) {
+ const targetCol = magnet.col - 1; // Cell to the left
+
+ const targetCellIndex = modifiedCells.findIndex(cell => cell.col === targetCol);
+ if (targetCellIndex !== -1) {
+ // Set target cell to 100% probability
+ modifiedCells[targetCellIndex] = {
+ ...modifiedCells[targetCellIndex],
+ currentProbability: 100
+ };
+
+ // Set all other cells to 0% (they're already 0 from reset above)
+ // This ensures only the leftmost magnet's target gets probability
+ break; // Leftmost magnet takes priority, stop processing others
+ }
+ }
+
+ return modifiedCells;
+};
+
+/**
* Calculate and normalize probabilities for a row
*/
const calculateRowProbabilities = (rowCells, player) => {
// Apply card modifiers with player buffs/curses
let modifiedCells = rowCells.map(cell => applyCardModifier(cell, player));
+ // Apply magnet effects - magnets override all other probability calculations
+ modifiedCells = applyMagnetEffects(modifiedCells);
+
// Normalize to ensure they sum to 100%
modifiedCells = normalizeProbabilities(modifiedCells);
@@ -821,10 +879,15 @@ const processCellLanding = (game, cell) => {
...newPlayer,
buffs: remainingBuffs
};
- addLogEntry('Cleared one buff!', 'clear');
+ addLogEntry('Lost one buff!', 'clear');
}
cardConsumed = !cell.card.persistent;
break;
+ case CardType.MAGNET:
+ // Magnets are passive and never consumed
+ addLogEntry('Magnet field detected', 'move');
+ cardConsumed = false; // Never consume magnets
+ break;
}
}
@@ -1292,6 +1355,7 @@ const getCardColor = (cardType) => {
case 'BUFF_REDUCED_PENALTY': return '#FF9800';
case CardType.CLEAR_CURSE: return '#00BCD4';
case CardType.CLEAR_BUFF: return '#E91E63';
+ case CardType.MAGNET: return '#C0C0C0'; // Shimmery silver
default: return '#666';
}
};
@@ -1571,6 +1635,7 @@ window.debugGame = {
// Make the game object globally accessible for debugging
window.game = null;
window.updateGame = null; // Will be set by init function
+window.calculateRowProbabilities = calculateRowProbabilities; // Expose for testing
// ============================================================================
// INITIALIZATION AND MAIN LOOP
@@ -1670,8 +1735,8 @@ const init = async () => {
if (cellIndex !== -1) {
const cell = game.currentLevel.grid[cellIndex];
- // Check if this cell has a consumable card
- if (cell.card && !cell.card.persistent) {
+ // Check if this cell has a consumable card (but not magnets)
+ if (cell.card && !cell.card.persistent && cell.card.type !== CardType.MAGNET) {
// Remove the card from the grid
game.currentLevel.grid[cellIndex] = { ...cell, card: null };