I'll create an Avatar: The Last Airbender bending arcade game using HTML5 Canvas and JavaScript. This will be a complete game where you can play as different benders and use their abilities against enemies.
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>Avatar Bending Arena</title>
<style>
body {
margin: 0;
padding: 20px;
background: linear-gradient(135deg, #1e3c72, #2a5298);
font-family: 'Arial', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
color: white;
}
canvas {
border: 3px solid #fff;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0,0,0,0.5);
background: linear-gradient(to bottom, #87CEEB, #98FB98);
}
.controls {
margin-top: 20px;
text-align: center;
}
.bender-select {
margin: 10px;
padding: 10px 20px;
border: none;
border-radius: 5px;
background: #ff6b35;
color: white;
cursor: pointer;
font-size: 16px;
transition: all 0.3s;
}
.bender-select:hover {
background: #ff8c42;
transform: scale(1.05);
}
.bender-select.active {
background: #28a745;
}
.instructions {
margin-top: 15px;
max-width: 600px;
text-align: center;
line-height: 1.6;
}
.score {
font-size: 24px;
font-weight: bold;
margin-top: 10px;
}
</style>
</head>
<body>
<h1>🔥 Avatar Bending Arena 🌊</h1>
<canvas id="gameCanvas" width="800" height="600"></canvas>
<div class="controls">
<button class="bender-select active" onclick="selectBender('fire')">🔥 Firebender</button>
<button class="bender-select" onclick="selectBender('water')">🌊 Waterbender</button>
<button class="bender-select" onclick="selectBender('earth')">🗿 Earthbender</button>
<button class="bender-select" onclick="selectBender('air')">💨 Airbender</button>
</div>
<div class="score" id="score">Score: 0</div>
<div class="instructions">
<strong>Controls:</strong> Use WASD to move, SPACE to bend/attack, R to use special ability<br>
<strong>Goal:</strong> Defeat enemies using your bending abilities! Each element has unique powers.
</div>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
// Game state
let gameState = {
player: null,
enemies: [],
projectiles: [],
particles: [],
score: 0,
keys: {},
currentBender: 'fire',
lastAttack: 0,
lastSpecial: 0
};
// Input handling
document.addEventListener('keydown', (e) => {
gameState.keys[e.key.toLowerCase()] = true;
});
document.addEventListener('keyup', (e) => {
gameState.keys[e.key.toLowerCase()] = false;
});
// Bender selection
function selectBender(type) {
gameState.currentBender = type;
initPlayer();
// Update button styles
document.querySelectorAll('.bender-select').forEach(btn => {
btn.classList.remove('active');
});
event.target.classList.add('active');
}
// Player class
class Player {
constructor(x, y, benderType) {
this.x = x;
this.y = y;
this.width = 40;
this.height = 40;
this.speed = 5;
this.benderType = benderType;
this.health = 100;
this.maxHealth = 100;
}
update() {
// Movement
if (gameState.keys['a'] && this.x > 0) this.x -= this.speed;
if (gameState.keys['d'] && this.x < canvas.width - this.width) this.x += this.speed;
if (gameState.keys['w'] && this.y > 0) this.y -= this.speed;
if (gameState.keys['s'] && this.y < canvas.height - this.height) this.y += this.speed;
// Attack
if (gameState.keys[' '] && Date.now() - gameState.lastAttack > 300) {
this.attack();
gameState.lastAttack = Date.now();
}
// Special ability
if (gameState.keys['r'] && Date.now() - gameState.lastSpecial > 2000) {
this.special();
gameState.lastSpecial = Date.now();
}
}
attack() {
const centerX = this.x + this.width / 2;
const centerY = this.y + this.height / 2;
switch (this.benderType) {
case 'fire':
// Fire blast
gameState.projectiles.push(new Projectile(
centerX, centerY, 8, 0, 'fire', '#ff4500', 15
));
break;
case 'water':
// Water whip
for (let i = -1; i <= 1; i++) {
gameState.projectiles.push(new Projectile(
centerX, centerY, 6, i * 2, 'water', '#00bfff', 12
));
}
break;
case 'earth':
// Rock projectile
gameState.projectiles.push(new Projectile(
centerX, centerY, 5, 0, 'earth', '#8b4513', 20
));
break;
case 'air':
// Air blast
for (let i = 0; i < 5; i++) {
gameState.projectiles.push(new Projectile(
centerX, centerY, 7 + Math.random() * 2,
(Math.random() - 0.5) * 4, 'air', '#e6e6fa', 8
));
}
break;
}
}
special() {
const centerX = this.x + this.width / 2;
const centerY = this.y + this.height / 2;
switch (this.benderType) {
case 'fire':
// Fire tornado
for (let angle = 0; angle < 360; angle += 30) {
const rad = angle * Math.PI / 180;
gameState.projectiles.push(new Projectile(
centerX, centerY,
Math.cos(rad) * 6, Math.sin(rad) * 6,
'fire', '#ff6600', 25
));
}
break;
case 'water':
// Healing wave
this.health = Math.min(this.maxHealth, this.health + 30);
for (let i = 0; i < 20; i++) {
gameState.particles.push(new Particle(
centerX + (Math.random() - 0.5) * 100,
centerY + (Math.random() - 0.5) * 100,
'#00ffff', 60
));
}
break;
case 'earth':
// Earthquake
gameState.enemies.forEach(enemy => {
const dist = Math.sqrt(
Math.pow(enemy.x - centerX, 2) +
Math.pow(enemy.y - centerY, 2)
);
if (dist < 150) {
enemy.health -= 40;
enemy.stunned = 60;
}
});
break;
case 'air':
// Tornado
gameState.projectiles.push(new Tornado(centerX, centerY));
break;
}
}
draw() {
// Draw player based on bender type
ctx.save();
switch (this.benderType) {
case 'fire':
ctx.fillStyle = '#ff4500';
break;
case 'water':
ctx.fillStyle = '#00bfff';
break;
case 'earth':
ctx.fillStyle = '#8b4513';
break;
case 'air':
ctx.fillStyle = '#e6e6fa';
break;
}
ctx.fillRect(this.x, this.y, this.width, this.height);
// Draw bending aura
ctx.globalAlpha = 0.3;
ctx.beginPath();
ctx.arc(this.x + this.width/2, this.y + this.height/2, 25, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
// Health bar
ctx.fillStyle = '#ff0000';
ctx.fillRect(this.x, this.y - 10, this.width, 5);
ctx.fillStyle = '#00ff00';
ctx.fillRect(this.x, this.y - 10, this.width * (this.health / this.maxHealth), 5);
}
}
// Enemy class
class Enemy {
constructor(x, y) {
this.x = x;
this.y = y;
this.width = 30;
this.height = 30;
this.speed = 2;
this.health = 50;
this.maxHealth = 50;
this.stunned = 0;
this.lastAttack = 0;
}
update() {
if (this.stunned > 0) {
this.stunned--;
return;
}
// Move toward player
const dx = gameState.player.x - this.x;
const dy = gameState.player.y - this.y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist > 0) {
this.x += (dx / dist) * this.speed;
this.y += (dy / dist) * this.speed;
}
// Attack player if close
if (dist < 50 && Date.now() - this.lastAttack > 1000) {
gameState.player.health -= 10;
this.lastAttack = Date.now();
// Create impact particles
for (let i = 0; i < 5; i++) {
gameState.particles.push(new Particle(
gameState.player.x + gameState.player.width/2,
gameState.player.y + gameState.player.height/2,
'#ff0000', 30
));
}
}
}
draw() {
ctx.fillStyle = this.stunned > 0 ? '#666666' : '#8b0000';
ctx.fillRect(this.x, this.y, this.width, this.height);
// Health bar
ctx.fillStyle = '#ff0000';
ctx.fillRect(this.x, this.y - 8, this.width, 3);
ctx.fillStyle = '#00ff00';
ctx.fillRect(this.x, this.y - 8, this.width * (this.health / this.maxHealth), 3);
}
}
// Projectile class
class Projectile {
constructor(x, y, vx, vy, type, color, damage) {
this.x = x;
this.y = y;
this.vx = vx;
this.vy = vy;
this.type = type;
this.color = color;
this.damage = damage;
this.life = 120;
this.size = 8;
}
update() {
this.x += this.vx;
this.y += this.vy;
this.life--;
// Check collision with enemies
gameState.enemies.forEach((enemy, index) => {
if (this.x < enemy.x + enemy.width &&
this.x + this.size > enemy.x &&
this.y < enemy.y + enemy.height &&
this.y + this.size > enemy.y) {
enemy.health -= this.damage;
this.life = 0;
// Create impact particles
for (let i = 0; i < 8; i++) {
gameState.particles.push(new Particle(
this.x, this.y, this.color, 40
));
}
if (enemy.health <= 0) {
gameState.enemies.splice(index, 1);
gameState.score += 100;
updateScore();
}
}
});
}
draw() {
ctx.fillStyle = this.color;
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fill();
// Add glow effect
ctx.save();
ctx.globalAlpha = 0.5;
ctx.beginPath();
ctx.arc(this.x, this.y, this.size * 1.5, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
}
}
// Tornado class (special air projectile)
class Tornado extends Projectile {
constructor(x, y) {
super(x, y, 3, 0, 'tornado', '#e6e6fa', 5);
this.life = 300;
this.size = 20;
this.angle = 0;
}
update() {
super.update();
this.angle += 0.2;
this.size = 20 + Math.sin(this.angle) * 5;
// Pull in nearby enemies
gameState.enemies.forEach(enemy => {
const dx = this.x - enemy.x;
const dy = this.y - enemy.y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 80) {
enemy.x += dx * 0.05;
enemy.y += dy * 0.05;
enemy.health -= 0.5;
}
});
}
draw() {
ctx.save();