You're right! The previous version was intentionally simple, but let's now create an improved, more polished version with:
- Smooth HP bar animations
- Better UI layout using CSS
- Cleaner turn indicators
- More Pokémon details and enhanced visuals
- Organized and modular JavaScript
✅ Features in This Version:
✅ Visual HP bars inspired by original Pokémon games
✅ Turn-based battle (with indicators)
✅ Better UI/UX with CSS styling
✅ Uses high-quality sprites from the Sprite DB
✅ Clean HTML/CSS + Modular JavaScript logic
We'll still use Pikachu vs. Bulbasaur, but it can be extended easily.
🔧 Final Output:
Create one single HTML file (no separate JS or CSS required).
⚔️ Enhanced Pokémon Battle Game HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Pokémon Battle - Pikachu vs Bulbasaur</title>
<style>
body {
font-family: 'Trebuchet MS', sans-serif;
text-align: center;
background: linear-gradient(to bottom right, #e0f7fa, #e8f5e9);
margin: 0;
padding: 20px;
}
h1 {
margin-top: 10px;
}
.battle-arena {
display: flex;
justify-content: space-around;
align-items: center;
margin-top: 30px;
flex-wrap: wrap;
position: relative;
}
.pokemon-card {
background-color: white;
padding: 20px;
border-radius: 15px;
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
width: 300px;
margin-bottom: 40px;
}
.pokemon-name {
font-size: 1.5em;
font-weight: bold;
}
.pokemon-img {
width: 150px;
height: 150px;
}
.hp-bar {
height: 20px;
background: #ccc;
width: 100%;
border-radius: 10px;
margin: 10px 0;
overflow: hidden;
}
.hp-fill {
height: 100%;
background: linear-gradient(to right, #66bb6a, #43a047);
width: 100%;
transition: width 0.5s ease-in-out;
}
.attack-btn {
margin-top: 10px;
padding: 10px 20px;
font-size: 16px;
border: none;
border-radius: 8px;
background-color: #039be5;
color: white;
cursor: pointer;
}
.attack-btn:disabled {
background-color: #ccc;
cursor: not-allowed;
}
.turn-indicator {
font-weight: bold;
margin-top: 20px;
font-size: 1.2em;
}
.winner-banner {
font-size: 2em;
color: #d32f2f;
margin-top: 20px;
}
</style>
</head>
<body>
<h1>🌟 Pokémon Battle: Pikachu vs Bulbasaur 🌱</h1>
<div class="battle-arena">
<!-- Pikachu Card -->
<div class="pokemon-card" id="pikachuCard">
<div class="pokemon-name">Pikachu</div>
<img src="https://img.pokemondb.net/sprites/home/normal/2x/pikachu.png" alt="Pikachu" class="pokemon-img">
<div class="hp-bar">
<div class="hp-fill" id="pikachuHPBar"></div>
</div>
<div>HP: <span id="pikachuHPText">100</span>/100</div>
<button class="attack-btn" id="pikachuAttack">⚡ Quick Attack</button>
</div>
<!-- Bulbasaur Card -->
<div class="pokemon-card" id="bulbasaurCard">
<div class="pokemon-name">Bulbasaur</div>
<img src="https://img.pokemondb.net/sprites/home/normal/2x/bulbasaur.png" alt="Bulbasaur" class="pokemon-img">
<div class="hp-bar">
<div class="hp-fill" id="bulbasaurHPBar"></div>
</div>
<div>HP: <span id="bulbasaurHPText">100</span>/100</div>
<button class="attack-btn" id="bulbasaurAttack">🌿 Tackle</button>
</div>
</div>
<div class="turn-indicator" id="turnIndicator">Turn: Pikachu</div>
<div class="winner-banner" id="winnerBanner"></div>
<script>
const pikachu = {
name: "Pikachu",
maxHP: 100,
hp: 100,
damage: 20,
bar: document.getElementById("pikachuHPBar"),
hpText: document.getElementById("pikachuHPText"),
button: document.getElementById("pikachuAttack")
};
const bulbasaur = {
name: "Bulbasaur",
maxHP: 100,
hp: 100,
damage: 20,
bar: document.getElementById("bulbasaurHPBar"),
hpText: document.getElementById("bulbasaurHPText"),
button: document.getElementById("bulbasaurAttack")
};
const turnIndicator = document.getElementById("turnIndicator");
const winnerBanner = document.getElementById("winnerBanner");
let currentTurn = "pikachu";
function updateHP(pokemon) {
const hpPercent = Math.max(0, (pokemon.hp / pokemon.maxHP) * 100);
pokemon.bar.style.width = hpPercent + "%";
pokemon.hpText.textContent = pokemon.hp;
}
function disableButtons() {
pikachu.button.disabled = true;
bulbasaur.button.disabled = true;
}
function nextTurn() {
if (pikachu.hp <= 0 || bulbasaur.hp <= 0) {
declareWinner();
return;
}
currentTurn = currentTurn === "pikachu" ? "bulbasaur" : "pikachu";
updateTurnDisplay();
}
function updateTurnDisplay() {
turnIndicator.textContent = `Turn: ${currentTurn === "pikachu" ? "Pikachu" : "Bulbasaur"}`;
pikachu.button.disabled = currentTurn !== "pikachu";
bulbasaur.button.disabled = currentTurn !== "bulbasaur";
}
function attack(attacker, defender) {
defender.hp -= attacker.damage;
if (defender.hp < 0) defender.hp = 0;
updateHP(defender);
nextTurn();
}
function declareWinner() {
disableButtons();
const winner = pikachu.hp > 0 ? "Pikachu ⚡" : "Bulbasaur 🌿";
winnerBanner.textContent = `${winner} wins the battle! 🎉`;
turnIndicator.textContent = "";
}
// Event Listeners
pikachu.button.addEventListener("click", () => attack(pikachu, bulbasaur));
bulbasaur.button.addEventListener("click", () => attack(bulbasaur, pikachu));
// Init
updateHP(pikachu);
updateHP(bulbasaur);
updateTurnDisplay();
</script>
</body>
</html>
🧪 How to Run:
- Copy the code into a file, e.g.,
pokemon-battle.html.
- Open the file in your browser.
- Enjoy the interactive turn-based Pokémon battle!
🧰 Next Steps / Optional Features
Want to enhance it even more?
- Add random damage between
min and max
- Add crit chance or miss chance
- Replace attack buttons with selectable moves
- Add player names / selectors
- Add sound effects via
<audio> tags
Would you like some of those next? 😎