dungeon crawler game test
coding
Prompt
Act as an expert game engineer specializing in retro rogue-like mechanics and 2D graphics math. Your task is to build a complete, self-contained "Procedural Dungeon Generator with Dynamic Fog of War" inside a single, beautifully styled HTML file. Use vanilla HTML, CSS, and JavaScript with NO external libraries or dependencies. ### Visual & UI Requirements: 1. UI Layout: A clean, dark cyber-grid theme. Center the canvas. Include a control panel with: - A button to "Regenerate Map" - Text display showing current player coordinates - A button to toggle "God Mode" (revealing the entire map layout completely for debugging/demonstration). 2. Canvas Dimensions: Fixed at 600x600 pixels. Use `image-rendering: pixelated;` in CSS. The internal simulation grid should map to exactly 60x60 cells (meaning each map tile is a 10x10 pixel square on the canvas). 3. Theme Colors: - Unexplored (Never Seen): Absolute pitch black (#000000) - Explored but Not Currently Visible: Dimmed/darker versions of the tile colors (e.g. walls #2a2d3f, floor #5c5360) — the player can still see the layout of areas they have already visited, but not at full brightness - Currently Visible Walls: Deep stone gray (#4a4e69) - Currently Visible Floor: Soft slate gray (#9a8c98) - Player Character: A bright, distinct green square or sprite (#55ff33) ### Core Mechanics & Algorithmic Rules: You must implement a 2D grid array representing the map states (0 = Floor, 1 = Wall) and a secondary 2D array tracking exploration (0 = Unexplored, 1 = Explored). Fog of War must use two layers: - **Explored**: Tiles the player has ever had line of sight to. Once a tile is marked explored, it stays explored permanently for the rest of the session — explored areas do NOT return to full darkness when the player moves away or leaves line of sight. - **Currently Visible**: Tiles within the player's current line-of-sight radius. This is recalculated each frame/move; tiles can leave current visibility but remain explored. Rendering rule: Unexplored tiles render as pitch black. Explored-but-not-visible tiles render dimmed. Currently visible tiles render at full brightness. 1. Map Generation (Choose One Engine): - Option A: Binary Space Partitioning (BSP) to split the grid recursively into rectangular rooms, then carving straight hallway connections between them. - Option B: Cellular Automata (Fill grid randomly with ~45% walls, then run 4-5 simulation steps of Conway's-like rules to create organic cave layouts). Ensure there is an algorithm to connect isolated cavern pockets. 2. Player Movement: Spawn the player on a valid Floor tile. Implement standard keyboard controls (Arrow keys or WASD) to move the player exactly 1 grid tile per keypress. Prevent walking through Wall tiles. 3. Raycasting Line of Sight (The Core Math Challenge): - You must calculate the player's real-time visibility radius (limited to 8-10 tiles away). - To do this, cast virtual rays from the player's tile out to every single grid tile along the perimeter of their visibility radius. - For EACH ray, you MUST implement a generalized Bresenham's Line Algorithm to trace the line of grid cells step-by-step from the player to the destination tile. - Trace rules: Mark cells along the line as both "Explored" (permanent) and "Currently Visible" (temporary). If the line hits a cell marked as a Wall, immediately stop tracing that ray further (blocking vision behind the wall). - After each move, clear the "Currently Visible" layer and recalculate it from scratch — but never clear the "Explored" layer. ### Deliverable: Write the complete, working code inside a single HTML file containing the HTML, CSS, and JavaScript. Do not leave any functions empty, do not use comments like "// implement logic here", and do not omit edge cases. It must run immediately when opened in a web browser. Note: You may not have access to a browser, dev server, or vision tools — do not rely on running or visually inspecting the game for verification. Validate by reading and reasoning about the code instead. Before finishing, review the code to confirm: - Map generation (BSP or cellular automata) produces valid floor tiles with connectivity between areas - Player moves one tile per keypress and cannot walk through walls - Bresenham raycasting marks explored and currently visible cells along each ray and stops at walls - Explored tiles remain visible (dimmed) after the player leaves; only never-seen tiles stay pitch black - God mode toggle reveals the full map; regenerate resets the map and exploration state - Complete single HTML file with no empty functions or placeholder logic
A system prompt was added to support web rendering
Response not available