Update templates/index.html
Browse files- templates/index.html +24 -16
templates/index.html
CHANGED
|
@@ -221,7 +221,7 @@
|
|
| 221 |
|
| 222 |
// Game configuration
|
| 223 |
const CONFIG = {
|
| 224 |
-
GRID_SIZE:
|
| 225 |
CELL_SIZE: 1, // Size of each grid cell/snake segment
|
| 226 |
BASE_SPEED: 150, // Base milliseconds between updates
|
| 227 |
DIFFICULTY_LEVELS: {
|
|
@@ -400,22 +400,23 @@
|
|
| 400 |
}
|
| 401 |
|
| 402 |
animate() {
|
| 403 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
// Semi-transparent background to create fade effect
|
| 405 |
this.ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
| 406 |
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
| 407 |
|
| 408 |
-
this.ctx.fillStyle = '#0f0';
|
| 409 |
this.ctx.font = this.fontSize + 'px monospace';
|
| 410 |
|
| 411 |
for(let i = 0; i < this.drops.length; i++) {
|
| 412 |
-
// Choose a random character
|
| 413 |
const text = this.characters.charAt(Math.floor(Math.random() * this.characters.length));
|
| 414 |
-
|
| 415 |
-
// Draw the character
|
| 416 |
this.ctx.fillText(text, i * this.fontSize, this.drops[i] * this.fontSize);
|
| 417 |
|
| 418 |
-
// Move drops down and reset when off the screen
|
| 419 |
if(this.drops[i] * this.fontSize > this.canvas.height && Math.random() > 0.975) {
|
| 420 |
this.drops[i] = 0;
|
| 421 |
}
|
|
@@ -424,8 +425,8 @@
|
|
| 424 |
}
|
| 425 |
requestAnimationFrame(this.animate);
|
| 426 |
}
|
| 427 |
-
}
|
| 428 |
|
|
|
|
| 429 |
// --- Object pooling for performance optimization ---
|
| 430 |
class ObjectPool {
|
| 431 |
constructor(createFunc, initialCount = 10) {
|
|
@@ -562,19 +563,26 @@
|
|
| 562 |
}
|
| 563 |
|
| 564 |
// Place food at random position
|
|
|
|
| 565 |
placeFood() {
|
| 566 |
let foodPos;
|
| 567 |
let validPosition = false;
|
| 568 |
let attempts = 0;
|
| 569 |
const maxAttempts = 100; // Prevent infinite loop
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 570 |
|
| 571 |
-
while (!validPosition && attempts < maxAttempts) {
|
| 572 |
-
foodPos = new THREE.Vector3(
|
| 573 |
-
Math.floor(Math.random() * CONFIG.GRID_SIZE - CONFIG.GRID_SIZE / 2) * CONFIG.CELL_SIZE,
|
| 574 |
-
0,
|
| 575 |
-
Math.floor(Math.random() * CONFIG.GRID_SIZE - CONFIG.GRID_SIZE / 2) * CONFIG.CELL_SIZE
|
| 576 |
-
);
|
| 577 |
-
|
| 578 |
// Check collision with snake
|
| 579 |
let collisionWithSnake = this.snake.some(segment =>
|
| 580 |
segment.position.distanceTo(foodPos) < CONFIG.CELL_SIZE * 0.9
|
|
@@ -959,7 +967,7 @@
|
|
| 959 |
init() {
|
| 960 |
// Create scene
|
| 961 |
this.scene = new THREE.Scene();
|
| 962 |
-
this.scene.background =
|
| 963 |
|
| 964 |
// Add fog for depth
|
| 965 |
this.scene.fog = new THREE.Fog(0x000500, CONFIG.GRID_SIZE * 0.8, CONFIG.GRID_SIZE * 2.5);
|
|
|
|
| 221 |
|
| 222 |
// Game configuration
|
| 223 |
const CONFIG = {
|
| 224 |
+
GRID_SIZE: 20, // Number of units across/deep
|
| 225 |
CELL_SIZE: 1, // Size of each grid cell/snake segment
|
| 226 |
BASE_SPEED: 150, // Base milliseconds between updates
|
| 227 |
DIFFICULTY_LEVELS: {
|
|
|
|
| 400 |
}
|
| 401 |
|
| 402 |
animate() {
|
| 403 |
+
// Check if the game is in menu, paused, OR game over state
|
| 404 |
+
if (GameState.currentState === GameState.MENU ||
|
| 405 |
+
GameState.currentState === GameState.PAUSED ||
|
| 406 |
+
GameState.currentState === GameState.GAME_OVER ||
|
| 407 |
+
GameState.currentState === GameState.PLAYING) { // Added PLAYING back, assuming you still want it there!
|
| 408 |
+
|
| 409 |
// Semi-transparent background to create fade effect
|
| 410 |
this.ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
| 411 |
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
| 412 |
|
| 413 |
+
this.ctx.fillStyle = '#0f0'; // Or your matrix color
|
| 414 |
this.ctx.font = this.fontSize + 'px monospace';
|
| 415 |
|
| 416 |
for(let i = 0; i < this.drops.length; i++) {
|
|
|
|
| 417 |
const text = this.characters.charAt(Math.floor(Math.random() * this.characters.length));
|
|
|
|
|
|
|
| 418 |
this.ctx.fillText(text, i * this.fontSize, this.drops[i] * this.fontSize);
|
| 419 |
|
|
|
|
| 420 |
if(this.drops[i] * this.fontSize > this.canvas.height && Math.random() > 0.975) {
|
| 421 |
this.drops[i] = 0;
|
| 422 |
}
|
|
|
|
| 425 |
}
|
| 426 |
requestAnimationFrame(this.animate);
|
| 427 |
}
|
|
|
|
| 428 |
|
| 429 |
+
|
| 430 |
// --- Object pooling for performance optimization ---
|
| 431 |
class ObjectPool {
|
| 432 |
constructor(createFunc, initialCount = 10) {
|
|
|
|
| 563 |
}
|
| 564 |
|
| 565 |
// Place food at random position
|
| 566 |
+
// Place food at random position
|
| 567 |
placeFood() {
|
| 568 |
let foodPos;
|
| 569 |
let validPosition = false;
|
| 570 |
let attempts = 0;
|
| 571 |
const maxAttempts = 100; // Prevent infinite loop
|
| 572 |
+
|
| 573 |
+
// --- THIS IS THE UPDATED PART ---
|
| 574 |
+
const numCells = CONFIG.GRID_SIZE;
|
| 575 |
+
const xIndex = Math.floor(Math.random() * numCells) - Math.floor((numCells - 1) / 2);
|
| 576 |
+
const zIndex = Math.floor(Math.random() * numCells) - Math.floor((numCells - 1) / 2);
|
| 577 |
+
|
| 578 |
+
const potentialFoodPos = new THREE.Vector3(
|
| 579 |
+
xIndex * CONFIG.CELL_SIZE,
|
| 580 |
+
0, // Assuming food is always on y=0 plane
|
| 581 |
+
zIndex * CONFIG.CELL_SIZE
|
| 582 |
+
);
|
| 583 |
+
// --- END OF UPDATED PART ---
|
| 584 |
|
| 585 |
+
while (!validPosition && attempts < maxAttempts) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 586 |
// Check collision with snake
|
| 587 |
let collisionWithSnake = this.snake.some(segment =>
|
| 588 |
segment.position.distanceTo(foodPos) < CONFIG.CELL_SIZE * 0.9
|
|
|
|
| 967 |
init() {
|
| 968 |
// Create scene
|
| 969 |
this.scene = new THREE.Scene();
|
| 970 |
+
this.scene.background = null;
|
| 971 |
|
| 972 |
// Add fog for depth
|
| 973 |
this.scene.fog = new THREE.Fog(0x000500, CONFIG.GRID_SIZE * 0.8, CONFIG.GRID_SIZE * 2.5);
|