I'll create a simple browser-based game where a man on a tricycle juggles balls while balancing on a pole. Here's the implementation:
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tricycle Juggler Balance Game</title>
<style>
body {
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: linear-gradient(to bottom, #87CEEB, #98D8C8);
font-family: Arial, sans-serif;
}
#gameContainer {
text-align: center;
}
canvas {
border: 3px solid #333;
background: #fff;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
#score {
font-size: 24px;
margin: 10px;
font-weight: bold;
}
#instructions {
margin: 10px;
font-size: 16px;
}
#gameOver {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background: #4CAF50;
color: white;
border: none;
border-radius: 5px;
margin: 5px;
}
button:hover {
background: #45a049;
}
</style>
</head>
<body>
<div id="gameContainer">
<div id="score">Score: 0</div>
<canvas id="gameCanvas" width="800" height="600"></canvas>
<div id="instructions">Use LEFT/RIGHT arrows to balance • SPACE to juggle</div>
<div id="gameOver">
<h2>Game Over!</h2>
<p id="finalScore">Final Score: 0</p>
<button onclick="resetGame()">Play Again</button>
</div>
</div>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
// Game variables
let score = 0;
let gameRunning = true;
let tilt = 0;
let tiltSpeed = 0;
let jugglePhase = 0;
let balls = [];
let lastJuggleTime = 0;
// Player object
const player = {
x: canvas.width / 2,
y: canvas.height - 150,
width: 60,
height: 80
};
// Pole
const pole = {
x: canvas.width / 2,
y: canvas.height - 50,
width: 10,
height: 100
};
// Initialize balls
function initBalls() {
balls = [
{ x: 0, y: 0, vx: 0, vy: 0, angle: 0 },
{ x: 0, y: 0, vx: 0, vy: 0, angle: 120 },
{ x: 0, y: 0, vx: 0, vy: 0, angle: 240 }
];
}
// Input handling
const keys = {};
document.addEventListener('keydown', (e) => {
keys[e.key] = true;
});
document.addEventListener('keyup', (e) => {
keys[e.key] = false;
});
// Update game state
function update() {
if (!gameRunning) return;
// Handle input
if (keys['ArrowLeft']) {
tiltSpeed -= 0.3;
}
if (keys['ArrowRight']) {
tiltSpeed += 0.3;
}
// Juggle on spacebar
if (keys[' '] && Date.now() - lastJuggleTime > 200) {
jugglePhase += 30;
lastJuggleTime = Date.now();
score += 5;
}
// Apply physics
tiltSpeed *= 0.95; // Friction
tilt += tiltSpeed;
// Add random wind
if (Math.random() < 0.02) {
tiltSpeed += (Math.random() - 0.5) * 0.5;
}
// Check game over
if (Math.abs(tilt) > 30) {
gameOver();
}
// Update juggling balls
balls.forEach((ball, i) => {
ball.angle += 5;
const juggleHeight = 50 + Math.sin((jugglePhase + ball.angle) * Math.PI / 180) * 30;
ball.x = player.x + Math.cos((ball.angle + i * 120) * Math.PI / 180) * 40;
ball.y = player.y - player.height - juggleHeight;
});
// Increment score for staying balanced
if (gameRunning) {
score += 1;
}
}
// Draw everything
function draw() {
// Clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Save context for rotation
ctx.save();
ctx.translate(canvas.width / 2, canvas.height - 50);
ctx.rotate(tilt * Math.PI / 180);
ctx.translate(-canvas.width / 2, -(canvas.height - 50));
// Draw pole
ctx.fillStyle = '#8B4513';
ctx.fillRect(pole.x - pole.width/2, pole.y - pole.height, pole.width, pole.height);
// Draw tricycle
ctx.fillStyle = '#FF0000';
// Body
ctx.fillRect(player.x - 20, player.y - 40, 40, 30);
// Wheels
ctx.beginPath();
ctx.arc(player.x - 15, player.y - 10, 10, 0, Math.PI * 2);
ctx.arc(player.x + 15, player.y - 10, 10, 0, Math.PI * 2);
ctx.arc(player.x, player.y - 5, 8, 0, Math.PI * 2);
ctx.fillStyle = '#333';
ctx.fill();
// Draw person
ctx.fillStyle = '#FFB6C1';
// Head
ctx.beginPath();
ctx.arc(player.x, player.y - 60, 15, 0, Math.PI * 2);
ctx.fill();
// Body
ctx.fillStyle = '#0000FF';
ctx.fillRect(player.x - 10, player.y - 45, 20, 25);
// Draw arms
ctx.strokeStyle = '#FFB6C1';
ctx.lineWidth = 5;
ctx.beginPath();
ctx.moveTo(player.x - 10, player.y - 40);
ctx.lineTo(player.x - 20, player.y - 50);
ctx.moveTo(player.x + 10, player.y - 40);
ctx.lineTo(player.x + 20, player.y - 50);
ctx.stroke();
// Draw juggling balls
balls.forEach(ball => {
ctx.beginPath();
ctx.arc(ball.x, ball.y, 8, 0, Math.PI * 2);
ctx.fillStyle = ['#FF0000', '#00FF00', '#0000FF'][balls.indexOf(ball)];
ctx.fill();
});
ctx.restore();
// Update score display
document.getElementById('score').textContent = `Score: ${score}`;
}
// Game over
function gameOver() {
gameRunning = false;
document.getElementById('finalScore').textContent = `Final Score: ${score}`;
document.getElementById('gameOver').style.display = 'block';
}
// Reset game
function resetGame() {
score = 0;
tilt = 0;
tiltSpeed = 0;
jugglePhase = 0;
gameRunning = true;
initBalls();
document.getElementById('gameOver').style.display = 'none';
}
// Game loop
function gameLoop() {
update();
draw();
requestAnimationFrame(gameLoop);
}
// Start game
initBalls();
gameLoop();
</script>
</body>
</html>
The game gets progressively harder as random wind effects make balancing more challenging. Try to juggle while maintaining balance to maximize your score!