Begin implementation
- User
Begin implementation
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Begin implementation
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here's the complete implementation of the procedural platformer:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Procedural Platformer</title>
<style>
body, html {
margin: 0;
padding: 0;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #1a1a2e;
font-family: monospace;
color: white;
}
#gameContainer {
position: relative;
}
canvas {
border: 2px solid #16213e;
background-color: #0f3460;
}
#ui {
position: absolute;
top: 10px;
left: 10px;
color: white;
font-size: 18px;
text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
}
#controls {
position: absolute;
bottom: 10px;
left: 10px;
color: white;
font-size: 14px;
text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
}
#seedInput {
position: absolute;
top: 10px;
right: 10px;
padding: 5px;
font-size: 16px;
}
</style>
</head>
<body>
<div id="gameContainer">
<canvas id="gameCanvas"></canvas>
<div id="ui">
<div>Time: <span id="timer">0.00</span>s</div>
<div>Coins: <span id="coins">0</span>/<span id="totalCoins">0</span></div>
<div>Best: <span id="bestTime">--</span>s</div>
</div>
<div id="controls">
Arrow Keys/WASD: Move | Space: Jump | R: Reset | Enter: New Seed
</div>
<input type="text" id="seedInput" placeholder="Seed" value="12345">
</div>
<script>
// Canvas Setup
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
canvas.width = 800;
canvas.height = 600;
// Game Constants
const GRAVITY = 0.5;
const PLAYER_SIZE = 20;
const COIN_SIZE = 15;
const PLATFORM_HEIGHT = 20;
const COYOTE_TIME = 100; // milliseconds
const JUMP_FORCE = -12;
const JUMP_RELEASE_DAMPING = 0.5;
const PLAYER_SPEED = 5;
const HAZARD_SIZE = 25;
// Game State
let gameState = {
player: null,
platforms: [],
hazards: [],
coins: [],
timer: 0,
gameStarted: false,
gameComplete: false,
seed: 12345,
bestTime: null,
ghostData: null,
currentGhost: null,
recording: []
};
// Seeded Random Number Generator
class SeededRandom {
constructor(seed) {
this.seed = seed;
}
next() {
this.seed = (this.seed * 9301 + 49297) % 233280;
return this.seed / 233280;
}
range(min, max) {
return min + this.next() * (max - min);
}
int(min, max) {
return Math.floor(this.range(min, max + 1));
}
}
// Player Class
class Player {
constructor(x, y) {
this.x = x;
this.y = y;
this.vx = 0;
this.vy = 0;
this.width = PLAYER_SIZE;
this.height = PLAYER_SIZE;
this.grounded = false;
this.lastGroundedTime = 0;
this.jumpHeld = false;
this.jumpsUsed = 0;
}
update(dt) {
// Apply gravity
this.vy += GRAVITY;
// Variable jump
if (!this.jumpHeld && this.vy < 0) {
this.vy *= JUMP_RELEASE_DAMPING;
}
// Apply velocity
this.x += this.vx;
this.y += this.vy;
// Check platform collisions
this.grounded = false;
for (let platform of gameState.platforms) {
if (this.checkCollision(platform)) {
// Landing on top of platform
if (this.vy > 0 && this.y < platform.y) {
this.y = platform.y - this.height;
this.vy = 0;
this.grounded = true;
this.lastGroundedTime = Date.now();
this.jumpsUsed = 0;
}
}
}
// Keep player on screen
this.x = Math.max(0, Math.min(canvas.width - this.width, this.x));
// Check if player fell off screen
if (this.y > canvas.height) {
resetLevel();
}
}
jump() {
const timeSinceGrounded = Date.now() - this.lastGroundedTime;
const canCoyoteJump = timeSinceGrounded < COYOTE_TIME;
if (this.grounded || (canCoyoteJump && this.jumpsUsed === 0)) {
this.vy = JUMP_FORCE;
this.jumpHeld = true;
this.jumpsUsed = 1;
}
}
checkCollision(rect) {
return this.x < rect.x + rect.width &&
this.x + this.width > rect.x &&
this.y < rect.y + rect.height &&
this.y + this.height > rect.y;
}
draw() {
ctx.fillStyle = '#e94560';
ctx.fillRect(this.x, this.y, this.width, this.height);
// Draw eyes
ctx.fillStyle = 'white';
ctx.fillRect(this.x + 4, this.y + 4, 4, 4);
ctx.fillRect(this.x + 12, this.y + 4, 4, 4);
}
}
// Platform Class
class Platform {
constructor(x, y, width) {
this.x = x;
this.y = y;
this.width = width;
this.height = PLATFORM_HEIGHT;
}
draw() {
ctx.fillStyle = '#16213e';
ctx.fillRect(this.x, this.y, this.width, this.height);
ctx.strokeStyle = '#0f3460';
ctx.strokeRect(this.x, this.y, this.width, this.height);
}
}
// Hazard Class
class Hazard {
constructor(x, y, movePattern) {
this.x = x;
this.y = y;
this.width = HAZARD_SIZE;
this.height = HAZARD_SIZE;
this.movePattern = movePattern;
this.time = 0;
this.initialX = x;
this.initialY = y;
}
update(dt) {
this.time += dt;
switch(this.movePattern) {
case 'horizontal':
this.x = this.initialX + Math.sin(this.time * 0.002) * 100;
break;
case 'vertical':
this.y = this.initialY + Math.sin(this.time * 0.003) * 80;
break;
case 'circle':
this.x = this.initialX + Math.cos(this.time * 0.002) * 60;
this.y = this.initialY + Math.sin(this.time * 0.002) * 60;
break;
}
}
draw() {
ctx.fillStyle = '#ff4757';
ctx.save();
ctx.translate(this.x + this.width/2, this.y + this.height/2);
ctx.rotate(this.time * 0.005);
ctx.fillRect(-this.width/2, -this.height/2, this.width, this.height);
ctx.restore();
}
}
// Coin Class
class Coin {
constructor(x, y) {
this.x = x;
this.y = y;
this.width = COIN_SIZE;
this.height = COIN_SIZE;
this.collected = false;
this.time = Math.random() * Math.PI * 2;
}
update(dt) {
this.time += dt * 0.005;
}
draw() {
if (this.collected) return;
ctx.fillStyle = '#ffd700';
ctx.save();
ctx.translate(this.x + this.width/2, this.y + this.height/2);
ctx.scale(1, 0.8 + Math.sin(this.time) * 0.2);
ctx.beginPath();
ctx.arc(0, 0, this.width/2, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
}
}
// Ghost Class
class Ghost {
constructor(recording) {
this.recording = recording;
this.currentFrame = 0;
this.width = PLAYER_SIZE;
this.height = PLAYER_SIZE;
}
update() {
if (this.currentFrame < this.recording.length - 1) {
this.currentFrame++;
}
}
draw() {
if (this.currentFrame >= this.recording.length) return;
const frame = this.recording[this.currentFrame];
ctx.fillStyle = 'rgba(233, 69, 96, 0.3)';
ctx.fillRect(frame.x, frame.y, this.width, this.height);
// Draw ghost eyes
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
ctx.fillRect(frame.x + 4, frame.y + 4, 4, 4);
ctx.fillRect(frame.x + 12, frame.y + 4, 4, 4);
}
}
// Level Generation
function generateLevel(seed) {
const rng = new SeededRandom(seed);
gameState.platforms = [];
gameState.hazards = [];
gameState.coins = [];
// Ground platform
gameState.platforms.push(new Platform(0, canvas.height - 40, canvas.width));
// Generate platforms
const numPlatforms = rng.int(6, 10);
for (let i = 0; i < numPlatforms; i++) {
const width = rng.range(80, 150);
const x = rng.range(0, canvas.width - width);
const y = rng.range(100, canvas.height - 100);
// Ensure platforms don't overlap too much
let valid = true;
for (let platform of gameState.platforms) {
if (Math.abs(platform.y - y) < 40) {
valid = false;
break;
}
}
if (valid) {
gameState.platforms.push(new Platform(x, y, width));
// Add coins above some platforms
if (rng.next() > 0.5) {
const numCoins = rng.int(3, 5);
for (let j = 0; j < numCoins; j++) {
const coinX = x + j * 30 + 10;
const coinY = y - 40;
if (coinX + COIN_SIZE < x + width) {
gameState.coins.push(new Coin(coinX, coinY));
}
}
}
}
}
// Generate hazards
const numHazards = rng.int(3, 6);
const patterns = ['horizontal', 'vertical', 'circle'];
for (let i = 0; i < numHazards; i++) {
const x = rng.range(100, canvas.width - 100);
const y = rng.range(100, canvas.height - 150);
const pattern = patterns[rng.int(0, patterns.length - 1)];
gameState.hazards.push(new Hazard(x, y, pattern));
}
// Create player at spawn point
gameState.player = new Player(50, canvas.height - 100);
// Update UI
document.getElementById('totalCoins').textContent = gameState.coins.length;
}
// Input Handling
const keys = {};
document.addEventListener('keydown', (e) => {
keys[e.key] = true;
if ((e.key === ' ' || e.key === 'w' || e.key === 'W' || e.key === 'ArrowUp') && gameState.player) {
gameState.player.jump();
if (!gameState.gameStarted && !gameState.gameComplete) {
gameState.gameStarted = true;
}
}
if (e.key === 'r' || e.key === 'R') {
resetLevel();
}
if (e.key === 'Enter') {
const seedInput = document.getElementById('seedInput');
gameState.seed = parseInt(seedInput.value) || Date.now();
seedInput.value = gameState.seed;
resetGame();
}
});
document.addEventListener('keyup', (e) => {
keys[e.key] = false;
if ((e.key === ' ' || e.key === 'w' || e.key === 'W' || e.key === 'ArrowUp') && gameState.player) {
gameState.player.jumpHeld = false;
}
});
// Update Game
function update(dt) {
if (!gameState.gameStarted || gameState.gameComplete) return;
// Update timer
gameState.timer += dt;
document.getElementById('timer').textContent = (gameState.timer / 1000).toFixed(2);
// Player movement
if (gameState.player) {
gameState.player.vx = 0;
if (keys['a'] || keys['A'] || keys['ArrowLeft']) {
gameState.player.vx = -PLAYER_SPEED;
}
if (keys['d'] || keys['D'] || keys['ArrowRight']) {
gameState.player.vx = PLAYER_SPEED;
}
gameState.player.update(dt);
// Record player position
if (gameState.recording) {
gameState.recording.push({
x: gameState.player.x,
y: gameState.player.y
});
}
// Check hazard collisions
for (let hazard of gameState.hazards) {
hazard.update(dt);
if (gameState.player.checkCollision(hazard)) {
resetLevel();
return;
}
}
// Check coin collection
let collectedCoins = 0;
for (let coin of gameState.coins) {
coin.update(dt);
if (!coin.collected && gameState.player.checkCollision(coin)) {
coin.collected = true;
}
if (coin.collected) collectedCoins++;
}
document.getElementById('coins').textContent = collectedCoins;
// Check win condition
if (collectedCoins === gameState.coins.length) {
gameState.gameComplete = true;
// Save best time
if (!gameState.bestTime || gameState.timer < gameState.bestTime) {
gameState.bestTime = gameState.timer;
document.getElementById('bestTime').textContent = (gameState.bestTime / 1000).toFixed(2);
// Save ghost data
gameState.ghostData = [...gameState.recording];
}
}
}
// Update ghost
if (gameState.currentGhost) {
gameState.currentGhost.update();
}
}
// Render Game
function render() {
// Clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw platforms
for (let platform of gameState.platforms) {
platform.draw();
}
// Draw coins
for (let coin of gameState.coins) {
coin.draw();
}
// Draw hazards
for (let hazard of gameState.hazards) {
hazard.draw();
}
// Draw ghost
if (gameState.currentGhost) {
gameState.currentGhost.draw();
}
// Draw player
if (gameState.player) {
gameState.player.draw();
}
// Draw win message
if (gameState.gameComplete) {
ctx.fillStyle = 'rgba(0, 0, 0, 0.7)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = '#ffd700';
ctx.font = '48px monospace';
ctx.textAlign = 'center';
ctx.fillText('LEVEL COMPLETE!', canvas.width / 2, canvas.height / 2 - 50);
ctx.font = '24px monospace';
ctx.fillText(`Time: ${(gameState.timer / 1000).toFixed(2)}s`, canvas.width / 2, canvas.height / 2);
ctx.font = '18px monospace';
ctx.fillText('Press R to play again', canvas.width / 2, canvas.height / 2 + 50);
}
}
// Reset Level
function resetLevel() {
gameState.gameStarted = false;
gameState.gameComplete = false;
gameState.timer = 0;
gameState.recording = [];
generateLevel(gameState.seed);
// Create ghost from previous run
if (gameState.ghostData) {
gameState.currentGhost = new Ghost(gameState.ghostData);
}
document.getElementById('timer').textContent = '0.00';
document.getElementById('coins').textContent = '0';
}
// Reset Game (new seed)
function resetGame() {
gameState.bestTime = null;
gameState.ghostData = null;
gameState.currentGhost = null;
document.getElementById('bestTime').textContent = '--';
resetLevel();
}
// Game Loop
let lastTime = 0;
function gameLoop(timestamp) {
const dt = timestamp - lastTime;
lastTime = timestamp;
update(dt);
render();
requestAnimationFrame(gameLoop);
}
// Initialize Game
resetLevel();
requestAnimationFrame(gameLoop);
</script>
</body>
</html>
This implementation includes all the requested features:
Seeded Level Generation: Uses a seeded random number generator to create consistent levels based on the seed value.
Coyote Time: Players can jump for 100ms after leaving a platform, making platforming more forgiving.
Variable Jump: Jump height is controlled by how long the jump button is held.
Moving Hazards: Three types of movement patterns (horizontal, vertical, circular) for hazards that kill the player on contact.
Coin Routes: Coins are strategically placed above platforms to create collection routes.
Speedrun Timer: Tracks time from first movement to level completion, with best time tracking.
Ghost Replay: Records player movement and replays it as a semi-transparent ghost on subsequent runs.
The game features:
The entire application is self-contained in a single HTML file with no external dependencies, as requested.