Este jogo possui alguns bugs, pode consertá-los e melhorar o jogo? [code]
- User
Este jogo possui alguns bugs, pode consertá-los e melhorar o jogo?
<!DOCTYPE html> <html lang="pt-BR"> <head> <meta name="referrer" content="no-referrer-when-downgrade"> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Explorador de Cores - Sobrevivência</title> <style> body { margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #1a1a1a; font-family: Arial, sans-serif; color: white; overflow: hidden; } #game-container { width: 800px; height: 600px; position: relative; overflow: hidden; border: 2px solid #fff; background-color: #000; } #start-screen, #game-screen { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; } #start-screen { background-color: rgba(0, 0, 0, 0.85); z-index: 10; } #game-screen { display: none; background-color: #222; } input, button { font-size: 18px; padding: 10px 20px; margin: 10px; border: none; border-radius: 5px; } button { background-color: #3498db; color: white; cursor: pointer; transition: background-color 0.3s; } button:hover { background-color: #2980b9; } #game-map { position: absolute; width: 600px; height: 600px; overflow: hidden; background-color: #555; } .tile { position: absolute; width: 20px; height: 20px; transition: background-color 0.2s ease; } #player { position: absolute; width: 20px; height: 20px; background-color: white; border-radius: 50%; z-index: 5; left: 50%; top: 50%; transform: translate(-50%, -50%); transition: background-color 0.2s ease; } #hud { position: absolute; top: 10px; left: 10px; font-size: 16px; background-color: rgba(0, 0, 0, 0.5); padding: 10px; border-radius: 5px; } #hud div { margin: 5px 0; } </style> </head> <body> <div id="game-container"> <div id="start-screen"> <h1>Explorador de Cores</h1> <input type="text" id="seed-input" placeholder="Digite a seed do mapa"> <button id="map-size-button">Tamanho do Mapa: 150x150</button> <button id="play-button">JOGAR</button> </div> <div id="game-screen"> <div id="game-map"></div> <div id="player"></div> <div id="hud"> <div id="health">Saúde: 100</div> <div id="hunger">Fome: 100</div> <div id="resources">Recursos: 0</div> </div> </div> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/seedrandom/3.0.5/seedrandom.min.js"></script> <!-- Adicionando uma biblioteca de sons (opcional) --> <script src="https://cdnjs.cloudflare.com/ajax/libs/howler/2.2.3/howler.min.js"></script> <script> (function () { const GG_ALL_GAME_CONFIG = { mapSizes: [ [150, 150], [300, 300], [500, 500] ], // Opções de tamanho do mapa currentMapSizeIndex: 0, // Índice do tamanho atual do mapa visibleTiles: { x: 30, y: 30 }, // Número de tiles visíveis tileSize: 20, // Tamanho de cada tile em pixels playerSpeed: 5, // Velocidade do movimento do jogador (tiles por segundo) colors: { sand: '#F4D03F', // Areia - Amarelo grass: '#2ECC71', // Grama - Verde water: '#3498DB', // Água - Azul resource: '#E74C3C' // Recurso - Vermelho }, healthDecreaseRate: 0.1, // Taxa de diminuição da saúde por segundo hungerDecreaseRate: 0.2, // Taxa de diminuição da fome por segundo noiseScale: 0.05, // Escala do ruído para geração procedural waterLevel: 0.3, // Nível da água sandLevel: 0.5, // Nível da areia cameraSmoothing: 0.15, // Fator de suavização da câmera resourceChance: 0.05 // Chance de recurso em tiles de grama }; let gameState = { map: [], playerX: 0, playerY: 0, mapOffsetX: 0, mapOffsetY: 0, targetMapOffsetX: 0, targetMapOffsetY: 0, health: 100, hunger: 100, resources: 0, gameLoop: null, movementKeys: { ArrowUp: false, ArrowDown: false, ArrowLeft: false, ArrowRight: false } }; // Sons do jogo const sounds = { bgm: new Howl({ src: ['https://assets.mixkit.co/music/preview/mixkit-adventure-arcade-game-overworld-231.mp3'], loop: true, volume: 0.5 }), collect: new Howl({ src: ['https://assets.mixkit.co/sfx/preview/mixkit-coin-pickup-211.wav'], volume: 1.0 }), gameOver: new Howl({ src: ['https://assets.mixkit.co/sfx/preview/mixkit-player-losing-or-failing-2042.wav'], volume: 1.0 }) }; function initGame() { document.getElementById('play-button').addEventListener('click', startGame); document.getElementById('map-size-button').addEventListener('click', cycleMapSize); document.addEventListener('keydown', movePlayer); document.addEventListener('keyup', movePlayer); } function cycleMapSize() { GG_ALL_GAME_CONFIG.currentMapSizeIndex = (GG_ALL_GAME_CONFIG.currentMapSizeIndex + 1) % GG_ALL_GAME_CONFIG.mapSizes.length; const [width, height] = GG_ALL_GAME_CONFIG.mapSizes[GG_ALL_GAME_CONFIG.currentMapSizeIndex]; document.getElementById('map-size-button').textContent = `Tamanho do Mapa: ${width}x${height}`; } function startGame() { const seed = document.getElementById('seed-input').value.trim() || Math.random().toString(36).substr(2, 9); const rng = new Math.seedrandom(seed); const [mapWidth, mapHeight] = GG_ALL_GAME_CONFIG.mapSizes[GG_ALL_GAME_CONFIG.currentMapSizeIndex]; gameState.map = generateMap(mapWidth, mapHeight, rng); document.getElementById('start-screen').style.display = 'none'; document.getElementById('game-screen').style.display = 'flex'; gameState.playerX = mapWidth / 2; gameState.playerY = mapHeight / 2; gameState.resources = 0; renderVisibleMap(); updatePlayerPosition(); updateHUD(); sounds.bgm.play(); if (gameState.gameLoop) clearInterval(gameState.gameLoop); gameState.gameLoop = setInterval(updateGameState, 1000 / 60); // 60 FPS } function generateMap(width, height, rng) { const map = []; const noise = new SimplexNoise(rng); for (let y = 0; y < height; y++) { map[y] = []; for (let x = 0; x < width; x++) { const noiseValue = (noise.noise2D(x * GG_ALL_GAME_CONFIG.noiseScale, y * GG_ALL_GAME_CONFIG.noiseScale) + 1) / 2; if (noiseValue < GG_ALL_GAME_CONFIG.waterLevel) { map[y][x] = 'water'; } else if (noiseValue < GG_ALL_GAME_CONFIG.sandLevel) { map[y][x] = 'sand'; } else { // Adiciona chance de recurso em tiles de grama map[y][x] = (rng() < GG_ALL_GAME_CONFIG.resourceChance) ? 'resource' : 'grass'; } } } return map; } // Implementação do SimplexNoise class SimplexNoise { constructor(rng) { this.p = new Uint8Array(256); for (let i = 0; i < 256; i++) { this.p[i] = i; } for (let i = 255; i > 0; i--) { const j = Math.floor(rng() * (i + 1)); [this.p[i], this.p[j]] = [this.p[j], this.p[i]]; } this.perm = new Uint8Array(512); this.permMod12 = new Uint8Array(512); for (let i = 0; i < 512; i++) { this.perm[i] = this.p[i & 255]; this.permMod12[i] = this.perm[i] % 12; } } noise2D(xin, yin) { const F2 = 0.5 * (Math.sqrt(3.0) - 1.0); const G2 = (3.0 - Math.sqrt(3.0)) / 6.0; let n0, n1, n2; const s = (xin + yin) * F2; let i = Math.floor(xin + s); let j = Math.floor(yin + s); const t = (i + j) * G2; const X0 = i - t; const Y0 = j - t; let x0 = xin - X0; let y0 = yin - Y0; let i1, j1; if (x0 > y0) { i1 = 1; j1 = 0; } else { i1 = 0; j1 = 1; } const x1 = x0 - i1 + G2; const y1 = y0 - j1 + G2; const x2 = x0 - 1.0 + 2.0 * G2; const y2 = y0 - 1.0 + 2.0 * G2; const ii = i & 255; const jj = j & 255; const gi0 = this.permMod12[ii + this.perm[jj]]; const gi1 = this.permMod12[ii + i1 + this.perm[jj + j1]]; const gi2 = this.permMod12[ii + 1 + this.perm[jj + 1]]; let t0 = 0.5 - x0 * x0 - y0 * y0; if (t0 < 0) n0 = 0.0; else { t0 *= t0; n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0); } let t1 = 0.5 - x1 * x1 - y1 * y1; if (t1 < 0) n1 = 0.0; else { t1 *= t1; n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1); } let t2 = 0.5 - x2 * x2 - y2 * y2; if (t2 < 0) n2 = 0.0; else { t2 *= t2; n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2); } return 70.0 * (n0 + n1 + n2); } dot(g, x, y) { return g[0] * x + g[1] * y; } grad3 = [ [1, 1], [-1, 1], [1, -1], [-1, -1], [1, 0], [-1, 0], [0, 1], [0, -1], [1, 1], [-1, 1], [1, -1], [-1, -1] ]; } function renderVisibleMap() { const mapContainer = document.getElementById('game-map'); mapContainer.innerHTML = ''; const [mapWidth, mapHeight] = GG_ALL_GAME_CONFIG.mapSizes[GG_ALL_GAME_CONFIG.currentMapSizeIndex]; const tileSize = GG_ALL_GAME_CONFIG.tileSize; const startX = Math.floor(gameState.mapOffsetX); const startY = Math.floor(gameState.mapOffsetY); const endX = Math.min(mapWidth, startX + GG_ALL_GAME_CONFIG.visibleTiles.x + 1); const endY = Math.min(mapHeight, startY + GG_ALL_GAME_CONFIG.visibleTiles.y + 1); for (let y = startY; y < endY; y++) { for (let x = startX; x < endX; x++) { const tile = document.createElement('div'); tile.className = 'tile'; let tileType = gameState.map[y][x]; if (tileType === 'resource') { tile.style.backgroundColor = GG_ALL_GAME_CONFIG.colors['resource']; } else { tile.style.backgroundColor = GG_ALL_GAME_CONFIG.colors[tileType]; } tile.style.left = `${(x - startX) * tileSize}px`; tile.style.top = `${(y - startY) * tileSize}px`; mapContainer.appendChild(tile); } } } function movePlayer(e) { if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(e.key)) { e.preventDefault(); // Evita o scroll da página } if (e.type === 'keydown') { gameState.movementKeys[e.key] = true; } else if (e.type === 'keyup') { gameState.movementKeys[e.key] = false; } } function updatePlayerPosition(deltaTime) { const [mapWidth, mapHeight] = GG_ALL_GAME_CONFIG.mapSizes[GG_ALL_GAME_CONFIG.currentMapSizeIndex]; const speedPerSecond = GG_ALL_GAME_CONFIG.playerSpeed; // Tiles por segundo const speedPerFrame = speedPerSecond * (deltaTime / 1000); // Tiles por frame if (gameState.movementKeys.ArrowUp) { gameState.playerY = Math.max(0, gameState.playerY - speedPerFrame); } if (gameState.movementKeys.ArrowDown) { gameState.playerY = Math.min(mapHeight - 1, gameState.playerY + speedPerFrame); } if (gameState.movementKeys.ArrowLeft) { gameState.playerX = Math.max(0, gameState.playerX - speedPerFrame); } if (gameState.movementKeys.ArrowRight) { gameState.playerX = Math.min(mapWidth - 1, gameState.playerX + speedPerFrame); } const centerX = GG_ALL_GAME_CONFIG.visibleTiles.x / 2; const centerY = GG_ALL_GAME_CONFIG.visibleTiles.y / 2; gameState.targetMapOffsetX = Math.max(0, Math.min(gameState.playerX - centerX, mapWidth - GG_ALL_GAME_CONFIG.visibleTiles.x)); gameState.targetMapOffsetY = Math.max(0, Math.min(gameState.playerY - centerY, mapHeight - GG_ALL_GAME_CONFIG.visibleTiles.y)); // Suavização da câmera gameState.mapOffsetX += (gameState.targetMapOffsetX - gameState.mapOffsetX) * GG_ALL_GAME_CONFIG.cameraSmoothing; gameState.mapOffsetY += (gameState.targetMapOffsetY - gameState.mapOffsetY) * GG_ALL_GAME_CONFIG.cameraSmoothing; renderVisibleMap(); checkResourceCollect(); } function checkResourceCollect() { const playerTileX = Math.floor(gameState.playerX); const playerTileY = Math.floor(gameState.playerY); if (gameState.map[playerTileY][playerTileX] === 'resource') { gameState.resources += 1; gameState.map[playerTileY][playerTileX] = 'grass'; // Remove recurso após coleta sounds.collect.play(); // Atualiza o mapa visível imediatamente para refletir a coleta renderVisibleMap(); updateHUD(); } } function updateGameState() { const deltaTime = 1000 / 60; // Aproximadamente 16.67ms por frame updatePlayerPosition(deltaTime); gameState.health -= GG_ALL_GAME_CONFIG.healthDecreaseRate / 60; gameState.hunger -= GG_ALL_GAME_CONFIG.hungerDecreaseRate / 60; if (gameState.health <= 0 || gameState.hunger <= 0) { endGame(); } updateHUD(); } function updateHUD() { document.getElementById('health').textContent = `Saúde: ${Math.max(0, Math.round(gameState.health))}`; document.getElementById('hunger').textContent = `Fome: ${Math.max(0, Math.round(gameState.hunger))}`; document.getElementById('resources').textContent = `Recursos: ${gameState.resources}`; } function endGame() { clearInterval(gameState.gameLoop); sounds.bgm.stop(); sounds.gameOver.play(); alert(`Fim de jogo! Você coletou ${gameState.resources} recursos.`); document.getElementById('game-screen').style.display = 'none'; document.getElementById('start-screen').style.display = 'flex'; resetGameState(); } function resetGameState() { gameState.health = 100; gameState.hunger = 100; gameState.playerX = 0; gameState.playerY = 0; gameState.mapOffsetX = 0; gameState.mapOffsetY = 0; gameState.resources = 0; gameState.movementKeys = { ArrowUp: false, ArrowDown: false, ArrowLeft: false, ArrowRight: false }; } initGame(); })(); </script> </body> </html> - Assistant