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

Use html with cdn packages to make a game called "squirrel finder": - You are a koala…

  1. User

    Use html with cdn packages to make a game called "squirrel finder":

    • You are a koala icon that can move quickly using the arrow keys. The icon image is koa la. png
    • A strawberry randomly spawns every second and bounces around. The icon image is strawberry . png
    • If a strawberry touches you, you die.
    • After three seconds, a squirrel icon spawns and bounces around. The icon image is squirrel. png. If you touch it, you win.
    • Make sure all icons are 40 pixels by 40 pixels.
    • Use retro colors and a dark background.
    • Put "openai" in the game screen and a timer in the corner.
    • Display the instructions before the game starts.
    • Automatically restart the game when you win or lose.
    • Give the code in a single file.

    make the icons required if they arent found, svg's that you make

  2. Assistant

    Here is the code for the "Squirrel Finder" game as per your specifications. Save this code in a file with the .html extension and open it in a web browser to play the game.

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>Squirrel Finder</title>
        <!-- Include p5.js from CDN -->
        <script src="https://cdn.jsdelivr.net/npm/p5@1.6.0/lib/p5.min.js"></script>
        <style>
            body {
                margin: 0;
                overflow: hidden;
                background-color: #000; /* Dark background */
                color: #fff; /* Retro color for text */
                font-family: 'Press Start 2P', cursive;
            }
            #instructions {
                position: absolute;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                text-align: center;
                background-color: #000;
                padding: 20px;
                border: 2px solid #fff;
                z-index: 10;
            }
            #timer {
                position: absolute;
                top: 10px;
                right: 10px;
                font-size: 20px;
                z-index: 10;
            }
            @font-face {
                font-family: 'Press Start 2P';
                font-style: normal;
                font-weight: 400;
                src: local('Press Start 2P'), local('PressStart2P'),
                    url(https://fonts.gstatic.com/s/pressstart2p/v11/e3t4euO8mAlZQE0jebZkMk7UjFFsYUFrGng.woff2) format('woff2');
            }
        </style>
    </head>
    <body>
        <div id="instructions">
            <h1>Squirrel Finder</h1>
            <p>You are the Koala. Use arrow keys to move quickly.</p>
            <p>Avoid the bouncing strawberries that spawn every second.</p>
            <p>After three seconds, a squirrel will appear. Touch it to win!</p>
            <p>If a strawberry touches you, you die.</p>
            <button id="start-button">Start Game</button>
        </div>
        <div id="timer">Time: 0</div>
    
        <script>
            let player;
            let strawberries = [];
            let squirrel;
            let gameStarted = false;
            let gameOver = false;
            let gameWon = false;
            let timeElapsed = 0;
            let gameWidth = window.innerWidth;
            let gameHeight = window.innerHeight;
    
            let playerImg, strawberryImg, squirrelImg;
    
            function preload() {
                // Try to load images, if not found, create SVGs
                playerImg = loadImage('koala.png', img => {}, err => {
                    playerImg = createKoalaSVG();
                });
                strawberryImg = loadImage('strawberry.png', img => {}, err => {
                    strawberryImg = createStrawberrySVG();
                });
                squirrelImg = loadImage('squirrel.png', img => {}, err => {
                    squirrelImg = createSquirrelSVG();
                });
            }
    
            function setup() {
                createCanvas(gameWidth, gameHeight);
                textFont('Press Start 2P');
                textSize(20);
                fill(255);
    
                player = new Player();
                setInterval(() => {
                    if (gameStarted && !gameOver && !gameWon) {
                        strawberries.push(new Strawberry());
                    }
                }, 1000);
    
                setTimeout(() => {
                    if (gameStarted && !gameOver && !gameWon) {
                        squirrel = new Squirrel();
                    }
                }, 3000);
    
                setInterval(() => {
                    if (gameStarted && !gameOver && !gameWon) {
                        timeElapsed++;
                        document.getElementById('timer').innerText = `Time: ${timeElapsed}`;
                    }
                }, 1000);
            }
    
            function draw() {
                if (gameStarted) {
                    background(0);
    
                    // Display "openai" in the game screen
                    text('openai', 10, gameHeight - 20);
    
                    player.update();
                    player.show();
    
                    if (squirrel) {
                        squirrel.update();
                        squirrel.show();
    
                        if (player.hits(squirrel)) {
                            gameWon = true;
                            gameOver = true;
                            setTimeout(restartGame, 2000);
                        }
                    }
    
                    for (let s of strawberries) {
                        s.update();
                        s.show();
    
                        if (player.hits(s)) {
                            gameOver = true;
                            setTimeout(restartGame, 2000);
                        }
                    }
    
                    if (gameWon) {
                        textAlign(CENTER);
                        text('You Win!', gameWidth / 2, gameHeight / 2);
                    } else if (gameOver) {
                        textAlign(CENTER);
                        text('Game Over', gameWidth / 2, gameHeight / 2);
                    }
                }
            }
    
            function keyPressed() {
                if (!gameOver) {
                    if (keyCode === UP_ARROW) {
                        player.move(0, -10);
                    } else if (keyCode === DOWN_ARROW) {
                        player.move(0, 10);
                    } else if (keyCode === LEFT_ARROW) {
                        player.move(-10, 0);
                    } else if (keyCode === RIGHT_ARROW) {
                        player.move(10, 0);
                    }
                }
            }
    
            function restartGame() {
                gameStarted = false;
                gameOver = false;
                gameWon = false;
                timeElapsed = 0;
                strawberries = [];
                squirrel = null;
                player = new Player();
                document.getElementById('instructions').style.display = 'block';
                document.getElementById('timer').innerText = 'Time: 0';
            }
    
            document.getElementById('start-button').addEventListener('click', () => {
                gameStarted = true;
                document.getElementById('instructions').style.display = 'none';
            });
    
            // Player class
            class Player {
                constructor() {
                    this.x = gameWidth / 2;
                    this.y = gameHeight / 2;
                    this.r = 20;
                }
    
                move(xdir, ydir) {
                    this.x += xdir;
                    this.y += ydir;
    
                    // Keep player within the canvas
                    this.x = constrain(this.x, 0, gameWidth - this.r);
                    this.y = constrain(this.y, 0, gameHeight - this.r);
                }
    
                update() {
                    // Additional physics or updates can be added here
                }
    
                show() {
                    image(playerImg, this.x, this.y, this.r * 2, this.r * 2);
                }
    
                hits(other) {
                    let d = dist(this.x, this.y, other.x, other.y);
                    return d < this.r + other.r;
                }
            }
    
            // Strawberry class
            class Strawberry {
                constructor() {
                    this.x = random(gameWidth);
                    this.y = random(gameHeight);
                    this.r = 20;
                    this.xspeed = random([-5, 5]);
                    this.yspeed = random([-5, 5]);
                }
    
                update() {
                    this.x += this.xspeed;
                    this.y += this.yspeed;
    
                    if (this.x < 0 || this.x > gameWidth - this.r * 2) {
                        this.xspeed *= -1;
                    }
    
                    if (this.y < 0 || this.y > gameHeight - this.r * 2) {
                        this.yspeed *= -1;
                    }
                }
    
                show() {
                    image(strawberryImg, this.x, this.y, this.r * 2, this.r * 2);
                }
            }
    
            // Squirrel class
            class Squirrel {
                constructor() {
                    this.x = random(gameWidth);
                    this.y = random(gameHeight);
                    this.r = 20;
                    this.xspeed = random([-5, 5]);
                    this.yspeed = random([-5, 5]);
                }
    
                update() {
                    this.x += this.xspeed;
                    this.y += this.yspeed;
    
                    if (this.x < 0 || this.x > gameWidth - this.r * 2) {
                        this.xspeed *= -1;
                    }
    
                    if (this.y < 0 || this.y > gameHeight - this.r * 2) {
                        this.yspeed *= -1;
                    }
                }
    
                show() {
                    image(squirrelImg, this.x, this.y, this.r * 2, this.r * 2);
                }
            }
    
            // Functions to create SVGs if images not found
            function createKoalaSVG() {
                let gfx = createGraphics(40, 40);
                gfx.background(0, 0); // Transparent background
                gfx.fill('#B5651D'); // Brown color for koala
                gfx.ellipse(20, 20, 40, 40);
                gfx.fill('#fff');
                gfx.ellipse(14, 15, 10, 10);
                gfx.ellipse(26, 15, 10, 10);
                gfx.fill('#000');
                gfx.ellipse(14, 15, 5, 5);
                gfx.ellipse(26, 15, 5, 5);
                return gfx;
            }
    
            function createStrawberrySVG() {
                let gfx = createGraphics(40, 40);
                gfx.background(0, 0);
                gfx.fill('#FF0000'); // Red color for strawberry
                gfx.triangle(20, 5, 35, 35, 5, 35);
                gfx.fill('#008000'); // Green color for leaves
                gfx.rect(17, 0, 6, 10);
                return gfx;
            }
    
            function createSquirrelSVG() {
                let gfx = createGraphics(40, 40);
                gfx.background(0, 0);
                gfx.fill('#A0522D'); // Sienna color for squirrel
                gfx.ellipse(20, 20, 30, 20);
                gfx.circle(25, 15, 10);
                gfx.fill('#fff');
                gfx.circle(23, 13, 5);
                gfx.fill('#000');
                gfx.circle(23, 13, 2);
                gfx.fill('#A0522D');
                gfx.triangle(20, 20, 35, 25, 35, 15);
                return gfx;
            }
        </script>
    </body>
    </html>
    

    Instructions to Run the Game:

    1. Copy the entire code above into a text editor.
    2. Save the file with a name like squirrel_finder.html.
    3. Open the saved HTML file in a modern web browser (e.g., Chrome, Firefox).
    4. Read the instructions displayed and click the "Start Game" button to begin.
    5. Use the arrow keys on your keyboard to move the Koala quickly.
    6. Avoid the bouncing strawberries that spawn every second.
    7. After three seconds, a squirrel will appear. Touch it to win!
    8. If a strawberry touches you, you lose, and the game will restart automatically.
    9. The game will also restart automatically when you win.

    Game Features:

    • Retro colors with a dark background.
    • All icons are 40x40 pixels in size.
    • "openai" text displayed in the game screen.
    • Timer displayed in the top-right corner.
    • Instructions displayed before the game starts.
    • Game restarts automatically upon winning or losing.
    • Icons are created using SVGs if the image files are not found.

    Note: If you have the image files (koala.png, strawberry.png, squirrel.png), place them in the same directory as the HTML file to use them. If not, the game will use the SVG graphics created within the code.