Below is a complete, self-contained HTML file for a “Cat Laser Pointer” mini-game.
Just paste the code into an .html file and open it in a browser―no additional libs needed.
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cat Laser Pointer Mini-Game</title>
<style>
html,body{
margin:0;padding:0;
background:#111;
overflow:hidden;
cursor:none; /* hide system cursor – we’ll draw a laser dot */
user-select:none;
}
canvas{display:block;}
/* Simple HUD */
#hud{
position:fixed;
top:10px;left:50%;
transform:translateX(-50%);
font-family:Verdana,Arial,sans-serif;
text-align:center;
color:#fff;
pointer-events:none;
}
#level{font-size:28px;opacity:.3;transition:opacity .4s;}
#score{font-size:16px;margin-top:4px;}
</style>
</head>
<body>
<canvas id="game"></canvas>
<div id="hud">
<div id="level">Level 1</div>
<div id="score">Catches: 0</div>
</div>
<script>
/* -------------------------------------------------- */
/* =============== SETUP & RESIZING =============== */
const canvas = document.getElementById('game');
const ctx = canvas.getContext('2d');
function fit() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', fit); fit();
/* -------------------------------------------------- */
/* ================= GAME STATE =================== */
const pointer = {x: canvas.width/2, y: canvas.height/2}; // laser dot
const cat = {x: Math.random()*canvas.width,
y: Math.random()*canvas.height,
angle:0};
let level = 1;
let score = 0;
const catchesPerLevel = 5;
const maxLevel = 10;
const baseSpeed = 100; // px / sec
const frameDuration = 0.12; // sprite animation
/* -------------------------------------------------- */
/* =============== SPRITE HANDLING ================ */
const catImg = new Image();
/* 96×32 sprite-sheet (3 frames) sourced from Kenney.nl, re-hosted on imgur for CORS-friendly demo */
catImg.src = "https://i.imgur.com/v4f6wYL.png";
const SPR_W = 32, SPR_H = 32;
let frame = 0, frameTimer = 0;
/* -------------------------------------------------- */
/* ================= INPUT (MOUSE) ================ */
window.addEventListener('mousemove', e=>{
pointer.x = e.clientX;
pointer.y = e.clientY;
});
/* -------------------------------------------------- */
/* ================= MAIN LOOP ==================== */
let lastTime = 0;
requestAnimationFrame(loop);
function loop(ts){
if(!lastTime) lastTime = ts;
const dt = (ts-lastTime)/1000; // delta-time in seconds
lastTime = ts;
update(dt);
draw();
requestAnimationFrame(loop);
}
/* -------------------------------------------------- */
/* ================== UPDATE ====================== */
function update(dt){
/* ---- Cat movement ---- */
const dx = pointer.x - cat.x;
const dy = pointer.y - cat.y;
const dist = Math.hypot(dx,dy);
cat.angle = Math.atan2(dy,dx);
const speed = baseSpeed + (level-1)*60; // accelerate per level
if(dist>1){ // avoid jitter
cat.x += (dx/dist)*speed*dt;
cat.y += (dy/dist)*speed*dt;
}
/* ---- Collision / Catch ---- */
if(dist < 20){
score++;
document.getElementById('score').textContent = "Catches: "+score;
// Teleport cat somewhere random (makes it feel like it "pounced")
cat.x = Math.random()*canvas.width;
cat.y = Math.random()*canvas.height;
// Level progression
if(score % catchesPerLevel === 0 && level < maxLevel){
level++;
flashLevel();
}
}
/* ---- Animate cat sprite ---- */
frameTimer += dt;
if(frameTimer > frameDuration){
frame = (frame + 1) % 3;
frameTimer = 0;
}
}
/* Little level-up flash */
function flashLevel(){
const lvlEl = document.getElementById('level');
lvlEl.textContent = "Level "+level;
lvlEl.style.opacity = 1;
setTimeout(()=>lvlEl.style.opacity = 0.3, 1500);
}
/* -------------------------------------------------- */
/* ==================== DRAW ====================== */
function draw(){
ctx.clearRect(0,0,canvas.width,canvas.height);
/* --- Laser dot (pulsing) --- */
const pulse = 6 + Math.sin(performance.now()/200)*3;
ctx.save();
ctx.shadowColor = "red";
ctx.shadowBlur = 18;
ctx.fillStyle = "red";
ctx.beginPath();
ctx.arc(pointer.x, pointer.y, pulse, 0, Math.PI*2);
ctx.fill();
ctx.restore();
/* --- Cat sprite --- */
if(catImg.complete){
ctx.save();
ctx.translate(cat.x, cat.y);
ctx.rotate(cat.angle + Math.PI/2); // rotate so sprite faces pointer
ctx.drawImage(catImg,
frame*SPR_W, 0, SPR_W, SPR_H, // source rect
-SPR_W/2, -SPR_H/2, SPR_W, SPR_H); // destination rect
ctx.restore();
}else{
// Fallback placeholder if image not loaded yet
ctx.fillStyle="#fff";
ctx.beginPath();
ctx.arc(cat.x, cat.y, 16, 0, Math.PI*2);
ctx.fill();
}
}
</script>
</body>
</html>
What you get
• Smooth laser-pointer controlled by your actual mouse position.
• A sprite-animated cat that rotates to face the laser and pounces toward it.
• Pulsing red laser-dot with glow.
• Level progression every 5 catches (speed ramps up, little HUD flash).
• Runs everywhere (mobile too – just change mousemove to touchmove if needed).
Feel free to remix
• Swap in your own sprite-sheet (just adjust SPR_W/SPR_H and frame count).
• Add sound effects (mew.wav on catch, laser “zap” on move).
• Introduce obstacles or multiple cats for chaos mode.
• Add a timer, high-score board, or “lives.”
Have fun batting that laser around! 😸🎮