Spaces:
Running
Running
instead of balls create diffrent food treats like lolly pops, bears - mixbag style assortments with different points
Browse files
script.js
CHANGED
|
@@ -82,13 +82,23 @@ class WormateGame {
|
|
| 82 |
|
| 83 |
// Generate initial food
|
| 84 |
for (let i = 0; i < 50; i++) {
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
}
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
this.gameStarted = true;
|
| 94 |
this.playBtn.style.display = 'none';
|
|
@@ -144,8 +154,8 @@ class WormateGame {
|
|
| 144 |
radius: tail.radius * 0.95
|
| 145 |
});
|
| 146 |
}
|
| 147 |
-
player.score +=
|
| 148 |
-
|
| 149 |
this.scoreDisplay.textContent = `Score: ${this.score}`;
|
| 150 |
return false; // Remove food
|
| 151 |
}
|
|
@@ -154,15 +164,24 @@ class WormateGame {
|
|
| 154 |
|
| 155 |
// Add new food if needed
|
| 156 |
if (this.foods.length < 30 && Math.random() < 0.1) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
this.foods.push({
|
| 158 |
x: Math.random() * this.canvas.width,
|
| 159 |
y: Math.random() * this.canvas.height,
|
| 160 |
-
radius:
|
| 161 |
-
color:
|
|
|
|
|
|
|
| 162 |
});
|
| 163 |
}
|
| 164 |
-
|
| 165 |
-
// Check wall collision
|
| 166 |
if (
|
| 167 |
head.x < -head.radius ||
|
| 168 |
head.x > this.canvas.width + head.radius ||
|
|
@@ -183,13 +202,76 @@ class WormateGame {
|
|
| 183 |
|
| 184 |
// Draw foods
|
| 185 |
this.foods.forEach(food => {
|
| 186 |
-
this.ctx.
|
| 187 |
-
this.ctx.
|
| 188 |
-
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
});
|
| 191 |
-
|
| 192 |
-
// Draw players
|
| 193 |
Object.values(this.players).forEach(player => {
|
| 194 |
// Draw worm segments
|
| 195 |
player.segments.forEach((segment, i) => {
|
|
|
|
| 82 |
|
| 83 |
// Generate initial food
|
| 84 |
for (let i = 0; i < 50; i++) {
|
| 85 |
+
const foodTypes = [
|
| 86 |
+
{ type: 'lollipop', radius: 12, color: '#FF5252', points: 10 },
|
| 87 |
+
{ type: 'gummybear', radius: 10, color: '#FF4081', points: 5 },
|
| 88 |
+
{ type: 'candycorn', radius: 8, color: '#FFD740', points: 3 },
|
| 89 |
+
{ type: 'chocolate', radius: 14, color: '#7B3F00', points: 15 },
|
| 90 |
+
{ type: 'marshmallow', radius: 9, color: '#FFFFFF', points: 8 }
|
| 91 |
+
];
|
| 92 |
+
const randomFood = foodTypes[Math.floor(Math.random() * foodTypes.length)];
|
| 93 |
+
this.foods.push({
|
| 94 |
+
x: Math.random() * this.canvas.width,
|
| 95 |
+
y: Math.random() * this.canvas.height,
|
| 96 |
+
radius: randomFood.radius,
|
| 97 |
+
color: randomFood.color,
|
| 98 |
+
type: randomFood.type,
|
| 99 |
+
points: randomFood.points
|
| 100 |
+
});
|
| 101 |
+
}
|
| 102 |
|
| 103 |
this.gameStarted = true;
|
| 104 |
this.playBtn.style.display = 'none';
|
|
|
|
| 154 |
radius: tail.radius * 0.95
|
| 155 |
});
|
| 156 |
}
|
| 157 |
+
player.score += food.points;
|
| 158 |
+
this.score = player.score;
|
| 159 |
this.scoreDisplay.textContent = `Score: ${this.score}`;
|
| 160 |
return false; // Remove food
|
| 161 |
}
|
|
|
|
| 164 |
|
| 165 |
// Add new food if needed
|
| 166 |
if (this.foods.length < 30 && Math.random() < 0.1) {
|
| 167 |
+
const foodTypes = [
|
| 168 |
+
{ type: 'lollipop', radius: 12, color: '#FF5252', points: 10 },
|
| 169 |
+
{ type: 'gummybear', radius: 10, color: '#FF4081', points: 5 },
|
| 170 |
+
{ type: 'candycorn', radius: 8, color: '#FFD740', points: 3 },
|
| 171 |
+
{ type: 'chocolate', radius: 14, color: '#7B3F00', points: 15 },
|
| 172 |
+
{ type: 'marshmallow', radius: 9, color: '#FFFFFF', points: 8 }
|
| 173 |
+
];
|
| 174 |
+
const randomFood = foodTypes[Math.floor(Math.random() * foodTypes.length)];
|
| 175 |
this.foods.push({
|
| 176 |
x: Math.random() * this.canvas.width,
|
| 177 |
y: Math.random() * this.canvas.height,
|
| 178 |
+
radius: randomFood.radius,
|
| 179 |
+
color: randomFood.color,
|
| 180 |
+
type: randomFood.type,
|
| 181 |
+
points: randomFood.points
|
| 182 |
});
|
| 183 |
}
|
| 184 |
+
// Check wall collision
|
|
|
|
| 185 |
if (
|
| 186 |
head.x < -head.radius ||
|
| 187 |
head.x > this.canvas.width + head.radius ||
|
|
|
|
| 202 |
|
| 203 |
// Draw foods
|
| 204 |
this.foods.forEach(food => {
|
| 205 |
+
this.ctx.save();
|
| 206 |
+
this.ctx.translate(food.x, food.y);
|
| 207 |
+
|
| 208 |
+
switch(food.type) {
|
| 209 |
+
case 'lollipop':
|
| 210 |
+
// Lollipop head
|
| 211 |
+
this.ctx.fillStyle = food.color;
|
| 212 |
+
this.ctx.beginPath();
|
| 213 |
+
this.ctx.arc(0, 0, food.radius, 0, Math.PI * 2);
|
| 214 |
+
this.ctx.fill();
|
| 215 |
+
|
| 216 |
+
// Lollipop stick
|
| 217 |
+
this.ctx.strokeStyle = '#FFFFFF';
|
| 218 |
+
this.ctx.lineWidth = 2;
|
| 219 |
+
this.ctx.beginPath();
|
| 220 |
+
this.ctx.moveTo(0, food.radius);
|
| 221 |
+
this.ctx.lineTo(0, food.radius * 2);
|
| 222 |
+
this.ctx.stroke();
|
| 223 |
+
break;
|
| 224 |
+
|
| 225 |
+
case 'gummybear':
|
| 226 |
+
// Gummy bear body
|
| 227 |
+
this.ctx.fillStyle = food.color;
|
| 228 |
+
this.ctx.beginPath();
|
| 229 |
+
this.ctx.ellipse(0, 0, food.radius, food.radius * 1.2, 0, 0, Math.PI * 2);
|
| 230 |
+
this.ctx.fill();
|
| 231 |
+
|
| 232 |
+
// Eyes
|
| 233 |
+
this.ctx.fillStyle = '#000000';
|
| 234 |
+
this.ctx.beginPath();
|
| 235 |
+
this.ctx.arc(-food.radius/3, -food.radius/3, 2, 0, Math.PI * 2);
|
| 236 |
+
this.ctx.arc(food.radius/3, -food.radius/3, 2, 0, Math.PI * 2);
|
| 237 |
+
this.ctx.fill();
|
| 238 |
+
break;
|
| 239 |
+
|
| 240 |
+
case 'candycorn':
|
| 241 |
+
// Candy corn triangle
|
| 242 |
+
this.ctx.fillStyle = food.color;
|
| 243 |
+
this.ctx.beginPath();
|
| 244 |
+
this.ctx.moveTo(0, -food.radius);
|
| 245 |
+
this.ctx.lineTo(-food.radius, food.radius);
|
| 246 |
+
this.ctx.lineTo(food.radius, food.radius);
|
| 247 |
+
this.ctx.closePath();
|
| 248 |
+
this.ctx.fill();
|
| 249 |
+
break;
|
| 250 |
+
|
| 251 |
+
case 'chocolate':
|
| 252 |
+
// Chocolate bar
|
| 253 |
+
this.ctx.fillStyle = food.color;
|
| 254 |
+
this.ctx.fillRect(-food.radius, -food.radius/2, food.radius*2, food.radius);
|
| 255 |
+
break;
|
| 256 |
+
|
| 257 |
+
case 'marshmallow':
|
| 258 |
+
// Marshmallow
|
| 259 |
+
this.ctx.fillStyle = food.color;
|
| 260 |
+
this.ctx.beginPath();
|
| 261 |
+
this.ctx.arc(0, 0, food.radius, 0, Math.PI * 2);
|
| 262 |
+
this.ctx.fill();
|
| 263 |
+
|
| 264 |
+
// Shading
|
| 265 |
+
this.ctx.fillStyle = 'rgba(0,0,0,0.1)';
|
| 266 |
+
this.ctx.beginPath();
|
| 267 |
+
this.ctx.arc(0, -food.radius/3, food.radius/3, 0, Math.PI * 2);
|
| 268 |
+
this.ctx.fill();
|
| 269 |
+
break;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
this.ctx.restore();
|
| 273 |
});
|
| 274 |
+
// Draw players
|
|
|
|
| 275 |
Object.values(this.players).forEach(player => {
|
| 276 |
// Draw worm segments
|
| 277 |
player.segments.forEach((segment, i) => {
|