<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mystic Bloom</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
/* ---------- RESET & GLOBAL ---------- */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%;font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;background:#0d0d0d;color:#fff;overflow:hidden}
/* ---------- PARTICLE BACKGROUND ---------- */
#particles{position:fixed;inset:0;z-index:0;pointer-events:none}
.particle{position:absolute;border-radius:50%;background:radial-gradient(circle,#fff 0%,transparent 70%);opacity:.4;animation:float 20s linear infinite}
@keyframes float{
0%{transform:translateY(110vh) scale(.3)}
100%{transform:translateY(-10vh) scale(1)}
}
/* ---------- GAME WRAPPER ---------- */
#gameWrapper{position:relative;z-index:1;display:grid;place-items:center;height:100%;padding:1rem}
#gameArea{
position:relative;
width:min(90vw,600px);
aspect-ratio:1/1;
background:radial-gradient(circle at 50% 50%,#1a1a2e 0%,#0f0f1e 100%);
border-radius:2rem;
box-shadow:0 0 20px #0ff4,0 0 40px #0ff2;
overflow:hidden;
}
/* ---------- PLAYER ---------- */
#player{
position:absolute;
width:40px;
height:40px;
background:radial-gradient(circle,#fff 0%,#0ff 60%,transparent 100%);
border-radius:50%;
box-shadow:0 0 10px #0ff,0 0 20px #0ff;
transition:transform .1s linear;
}
/* ---------- FLOWER ---------- */
.flower{
position:absolute;
width:30px;
height:30px;
background:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="20" fill="%23ff69b4"/><circle cx="50" cy="30" r="15" fill="%23ff69b4"/><circle cx="50" cy="70" r="15" fill="%23ff69b4"/><circle cx="30" cy="50" r="15" fill="%23ff69b4"/><circle cx="70" cy="50" r="15" fill="%23ff69b4"/></svg>') center/contain no-repeat;
animation:pop .4s ease-out forwards;
}
@keyframes pop{
0%{transform:scale(0) rotate(0deg)}
100%{transform:scale(1) rotate(360deg)}
}
.collected{
animation:collect .4s ease-out forwards;
}
@keyframes collect{
0%{transform:scale(1);opacity:1}
100%{transform:scale(2);opacity:0}
}
/* ---------- UI ---------- */
#ui{
position:absolute;
top:1rem;
left:50%;
translate:-50% 0;
display:flex;
gap:1rem;
padding:.5rem 1rem;
background:#0008;
border-radius:1rem;
font-size:1.2rem;
backdrop-filter:blur(4px);
}
/* ---------- OVERLAYS ---------- */
.overlay{
position:absolute;
inset:0;
background:#000a;
display:grid;
place-items:center;
z-index:10;
animation:fadeIn .4s ease-out;
}
@keyframes fadeIn{from{opacity:0}to{opacity:1}}
.overlay.hidden{display:none}
.panel{
background:#111;
padding:2rem 3rem;
border-radius:2xl;
text-align:center;
box-shadow:0 0 20px #0ff4;
}
button{
margin-top:1rem;
padding:.75rem 1.5rem;
border:none;
border-radius:1rem;
background:#0ff;
color:#000;
font-weight:bold;
cursor:pointer;
transition:transform .2s;
}
button:hover{transform:scale(1.05)}
</style>
</head>
<body>
<!-- Particle Background -->
<div id="particles"></div>
<!-- Game Wrapper -->
<div id="gameWrapper">
<div id="gameArea">
<div id="player"></div>
<div id="ui">
<span id="score">Score: 0</span>
<span id="timer">Time: 30</span>
</div>
<!-- Intro Overlay -->
<div id="introOverlay" class="overlay">
<div class="panel">
<h1>Mystic Bloom</h1>
<p>Collect the glowing flowers before time runs out!</p>
<button id="startBtn">Start</button>
</div>
</div>
<!-- Game Over Overlay -->
<div id="gameOverOverlay" class="overlay hidden">
<div class="panel">
<h2>Game Over</h2>
<p id="finalScore">Score: 0</p>
<button id="restartBtn">Restart</button>
</div>
</div>
</div>
</div>
<!-- Audio -->
<audio id="collectSound" src="data:audio/wav;base64,UklGRl9vT19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YU..." preload="auto"></audio>
<audio id="gameOverSound" src="data:audio/wav;base64,UklGRl9vT19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YU..." preload="auto"></audio>
<script>
/* ---------- UTILS ---------- */
const $ = sel => document.querySelector(sel);
const rand = (min,max)=>Math.random()*(max-min)+min;
/* ---------- STATE ---------- */
let score = 0;
let timeLeft = 30;
let gameRunning = false;
let playerPos = {x:0,y:0};
let keys = {};
let flowers = [];
let timerId;
let animFrame;
/* ---------- DOM ---------- */
const gameArea = $('#gameArea');
const player = $('#player');
const scoreEl = $('#score');
const timerEl = $('#timer');
const introOverlay = $('#introOverlay');
const gameOverOverlay = $('#gameOverOverlay');
const startBtn = $('#startBtn');
const restartBtn = $('#restartBtn');
const finalScoreEl = $('#finalScore');
const collectSound = $('#collectSound');
const gameOverSound = $('#gameOverSound');
/* ---------- PARTICLES ---------- */
function createParticles(){
for(let i=0;i<30;i++){
const p = document.createElement('div');
p.className='particle';
p.style.left = rand(0,100)+'vw';
p.style.width = p.style.height = rand(2,6)+'px';
p.style.animationDuration = rand(10,30)+'s';
p.style.animationDelay = rand(0,30)+'s';
$('#particles').appendChild(p);
}
}
createParticles();
/* ---------- PLAYER MOVEMENT ---------- */
function updatePlayer(){
const speed = 5;
if(keys['ArrowUp'] || keys['w']) playerPos.y = Math.max(0,playerPos.y-speed);
if(keys['ArrowDown'] || keys['s']) playerPos.y = Math.min(gameArea.clientHeight-40,playerPos.y+speed);
if(keys['ArrowLeft'] || keys['a']) playerPos.x = Math.max(0,playerPos.x-speed);
if(keys['ArrowRight'] || keys['d']) playerPos.x = Math.min(gameArea.clientWidth-40,playerPos.x+speed);
player.style.transform = `translate(${playerPos.x}px,${playerPos.y}px)`;
}
/* ---------- FLOWER SPAWNING ---------- */
function spawnFlower(){
const flower = document.createElement('div');
flower.className='flower';
const x = rand(0,gameArea.clientWidth-30);
const y = rand(0,gameArea.clientHeight-30);
flower.style.left = x+'px';
flower.style.top = y+'px';
gameArea.appendChild(flower);
flowers.push({el:flower,x,y});
}
/* ---------- COLLISION ---------- */
function checkCollisions(){
flowers.forEach((f,i)=>{
const dx = (playerPos.x+20)-(f.x+15);
const dy = (playerPos.y+20)-(f.y+15);
if(Math.hypot(dx,dy)<25){
f.el.classList.add('collected');
setTimeout(()=>f.el.remove(),400);
flowers.splice(i,1);
score++;
scoreEl.textContent = `Score: ${score}`;
collectSound.currentTime=0;
collectSound.play().catch(()=>{});
}
});
}
/* ---------- GAME LOOP ---------- */
function gameLoop(){
if(!gameRunning) return;
updatePlayer();
checkCollisions();
animFrame = requestAnimationFrame(gameLoop);
}
/* ---------- TIMER ---------- */
function startTimer(){
timerId = setInterval(()=>{
timeLeft--;
timerEl.textContent = `Time: ${timeLeft}`;
if(timeLeft<=0) endGame();
},1000);
}
/* ---------- START / END ---------- */
function startGame(){
introOverlay.classList.add('hidden');
score=0;timeLeft=30;
scoreEl.textContent='Score: 0';
timerEl.textContent='Time: 30';
playerPos={x:gameArea.clientWidth/2-20,y:gameArea.clientHeight/2-20};
player.style.transform=`translate(${playerPos.x}px,${playerPos.y}px)`;
gameRunning=true;
startTimer();
gameLoop();
// spawn flowers periodically
const spawnInterval = setInterval(()=>{
if(!gameRunning){clearInterval(spawnInterval);return}
if(flowers.length<5) spawnFlower();
},1500);
}
function endGame(){
gameRunning=false;
clearInterval(timerId);
cancelAnimationFrame(animFrame);
flowers.forEach(f=>f.el.remove());
flowers=[];
finalScoreEl.textContent=`Score: ${score}`;
gameOverOverlay.classList.remove('hidden');
gameOverSound.play().catch(()=>{});
}
/* ---------- EVENTS ---------- */
window.addEventListener('keydown',e=>keys[e.key]=true);
window.addEventListener('keyup',e=>keys[e.key]=false);
// Touch controls
let touchStartX,touchStartY;
gameArea.addEventListener('touchstart',e=>{
const t=e.touches[0];
touchStartX=t.clientX;
touchStartY=t.clientY;
});
gameArea.addEventListener('touchmove',e=>{
if(!gameRunning)return;
const t=e.touches[0];
const dx = t.clientX-touchStartX;
const dy = t.clientY-touchStartY;
playerPos.x = Math.max(0,Math.min(gameArea.clientWidth-40,playerPos.x+dx/5));
playerPos.y = Math.max(0,Math.min(gameArea.clientHeight-40,playerPos.y+dy/5));
touchStartX=t.clientX;
touchStartY=t.clientY;
});
startBtn.addEventListener('click',startGame);
restartBtn.addEventListener('click',()=>{
gameOverOverlay.classList.add('hidden');
startGame();
});
</script>
</body>
</html>