Skip to content
TheChatArchiveThe Chat Archive
o1-preview-2024-09-12· OpenAIAi2 WildChat-4.8M (AI2)

Create a pokemon style rpg. Add in stats, STAB, types, several creatures, moves, a menu,…

  1. User

    Create a pokemon style rpg. Add in stats, STAB, types, several creatures, moves, a menu, items, a place to heal that you can enter an exit like a pokemon center. Use programmatic graphics for now. Can you create that in javascript/html and put keep it consolidated into one file. Please make it 90s style. Make sure everything happens in the game world and don't use buttons to execute actions.

  2. Assistant

    Sure! Below is a consolidated HTML file that contains a simple 90s-style Pokémon-style RPG game implemented using JavaScript and HTML. The game features:

    • Creatures with stats, types, moves, and STAB (Same Type Attack Bonus).
    • Simple programmatic graphics using HTML5 Canvas.
    • A menu system for selecting actions within the game world.
    • Items that can be used.
    • A healing place similar to a Pokémon Center that you can enter and exit.
    • All interactions happen within the game world without the use of HTML buttons.

    Note: To run the game, simply copy the code below into a file with a .html extension and open it in a modern web browser.

    <!DOCTYPE html>
    <html>
    <head>
        <title>90s Style RPG</title>
        <style>
            body {
                margin: 0;
                background-color: black;
                color: white;
                font-family: monospace;
            }
            #gameCanvas {
                display: block;
                margin: 0 auto;
                background-color: #303030;
            }
        </style>
    </head>
    <body>
    <canvas id="gameCanvas" width="640" height="480"></canvas>
    <script>
    // Game Variables
    const canvas = document.getElementById('gameCanvas');
    const ctx = canvas.getContext('2d');
    
    // Game State
    let gameState = 'overworld'; // 'overworld', 'battle', 'menu', 'healing'
    
    const player = {
        x: 320,
        y: 240,
        width: 32,
        height: 32,
        color: 'blue',
        sprite: null,
        creatures: [],
        items: []
    };
    
    const creaturesList = [
        {
            name: 'Emberon',
            type: 'Fire',
            hp: 30,
            maxHp: 30,
            attack: 12,
            defense: 8,
            speed: 10,
            moves: [
                { name: 'Flame Burst', type: 'Fire', power: 10 },
                { name: 'Scratch', type: 'Normal', power: 5 }
            ]
        },
        {
            name: 'Aquaphin',
            type: 'Water',
            hp: 35,
            maxHp: 35,
            attack: 10,
            defense: 10,
            speed: 8,
            moves: [
                { name: 'Water Splash', type: 'Water', power: 10 },
                { name: 'Tail Whip', type: 'Normal', power: 5 }
            ]
        },
        {
            name: 'Terradon',
            type: 'Grass',
            hp: 40,
            maxHp: 40,
            attack: 8,
            defense: 12,
            speed: 7,
            moves: [
                { name: 'Leaf Blade', type: 'Grass', power: 10 },
                { name: 'Bite', type: 'Normal', power: 5 }
            ]
        }
    ];
    
    const enemyCreatures = [...creaturesList]; // Copy of creatures for encounters
    
    const typesEffectiveness = {
        'Fire': { 'Fire': 0.5, 'Water': 0.5, 'Grass': 2, 'Normal': 1 },
        'Water': { 'Fire': 2, 'Water': 0.5, 'Grass': 0.5, 'Normal': 1 },
        'Grass': { 'Fire': 0.5, 'Water': 2, 'Grass': 0.5, 'Normal': 1 },
        'Normal': { 'Fire': 1, 'Water': 1, 'Grass': 1, 'Normal': 1 }
    };
    
    // Initialize player with a creature
    player.creatures.push(JSON.parse(JSON.stringify(creaturesList[0])));
    
    // Items
    player.items.push({ name: 'Potion', effect: 'heal', amount: 20, quantity: 3 });
    
    // Overworld Map (Simple)
    const map = {
        width: 640,
        height: 480,
        healingZone: { x: 500, y: 200, width: 64, height: 64 }
    };
    
    // Keyboard Input
    const keys = {};
    window.addEventListener('keydown', function(e) {
        keys[e.key] = true;
    });
    window.addEventListener('keyup', function(e) {
        keys[e.key] = false;
    });
    
    // Main Game Loop
    function gameLoop() {
        update();
        draw();
        requestAnimationFrame(gameLoop);
    }
    
    // Update Function
    function update() {
        if (gameState === 'overworld') {
            movePlayer();
            checkEncounter();
            checkHealingZone();
        } else if (gameState === 'battle') {
            // Battle logic will be handled during menu interactions
        }
    }
    
    // Draw Function
    function draw() {
        // Clear Canvas
        ctx.clearRect(0, 0, canvas.width, canvas.height);
    
        if (gameState === 'overworld') {
            drawOverworld();
        } else if (gameState === 'battle') {
            drawBattle();
        } else if (gameState === 'menu') {
            // Menu is drawn over current state
        } else if (gameState === 'healing') {
            drawHealing();
        }
    }
    
    // Player Movement
    function movePlayer() {
        if (keys['ArrowUp']) {
            player.y -= 2;
        }
        if (keys['ArrowDown']) {
            player.y += 2;
        }
        if (keys['ArrowLeft']) {
            player.x -= 2;
        }
        if (keys['ArrowRight']) {
            player.x += 2;
        }
        // Keep player within bounds
        player.x = Math.max(0, Math.min(player.x, map.width - player.width));
        player.y = Math.max(0, Math.min(player.y, map.height - player.height));
    }
    
    // Random Encounter
    function checkEncounter() {
        if (Math.random() < 0.01) {
            // Start battle with a random creature
            startBattle();
        }
    }
    
    // Check for Healing Zone
    function checkHealingZone() {
        if (player.x < map.healingZone.x + map.healingZone.width &&
            player.x + player.width > map.healingZone.x &&
            player.y < map.healingZone.y + map.healingZone.height &&
            player.y + player.height > map.healingZone.y) {
                gameState = 'healing';
                healCreatures();
                setTimeout(() => {
                    gameState = 'overworld';
                }, 2000);
        }
    }
    
    // Start Battle
    let enemy;
    function startBattle() {
        gameState = 'battle';
        enemy = JSON.parse(JSON.stringify(enemyCreatures[Math.floor(Math.random() * enemyCreatures.length)]));
        battleMenu();
    }
    
    // Draw Overworld
    function drawOverworld() {
        // Draw Player
        ctx.fillStyle = player.color;
        ctx.fillRect(player.x, player.y, player.width, player.height);
    
        // Draw Healing Zone
        ctx.fillStyle = 'green';
        ctx.fillRect(map.healingZone.x, map.healingZone.y, map.healingZone.width, map.healingZone.height);
    }
    
    // Draw Battle
    function drawBattle() {
        // Clear screen with battle background
        ctx.fillStyle = '#505050';
        ctx.fillRect(0, 0, canvas.width, canvas.height);
    
        // Draw Player Creature
        ctx.fillStyle = 'blue';
        ctx.fillRect(100, 300, 64, 64);
        ctx.fillStyle = 'white';
        ctx.fillText(player.creatures[0].name, 100, 290);
        ctx.fillText(`HP: ${player.creatures[0].hp}/${player.creatures[0].maxHp}`, 100, 380);
    
        // Draw Enemy Creature
        ctx.fillStyle = 'red';
        ctx.fillRect(400, 100, 64, 64);
        ctx.fillStyle = 'white';
        ctx.fillText(enemy.name, 400, 90);
        ctx.fillText(`HP: ${enemy.hp}/${enemy.maxHp}`, 400, 190);
    }
    
    // Battle Menu
    function battleMenu() {
        // Display options: Fight, Item, Run
        gameState = 'menu';
        let selection = 0;
        const options = ['Fight', 'Item', 'Run'];
    
        function handleBattleMenuInput(e) {
            if (e.key === 'ArrowUp') {
                selection = (selection + options.length - 1) % options.length;
                drawBattleMenu();
            } else if (e.key === 'ArrowDown') {
                selection = (selection + 1) % options.length;
                drawBattleMenu();
            } else if (e.key === 'Enter') {
                window.removeEventListener('keydown', handleBattleMenuInput);
                executeBattleOption(options[selection]);
            }
        }
    
        window.addEventListener('keydown', handleBattleMenuInput);
    
        function drawBattleMenu() {
            drawBattle();
            ctx.fillStyle = 'black';
            ctx.fillRect(0, 400, 640, 80);
            ctx.fillStyle = 'white';
            options.forEach((option, index) => {
                if (index === selection) {
                    ctx.fillText(`> ${option}`, 50, 430 + index * 20);
                } else {
                    ctx.fillText(option, 70, 430 + index * 20);
                }
            });
        }
    
        drawBattleMenu();
    }
    
    // Execute Battle Option
    function executeBattleOption(option) {
        if (option === 'Fight') {
            // Move Selection
            moveSelectionMenu();
        } else if (option === 'Item') {
            // Item Selection
            itemSelectionMenu();
        } else if (option === 'Run') {
            // Attempt to run
            attemptToRun();
        }
    }
    
    // Move Selection Menu
    function moveSelectionMenu() {
        let selection = 0;
        const moves = player.creatures[0].moves;
    
        function handleMoveSelectionInput(e) {
            if (e.key === 'ArrowUp') {
                selection = (selection + moves.length - 1) % moves.length;
                drawMoveSelectionMenu();
            } else if (e.key === 'ArrowDown') {
                selection = (selection + 1) % moves.length;
                drawMoveSelectionMenu();
            } else if (e.key === 'Enter') {
                window.removeEventListener('keydown', handleMoveSelectionInput);
                performPlayerAttack(moves[selection]);
            }
        }
    
        window.addEventListener('keydown', handleMoveSelectionInput);
    
        function drawMoveSelectionMenu() {
            drawBattle();
            ctx.fillStyle = 'black';
            ctx.fillRect(0, 400, 640, 80);
            ctx.fillStyle = 'white';
            moves.forEach((move, index) => {
                if (index === selection) {
                    ctx.fillText(`> ${move.name}`, 50, 430 + index * 20);
                } else {
                    ctx.fillText(move.name, 70, 430 + index * 20);
                }
            });
        }
    
        drawMoveSelectionMenu();
    }
    
    // Perform Player Attack
    function performPlayerAttack(move) {
        const playerCreature = player.creatures[0];
        const damage = calculateDamage(playerCreature, enemy, move);
        enemy.hp -= damage;
        if (enemy.hp <= 0) {
            enemy.hp = 0;
            endBattle('win');
        } else {
            setTimeout(() => {
                performEnemyAttack();
            }, 1000);
        }
    }
    
    // Perform Enemy Attack
    function performEnemyAttack() {
        const move = enemy.moves[Math.floor(Math.random() * enemy.moves.length)];
        const damage = calculateDamage(enemy, player.creatures[0], move);
        player.creatures[0].hp -= damage;
        if (player.creatures[0].hp <= 0) {
            player.creatures[0].hp = 0;
            endBattle('lose');
        } else {
            // Return to battle menu
            battleMenu();
        }
    }
    
    // Calculate Damage
    function calculateDamage(attacker, defender, move) {
        // STAB
        let damage = move.power;
        if (attacker.type === move.type) {
            damage *= 1.5; // STAB
        }
        // Type effectiveness
        const effectiveness = typesEffectiveness[move.type][defender.type];
        damage *= effectiveness;
        // Random factor
        damage *= (Math.random() * 0.2 + 0.9);
        // Round damage
        damage = Math.round(damage);
        return damage;
    }
    
    // End Battle
    function endBattle(result) {
        if (result === 'win') {
            gameState = 'overworld';
        } else {
            gameState = 'overworld';
            // In a full game, you'd handle game over here
        }
    }
    
    // Item Selection Menu
    function itemSelectionMenu() {
        let selection = 0;
        const items = player.items;
    
        function handleItemSelectionInput(e) {
            if (e.key === 'ArrowUp') {
                selection = (selection + items.length - 1) % items.length;
                drawItemSelectionMenu();
            } else if (e.key === 'ArrowDown') {
                selection = (selection + 1) % items.length;
                drawItemSelectionMenu();
            } else if (e.key === 'Enter') {
                window.removeEventListener('keydown', handleItemSelectionInput);
                useItem(items[selection]);
            }
        }
    
        window.addEventListener('keydown', handleItemSelectionInput);
    
        function drawItemSelectionMenu() {
            drawBattle();
            ctx.fillStyle = 'black';
            ctx.fillRect(0, 400, 640, 80);
            ctx.fillStyle = 'white';
            items.forEach((item, index) => {
                if (index === selection) {
                    ctx.fillText(`> ${item.name} x${item.quantity}`, 50, 430 + index * 20);
                } else {
                    ctx.fillText(`${item.name} x${item.quantity}`, 70, 430 + index * 20);
                }
            });
        }
    
        drawItemSelectionMenu();
    }
    
    // Use Item
    function useItem(item) {
        if (item.effect === 'heal') {
            player.creatures[0].hp += item.amount;
            if (player.creatures[0].hp > player.creatures[0].maxHp) {
                player.creatures[0].hp = player.creatures[0].maxHp;
            }
            item.quantity -= 1;
            if (item.quantity <= 0) {
                player.items.splice(player.items.indexOf(item), 1);
            }
            setTimeout(() => {
                performEnemyAttack();
            }, 1000);
        }
    }
    
    // Attempt to Run
    function attemptToRun() {
        if (Math.random() < 0.5) {
            gameState = 'overworld';
        } else {
            setTimeout(() => {
                performEnemyAttack();
            }, 1000);
        }
    }
    
    // Draw Healing
    function drawHealing() {
        drawOverworld();
        ctx.fillStyle = 'black';
        ctx.fillRect(0, 200, 640, 80);
        ctx.fillStyle = 'white';
        ctx.fillText('Healing your creatures...', 200, 250);
    }
    
    // Heal Creatures
    function healCreatures() {
        player.creatures.forEach(creature => {
            creature.hp = creature.maxHp;
        });
    }
    
    // Start Game Loop
    gameLoop();
    </script>
    </body>
    </html>
    

    Instructions:

    1. Copy the entire code above.
    2. Paste it into a text editor like Notepad or any code editor.
    3. Save the file with a name like game.html.
    4. Open the saved file in a modern web browser (Chrome, Firefox, Edge).

    Controls:

    • Arrow Keys: Move the player character in the overworld.
    • Random Encounters: As you move, you may randomly enter battles.
    • Battle Controls:
      • Use Arrow Up and Arrow Down to navigate menus.
      • Press Enter to select an option.

    Game Features:

    • Overworld: Move around using the arrow keys.
    • Healing Zone: There's a green square on the map representing the healing center. Walking into it will heal your creatures.
    • Battles: Engage in battles with random creatures. Use moves, items, or attempt to run away.
    • Menu System: Navigate through battle options using the keyboard.

    Notes:

    • The game uses simple shapes and text to represent graphics, giving it a retro, 90s feel.
    • All interactions are handled within the game world, and no HTML buttons are used.
    • The code is consolidated into a single HTML file for simplicity.

    Enjoy the game!

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