<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mystic Bloom</title>
<style>
/* Reset and base styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
overflow: hidden;
position: relative;
}
/* Animated background particles */
.particles {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 1;
}
.particle {
position: absolute;
width: 4px;
height: 4px;
background: rgba(255, 255, 255, 0.3);
border-radius: 50%;
animation: float 6s infinite ease-in-out;
}
@keyframes float {
0%, 100% { transform: translateY(0px) rotate(0deg); opacity: 0.3; }
50% { transform: translateY(-20px) rotate(180deg); opacity: 0.8; }
}
/* Main game container */
.game-container {
position: relative;
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 2;
padding: 1rem;
}
/* Game area */
.game-area {
position: relative;
width: min(90vw, 800px);
height: min(70vh, 600px);
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 2rem;
border: 2px solid rgba(255, 255, 255, 0.2);
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
overflow: hidden;
padding: 1rem;
}
/* UI Panel */
.ui-panel {
position: absolute;
top: 1rem;
left: 1rem;
right: 1rem;
display: flex;
justify-content: space-between;
align-items: center;
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(10px);
padding: 1rem 1.5rem;
border-radius: 1rem;
border: 1px solid rgba(255, 255, 255, 0.2);
z-index: 10;
}
.score, .timer {
color: white;
font-size: 1.2rem;
font-weight: 600;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
/* Player orb */
.player {
position: absolute;
width: 40px;
height: 40px;
background: radial-gradient(circle, #ffd700, #ffed4e);
border-radius: 50%;
box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
transition: all 0.1s ease;
z-index: 5;
}
.player::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 60px;
height: 60px;
background: radial-gradient(circle, rgba(255, 215, 0, 0.3), transparent);
border-radius: 50%;
animation: pulse 2s infinite ease-in-out;
}
@keyframes pulse {
0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.7; }
50% { transform: translate(-50%, -50%) scale(1.2); opacity: 0.3; }
}
/* Flower collectibles */
.flower {
position: absolute;
width: 30px;
height: 30px;
z-index: 3;
animation: bloom 0.5s ease-out, sparkle 3s infinite ease-in-out;
}
@keyframes bloom {
0% { transform: scale(0) rotate(0deg); opacity: 0; }
100% { transform: scale(1) rotate(360deg); opacity: 1; }
}
@keyframes sparkle {
0%, 100% { filter: brightness(1) hue-rotate(0deg); }
50% { filter: brightness(1.3) hue-rotate(30deg); }
}
/* Collection animation */
.collected {
animation: collect 0.5s ease-out forwards;
}
@keyframes collect {
0% { transform: scale(1); opacity: 1; }
100% { transform: scale(2) translateY(-30px); opacity: 0; }
}
/* Overlays */
.overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 20;
border-radius: 2rem;
}
.overlay h1 {
color: white;
font-size: 3rem;
margin-bottom: 1rem;
text-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
animation: glow 2s infinite ease-in-out alternate;
}
@keyframes glow {
0% { text-shadow: 0 4px 8px rgba(0, 0, 0, 0.5), 0 0 20px rgba(255, 255, 255, 0.3); }
100% { text-shadow: 0 4px 8px rgba(0, 0, 0, 0.5), 0 0 30px rgba(255, 255, 255, 0.6); }
}
.overlay p {
color: rgba(255, 255, 255, 0.8);
font-size: 1.2rem;
margin-bottom: 2rem;
text-align: center;
max-width: 400px;
}
.btn {
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
border: none;
padding: 1rem 2rem;
border-radius: 1rem;
font-size: 1.1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
.btn:active {
transform: translateY(0);
}
/* Instructions */
.instructions {
position: absolute;
bottom: 1rem;
left: 50%;
transform: translateX(-50%);
color: rgba(255, 255, 255, 0.7);
text-align: center;
font-size: 0.9rem;
}
/* Mobile responsiveness */
@media (max-width: 768px) {
.overlay h1 {
font-size: 2rem;
}
.ui-panel {
padding: 0.75rem 1rem;
}
.score, .timer {
font-size: 1rem;
}
.player {
width: 35px;
height: 35px;
}
.flower {
width: 25px;
height: 25px;
}
}
/* Hidden class for overlays */
.hidden {
display: none;
}
</style>
</head>
<body>
<!-- Background particles -->
<div class="particles" id="particles"></div>
<!-- Main game container -->
<div class="game-container">
<div class="game-area" id="gameArea">
<!-- UI Panel -->
<div class="ui-panel">
<div class="score">Score: <span id="scoreValue">0</span></div>
<div class="timer">Time: <span id="timeValue">60</span>s</div>
</div>
<!-- Player orb -->
<div class="player" id="player"></div>
<!-- Start overlay -->
<div class="overlay" id="startOverlay">
<h1>Mystic Bloom</h1>
<p>Guide your glowing orb to collect magical flowers before time runs out!</p>
<button class="btn" id="startBtn">Start Game</button>
<div class="instructions">
Use arrow keys or touch to move • Collect flowers to score points
</div>
</div>
<!-- Game over overlay -->
<div class="overlay hidden" id="gameOverOverlay">
<h1>Game Over</h1>
<p>Final Score: <span id="finalScore">0</span></p>
<button class="btn" id="restartBtn">Play Again</button>
</div>
</div>
</div>
<script>
// Game state and configuration
const gameState = {
isPlaying: false,
score: 0,
timeLeft: 60,
player: { x: 0, y: 0 },
flowers: [],
keys: {},
gameLoop: null,
spawnTimer: 0,
touchStart: null
};
// DOM elements
const elements = {
gameArea: document.getElementById('gameArea'),
player: document.getElementById('player'),
scoreValue: document.getElementById('scoreValue'),
timeValue: document.getElementById('timeValue'),
startOverlay: document.getElementById('startOverlay'),
gameOverOverlay: document.getElementById('gameOverOverlay'),
startBtn: document.getElementById('startBtn'),
restartBtn: document.getElementById('restartBtn'),
finalScore: document.getElementById('finalScore'),
particles: document.getElementById('particles')
};
// Audio context for sound effects (base64 encoded)
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
// Create sound effects
const createBeep = (frequency, duration, type = 'sine') => {
const oscillator = audioContext.createOscillator();
const gainNode = audioContext.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioContext.destination);
oscillator.frequency.value = frequency;
oscillator.type = type;
gainNode.gain.setValueAtTime(0.3, audioContext.currentTime);
gainNode.gain.exponentialRampToValueAtTime(0.01, audioContext.currentTime + duration);
oscillator.start(audioContext.currentTime);
oscillator.stop(audioContext.currentTime + duration);
};
// Initialize background particles
const initParticles = () => {
for (let i = 0; i < 20; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
particle.style.left = Math.random() * 100 + '%';
particle.style.top = Math.random() * 100 + '%';
particle.style.animationDelay = Math.random() * 6 + 's';
particle.style.animationDuration = (4 + Math.random() * 4) + 's';
elements.particles.appendChild(particle);
}
};
// Initialize player position
const initPlayer = () => {
const gameRect = elements.gameArea.getBoundingClientRect();
gameState.player.x = gameRect.width / 2 - 20;
gameState.player.y = gameRect.height / 2 - 20;
updatePlayerPosition();
};
// Update player visual position
const updatePlayerPosition = () => {
elements.player.style.left = gameState.player.x + 'px';
elements.player.style.top = gameState.player.y + 'px';
};
// Create flower SVG
const createFlowerSVG = () => {
const colors = ['#ff6b6b', '#4ecdc4', '#45b7d1', '#96ceb4', '#feca57', '#ff9ff3'];
const color = colors[Math.floor(Math.random() * colors.length)];
return `
<svg width="30" height="30" viewBox="0 0 30 30">
<g transform="translate(15,15)">
<circle cx="0" cy="-8" r="4" fill="${color}" opacity="0.8"/>
<circle cx="6" cy="-4" r="4" fill="${color}" opacity="0.8"/>
<circle cx="6" cy="4" r="4" fill="${color}" opacity="0.8"/>
<circle cx="0" cy="8" r="4" fill="${color}" opacity="0.8"/>
<circle cx="-6" cy="4" r="4" fill="${color}" opacity="0.8"/>
<circle cx="-6" cy="-4" r="4" fill="${color}" opacity="0.8"/>
<circle cx="0" cy="0" r="3" fill="#ffd700"/>
</g>
</svg>
`;
};
// Spawn a new flower
const spawnFlower = () => {
const gameRect = elements.gameArea.getBoundingClientRect();
const flower = document.createElement('div');
flower.className = 'flower';
flower.innerHTML = createFlowerSVG();
// Random position avoiding UI panel area
flower.style.left = Math.random() * (gameRect.width - 60) + 30 + 'px';
flower.style.top = Math.random() * (gameRect.height - 120) + 80 + 'px';
elements.gameArea.appendChild(flower);
gameState.flowers.push(flower);
};
// Check collision between player and flowers
const checkCollisions = () => {
const playerRect = elements.player.getBoundingClientRect();
gameState.flowers.forEach((flower, index) => {
const flowerRect = flower.getBoundingClientRect();
if (playerRect.left < flowerRect.right &&
playerRect.right > flowerRect.left &&
playerRect.top < flowerRect.bottom &&
playerRect.bottom > flowerRect.top) {
// Collision detected
collectFlower(flower, index);
}
});
};
// Collect a flower
const collectFlower = (flower, index) => {
flower.classList.add('collected');
gameState.score += 10;
elements.scoreValue.textContent = gameState.score;