Spaces:
Running
Running
fix the time dynamics
Browse files
script.js
CHANGED
|
@@ -26,9 +26,11 @@ class WormateGame {
|
|
| 26 |
this.foods = [];
|
| 27 |
this.powerUps = [];
|
| 28 |
this.score = 0;
|
| 29 |
-
this.timeLeft =
|
| 30 |
-
this.maxTime =
|
| 31 |
-
this.
|
|
|
|
|
|
|
| 32 |
this.keys = {
|
| 33 |
ArrowUp: false,
|
| 34 |
ArrowDown: false,
|
|
@@ -93,15 +95,16 @@ this.keys = {
|
|
| 93 |
{ type: 'chocolate', radius: 14, color: '#7B3F00', time: 10, rarity: 0.1 },
|
| 94 |
{ type: 'marshmallow', radius: 9, color: '#FFFFFF', time: 5, rarity: 0.2 }
|
| 95 |
];
|
| 96 |
-
const randomFood = foodTypes[Math.floor(Math.random() * foodTypes.length)];
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
| 105 |
}
|
| 106 |
this.gameStarted = true;
|
| 107 |
this.playBtn.style.display = 'none';
|
|
@@ -117,18 +120,33 @@ const randomFood = foodTypes[Math.floor(Math.random() * foodTypes.length)];
|
|
| 117 |
}
|
| 118 |
requestAnimationFrame(() => this.gameLoop());
|
| 119 |
}
|
| 120 |
-
|
| 121 |
startTimer() {
|
| 122 |
clearInterval(this.gameTimer);
|
|
|
|
|
|
|
| 123 |
this.gameTimer = setInterval(() => {
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
if (this.timeLeft <= 0) {
|
| 127 |
this.gameOver();
|
| 128 |
}
|
| 129 |
-
|
|
|
|
| 130 |
if (this.timeLeft <= 10) {
|
| 131 |
this.timeDisplay.classList.add('warning');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
} else {
|
| 133 |
this.timeDisplay.classList.remove('warning');
|
| 134 |
}
|
|
@@ -175,9 +193,13 @@ update() {
|
|
| 175 |
radius: tail.radius * 0.95
|
| 176 |
});
|
| 177 |
}
|
| 178 |
-
// Add time for eating food
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
this.score = player.score;
|
| 182 |
this.scoreDisplay.textContent = `Score: ${this.score}`;
|
| 183 |
this.timeDisplay.textContent = `Time: ${this.timeLeft}s`;
|
|
|
|
| 26 |
this.foods = [];
|
| 27 |
this.powerUps = [];
|
| 28 |
this.score = 0;
|
| 29 |
+
this.timeLeft = 60; // Starting time (seconds)
|
| 30 |
+
this.maxTime = 120; // Maximum time bank
|
| 31 |
+
this.timeDecayRate = 1.0; // Base decay rate (seconds per second)
|
| 32 |
+
this.timeDecayMultiplier = 0.01; // Increases as worm grows
|
| 33 |
+
this.gameTimer = null;
|
| 34 |
this.keys = {
|
| 35 |
ArrowUp: false,
|
| 36 |
ArrowDown: false,
|
|
|
|
| 95 |
{ type: 'chocolate', radius: 14, color: '#7B3F00', time: 10, rarity: 0.1 },
|
| 96 |
{ type: 'marshmallow', radius: 9, color: '#FFFFFF', time: 5, rarity: 0.2 }
|
| 97 |
];
|
| 98 |
+
const randomFood = foodTypes[Math.floor(Math.random() * foodTypes.length)];
|
| 99 |
+
this.foods.push({
|
| 100 |
+
x: Math.random() * this.canvas.width,
|
| 101 |
+
y: Math.random() * this.canvas.height,
|
| 102 |
+
radius: randomFood.radius,
|
| 103 |
+
color: randomFood.color,
|
| 104 |
+
type: randomFood.type,
|
| 105 |
+
points: randomFood.points,
|
| 106 |
+
time: Math.max(1, 5 - (this.players[this.playerId]?.segments.length * 0.05))
|
| 107 |
+
});
|
| 108 |
}
|
| 109 |
this.gameStarted = true;
|
| 110 |
this.playBtn.style.display = 'none';
|
|
|
|
| 120 |
}
|
| 121 |
requestAnimationFrame(() => this.gameLoop());
|
| 122 |
}
|
|
|
|
| 123 |
startTimer() {
|
| 124 |
clearInterval(this.gameTimer);
|
| 125 |
+
let lastTime = Date.now();
|
| 126 |
+
|
| 127 |
this.gameTimer = setInterval(() => {
|
| 128 |
+
const now = Date.now();
|
| 129 |
+
const delta = (now - lastTime) / 1000; // Convert to seconds
|
| 130 |
+
lastTime = now;
|
| 131 |
+
|
| 132 |
+
// Calculate time decay based on worm size
|
| 133 |
+
const decayRate = this.timeDecayRate +
|
| 134 |
+
(this.timeDecayMultiplier * this.players[this.playerId]?.segments.length || 0);
|
| 135 |
+
|
| 136 |
+
this.timeLeft = Math.max(0, this.timeLeft - (decayRate * delta));
|
| 137 |
+
this.timeDisplay.textContent = `Time: ${Math.floor(this.timeLeft)}s`;
|
| 138 |
+
|
| 139 |
if (this.timeLeft <= 0) {
|
| 140 |
this.gameOver();
|
| 141 |
}
|
| 142 |
+
|
| 143 |
+
// Visual feedback for time status
|
| 144 |
if (this.timeLeft <= 10) {
|
| 145 |
this.timeDisplay.classList.add('warning');
|
| 146 |
+
this.timeDisplay.style.animationDuration = `${0.5 / (11 - this.timeLeft)}s`;
|
| 147 |
+
} else if (this.timeLeft <= 30) {
|
| 148 |
+
this.timeDisplay.classList.add('warning');
|
| 149 |
+
this.timeDisplay.style.animationDuration = '1s';
|
| 150 |
} else {
|
| 151 |
this.timeDisplay.classList.remove('warning');
|
| 152 |
}
|
|
|
|
| 193 |
radius: tail.radius * 0.95
|
| 194 |
});
|
| 195 |
}
|
| 196 |
+
// Add time for eating food with diminishing returns based on worm size
|
| 197 |
+
const timeGain = Math.max(1, food.time - (player.segments.length * 0.1));
|
| 198 |
+
this.timeLeft = Math.min(this.maxTime, this.timeLeft + timeGain);
|
| 199 |
+
|
| 200 |
+
// Increase time decay as worm grows (harder to maintain)
|
| 201 |
+
this.timeDecayMultiplier = 0.01 + (player.segments.length * 0.0005);
|
| 202 |
+
player.score += 1;
|
| 203 |
this.score = player.score;
|
| 204 |
this.scoreDisplay.textContent = `Score: ${this.score}`;
|
| 205 |
this.timeDisplay.textContent = `Time: ${this.timeLeft}s`;
|
style.css
CHANGED
|
@@ -243,10 +243,24 @@ body {
|
|
| 243 |
|
| 244 |
/* Animations */
|
| 245 |
@keyframes pulse {
|
| 246 |
-
0% {
|
| 247 |
-
|
| 248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
}
|
| 250 |
-
.
|
|
|
|
| 251 |
animation: pulse 1s infinite;
|
| 252 |
-
}
|
|
|
|
| 243 |
|
| 244 |
/* Animations */
|
| 245 |
@keyframes pulse {
|
| 246 |
+
0% {
|
| 247 |
+
transform: scale(1);
|
| 248 |
+
text-shadow: 0 0 5px rgba(255, 0, 0, 0.5);
|
| 249 |
+
}
|
| 250 |
+
50% {
|
| 251 |
+
transform: scale(1.2);
|
| 252 |
+
text-shadow: 0 0 15px rgba(255, 0, 0, 0.8);
|
| 253 |
+
}
|
| 254 |
+
100% {
|
| 255 |
+
transform: scale(1);
|
| 256 |
+
text-shadow: 0 0 5px rgba(255, 0, 0, 0.5);
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
.time-critical {
|
| 260 |
+
color: #ff0000 !important;
|
| 261 |
+
animation: pulse 0.5s infinite;
|
| 262 |
}
|
| 263 |
+
.time-warning {
|
| 264 |
+
color: #ff6b6b;
|
| 265 |
animation: pulse 1s infinite;
|
| 266 |
+
}
|