Skip to content
The Chat Archive
claude-opus-4-20250514· Anthropic LMArena Human Preference 140K

create game in html similar to duper cobra from atari

  1. User

    create game in html similar to duper cobra from atari

  2. Assistant

    I'll create an HTML game inspired by Super Cobra from Atari. This will be a side-scrolling helicopter game where you navigate through caves while avoiding obstacles.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Cave Flyer</title>
        <style>
            body {
                margin: 0;
                padding: 0;
                background-color: #000;
                display: flex;
                justify-content: center;
                align-items: center;
                height: 100vh;
                font-family: monospace;
            }
            
            #gameContainer {
                position: relative;
            }
            
            #gameCanvas {
                border: 2px solid #0f0;
                background-color: #111;
            }
            
            #gameInfo {
                position: absolute;
                top: 10px;
                left: 10px;
                color: #0f0;
                font-size: 18px;
            }
            
            #gameOver {
                position: absolute;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                color: #f00;
                font-size: 32px;
                display: none;
                text-align: center;
            }
            
            #instructions {
                position: absolute;
                bottom: -40px;
                left: 0;
                right: 0;
                text-align: center;
                color: #0f0;
                font-size: 14px;
            }
        </style>
    </head>
    <body>
        <div id="gameContainer">
            <canvas id="gameCanvas" width="800" height="400"></canvas>
            <div id="gameInfo">
                <div>Score: <span id="score">0</span></div>
                <div>Fuel: <span id="fuel">100</span></div>
            </div>
            <div id="gameOver">
                GAME OVER<br>
                <span style="font-size: 18px;">Press SPACE to restart</span>
            </div>
            <div id="instructions">
                Use ARROW KEYS to move • SPACE to shoot • Avoid walls and enemies
            </div>
        </div>
    
        <script>
            const canvas = document.getElementById('gameCanvas');
            const ctx = canvas.getContext('2d');
            
            // Game variables
            let gameRunning = true;
            let score = 0;
            let fuel = 100;
            let scrollSpeed = 2;
            
            // Helicopter object
            const helicopter = {
                x: 100,
                y: 200,
                width: 30,
                height: 15,
                velocityY: 0,
                speed: 3
            };
            
            // Arrays for game objects
            let terrain = [];
            let enemies = [];
            let bullets = [];
            let fuelTanks = [];
            
            // Input handling
            const keys = {};
            document.addEventListener('keydown', (e) => {
                keys[e.key] = true;
                if (e.key === ' ' && !gameRunning) {
                    resetGame();
                }
            });
            document.addEventListener('keyup', (e) => {
                keys[e.key] = false;
            });
            
            // Initialize terrain
            function initTerrain() {
                terrain = [];
                let topHeight = 100;
                let bottomHeight = 100;
                
                for (let x = 0; x < canvas.width + 200; x += 20) {
                    topHeight += (Math.random() - 0.5) * 20;
                    bottomHeight += (Math.random() - 0.5) * 20;
                    
                    topHeight = Math.max(50, Math.min(150, topHeight));
                    bottomHeight = Math.max(50, Math.min(150, bottomHeight));
                    
                    terrain.push({
                        x: x,
                        topHeight: topHeight,
                        bottomHeight: bottomHeight
                    });
                }
            }
            
            // Update game objects
            function update() {
                if (!gameRunning) return;
                
                // Update helicopter
                if (keys['ArrowUp'] && helicopter.y > 0) {
                    helicopter.y -= helicopter.speed;
                }
                if (keys['ArrowDown'] && helicopter.y < canvas.height - helicopter.height) {
                    helicopter.y += helicopter.speed;
                }
                if (keys['ArrowLeft'] && helicopter.x > 0) {
                    helicopter.x -= helicopter.speed;
                }
                if (keys['ArrowRight'] && helicopter.x < canvas.width - helicopter.width) {
                    helicopter.x += helicopter.speed;
                }
                
                // Shoot bullets
                if (keys[' '] && bullets.length < 3) {
                    keys[' '] = false;
                    bullets.push({
                        x: helicopter.x + helicopter.width,
                        y: helicopter.y + helicopter.height / 2,
                        speed: 8
                    });
                }
                
                // Update bullets
                bullets = bullets.filter(bullet => {
                    bullet.x += bullet.speed;
                    return bullet.x < canvas.width;
                });
                
                // Scroll terrain
                terrain.forEach(segment => {
                    segment.x -= scrollSpeed;
                });
                
                // Remove off-screen terrain and add new
                terrain = terrain.filter(segment => segment.x > -20);
                
                if (terrain[terrain.length - 1].x < canvas.width) {
                    const lastSegment = terrain[terrain.length - 1];
                    let topHeight = lastSegment.topHeight + (Math.random() - 0.5) * 30;
                    let bottomHeight = lastSegment.bottomHeight + (Math.random() - 0.5) * 30;
                    
                    topHeight = Math.max(50, Math.min(150, topHeight));
                    bottomHeight = Math.max(50, Math.min(150, bottomHeight));
                    
                    terrain.push({
                        x: lastSegment.x + 20,
                        topHeight: topHeight,
                        bottomHeight: bottomHeight
                    });
                }
                
                // Spawn enemies
                if (Math.random() < 0.02) {
                    enemies.push({
                        x: canvas.width,
                        y: Math.random() * (canvas.height - 100) + 50,
                        width: 25,
                        height: 25,
                        speed: scrollSpeed + 1
                    });
                }
                
                // Update enemies
                enemies = enemies.filter(enemy => {
                    enemy.x -= enemy.speed;
                    
                    // Check bullet collisions
                    for (let i = bullets.length - 1; i >= 0; i--) {
                        if (bullets[i].x > enemy.x && 
                            bullets[i].x < enemy.x + enemy.width &&
                            bullets[i].y > enemy.y && 
                            bullets[i].y < enemy.y + enemy.height) {
                            bullets.splice(i, 1);
                            score += 50;
                            return false;
                        }
                    }
                    
                    return enemy.x > -enemy.width;
                });
                
                // Spawn fuel tanks
                if (Math.random() < 0.005 && fuel < 50) {
                    fuelTanks.push({
                        x: canvas.width,
                        y: Math.random() * (canvas.height - 150) + 75,
                        width: 20,
                        height: 20
                    });
                }
                
                // Update fuel tanks
                fuelTanks = fuelTanks.filter(tank => {
                    tank.x -= scrollSpeed;
                    
                    // Check helicopter collision
                    if (helicopter.x < tank.x + tank.width &&
                        helicopter.x + helicopter.width > tank.x &&
                        helicopter.y < tank.y + tank.height &&
                        helicopter.y + helicopter.height > tank.y) {
                        fuel = Math.min(100, fuel + 30);
                        return false;
                    }
                    
                    return tank.x > -tank.width;
                });
                
                // Check collisions
                checkCollisions();
                
                // Update fuel and score
                fuel -= 0.1;
                if (fuel <= 0) {
                    gameOver();
                }
                score += 1;
                
                // Update UI
                document.getElementById('score').textContent = Math.floor(score);
                document.getElementById('fuel').textContent = Math.floor(fuel);
            }
            
            function checkCollisions() {
                // Check terrain collision
                for (let segment of terrain) {
                    if (helicopter.x + helicopter.width > segment.x && 
                        helicopter.x < segment.x + 20) {
                        if (helicopter.y < segment.topHeight || 
                            helicopter.y + helicopter.height > canvas.height - segment.bottomHeight) {
                            gameOver();
                        }
                    }
                }
                
                // Check enemy collision
                for (let enemy of enemies) {
                    if (helicopter.x < enemy.x + enemy.width &&
                        helicopter.x + helicopter.width > enemy.x &&
                        helicopter.y < enemy.y + enemy.height &&
                        helicopter.y + helicopter.height > enemy.y) {
                        gameOver();
                    }
                }
            }
            
            function gameOver() {
                gameRunning = false;
                document.getElementById('gameOver').style.display = 'block';
            }
            
            function resetGame() {
                gameRunning = true;
                score = 0;
                fuel = 100;
                helicopter.x = 100;
                helicopter.y = 200;
                enemies = [];
                bullets = [];
                fuelTanks = [];
                initTerrain();
                document.getElementById('gameOver').style.display = 'none';
            }
            
            // Draw functions
            function draw() {
                // Clear canvas
                ctx.fillStyle = '#111';
                ctx.fillRect(0, 0, canvas.width, canvas.height);
                
                // Draw terrain
                ctx.fillStyle = '#0a0';
                terrain.forEach(segment => {
                    // Top terrain
                    ctx.fillRect(segment.x, 0, 20, segment.topHeight);
                    // Bottom terrain
                    ctx.fillRect(segment.x, canvas.height - segment.bottomHeight, 20, segment.bottomHeight);
                });
                
                // Draw helicopter
                ctx.fillStyle = '#0f0';
                ctx.fillRect(helicopter.x, helicopter.y, helicopter.width, helicopter.height);
                // Rotor
                ctx.fillRect(helicopter.x + 5, helicopter.y - 3, 20, 2);
                // Tail
                ctx.fillRect(helicopter.x - 10, helicopter.y + 5, 10, 5);
                
                // Draw enemies
                ctx.fillStyle = '#f00';
                enemies.forEach(enemy => {
                    ctx.fillRect(enemy.x, enemy.y, enemy.width, enemy.height);
                });
                
                // Draw bullets
                ctx.fillStyle = '#ff0';
                bullets.forEach(bullet => {
                    ctx.fillRect(bullet.x, bullet.y - 1, 5, 2);
                });
                
                // Draw fuel tanks
                ctx.fillStyle = '#00f';
                fuelTanks.forEach(tank => {
                    ctx.fillRect(tank.x, tank.y, tank.width, tank.height);
                    ctx.fillStyle = '#fff';
                    ctx.fillText('F', tank.x + 5, tank.y + 15);
                    ctx.fillStyle = '#00f';
                });
            }
            
            // Game loop
            function gameLoop() {
                update();
                draw();
                requestAnimationFrame(gameLoop);
            }
            
            // Initialize and start game
            initTerrain();
            gameLoop();
        </script>
    </body>
    </html>
    

    This game recreates the classic Super Cobra experience with:

    • A helicopter that you control with arrow keys
    • Procedurally generated cave terrain that scrolls continuously
    • Enemy obstacles (red squares) that appear randomly
    • A fuel system that depletes over time
    • Fuel tanks (blue squares marked with 'F') that replenish your fuel
    • Shooting mechanics (spacebar) to destroy enemies
    • Score tracking
    • Collision detection with walls and enemies
    • Game over and restart functionality

    The game features retro-style graphics with a green color scheme reminiscent of early arcade games. The difficulty gradually increases as you progress, and you need to balance avoiding obstacles while managing your fuel supply.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.