Etta: Mushrooms 2

by whelkaholism

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Move the Mushroom Character</title>
    <style>
        body {
            margin: 0;
            overflow: hidden;
        }

        #gameArea {
            position: relative;
            width: 100vw;
            height: 100vh;
            background-color: #87CEEB; /* Light sky blue */
        }

        .redCircle {
            position: absolute;
            width: 30px;
            height: 30px;
            background-color: red;
            border-radius: 50%;
        }

        #character {
            position: absolute;
            width: 100px;   /* Fixed width */
            height: 115px;  /* Fixed height */
            background-image: url('https://cfront.co.uk/images/mushroomai.png');
            background-size: cover;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        #score {
            position: absolute;
            top: 20px;
            left: 20px;
            font-size: 24px;
            color: white;
            background-color: rgba(0, 0, 0, 0.5);
            padding: 10px;
            border-radius: 5px;
        }
    </style>
</head>
<body>
    <div id="gameArea">
        <div id="character"></div>
        <div id="score">Apples Collected: 0</div>
    </div>

    <script>
        const character = document.getElementById('character');
        const scoreDisplay = document.getElementById('score');
        let positionX = window.innerWidth / 2 - 50; // Initial X position (centered, based on width)
        let positionY = window.innerHeight / 2 - 57.5; // Initial Y position (centered, based on height)
        const speed = 10; // Movement speed
        let apples = []; // Array to store the apple elements
        let applesCollected = 0; // Counter for apples collected

        // Randomly generate red circles (apples) in the...