/* Base Styles */
body {
margin: 0;
padding: 0;
font-family: 'Press Start 2P', cursive;
background-color: #000;
color: #fff;
overflow: hidden;
}
.game-container {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
background-color: #000;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}
/* Header Styles */
.game-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 20px;
background-color: #000;
border-bottom: 2px solid #f00;
font-size: 1.2rem;
}
.player-info {
display: flex;
gap: 20px;
}
.game-title {
font-size: 2rem;
color: #f00;
text-shadow: 2px 2px 0 #000;
}
.game-time {
font-size: 1.2rem;
}
/* Main Game Area */
.game-main {
display: flex;
flex: 1;
position: relative;
}
/* Map and World View */
.game-map {
flex: 1;
display: flex;
flex-direction: column;
background-color: #000;
border-right: 2px solid #f00;
}
.map-container {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
background-color: #000;
overflow: hidden;
}
#gameCanvas {
background-color: #000;
border: 2px solid #f00;
}
.map-controls {
padding: 10px;
background-color: #000;
border-top: 2px solid #f00;
}
.map-btn {
background-color: #f00;
color: #fff;
border: none;
padding: 10px;
margin: 5px;
font-size: 1.2rem;
cursor: pointer;
transition: all 0.2s;
}
.map-btn:hover {
background-color: #ff3333;
transform: scale(1.05);
}
.map-btn-row {
display: flex;
justify-content: center;
gap: 10px;
}
/* Battle Screen */
.battle-screen {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.9);
display: none;
flex-direction: column;
justify-content: space-between;
padding: 20px;
box-sizing: border-box;
z-index: 10;
}
.battle-opponent, .battle-player {
display: flex;
justify-content: space-between;
align-items: center;
}
.opponent-pokemon, .player-pokemon {
display: flex;
flex-direction: column;
align-items: center;
gap: 5px;
}
.pokemon-sprite {
width: 120px;
height: 120px;
filter: drop-shadow(0 0 5px #fff);
}
.pokemon-name {
font-size: 1.5rem;
color: #fff;
text-shadow: 1px 1px 0 #000;
}
.pokemon-level {
font-size: 1rem;
color: #fff;
text-shadow: 1px 1px 0 #000;
}
.pokemon-health {
width: 200px;
height: 20px;
background-color: #333;
border-radius: 5px;
overflow: hidden;
}
.health-bar {
height: 100%;
background-color: #4CAF50;
transition: width 0.3s;
}
.opponent-info, .player-info {
display: flex;
flex-direction: column;
gap: 10px;
}
.opponent-name, .player-name {
font-size: 1.2rem;
color: #fff;
text-shadow: 1px 1px 0 #000;
}
.pokemon-icon {
width: 40px;
height: 40px;
border: 2px solid transparent;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}
.pokemon-icon.active {
border-color: #f00;
}
.pokemon-icon img {
width: 30px;
height: 30px;
}
.battle-actions {
display: flex;
flex-direction: column;
gap: 20px;
margin-top: 20px;
}
.battle-messages {
height: 100px;
background-color: #333;
padding: 10px;
border-radius: 5px;
overflow-y: auto;
}
.message {
color: #fff;
padding: 5px 0;
border-bottom: 1px solid #555;
}
.action-buttons {
display: flex;
justify-content: space-around;
}
.battle-btn {
background-color: #f00;
color: #fff;
border: none;
padding: 10px 20px;
font-size: 1.2rem;
cursor: pointer;
transition: all 0.2s;
}
.battle-btn:hover {
background-color: #ff3333;
transform: scale(1.05);
}
.move-selection {
display: flex;
justify-content: space-around;
margin-top: 20px;
}
.move-btn {
background-color: #f00;
color: #fff;
border: none;
padding: 10px 20px;
font-size: 1.2rem;
cursor: pointer;
transition: all 0.2s;
width: 20%;
}
.move-btn:hover {
background-color: #ff3333;
transform: scale(1.05);
}
/* Overworld UI */
.overworld-ui {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background-color: rgba(0, 0, 0, 0.7);
padding: 10px;
display: flex;
justify-content: space-between;
align-items: center;
z-index: 5;
}
.pokemon-menu {
display: flex;
gap: 10px;
}
.menu-btn {
background-color: #f00;
color: #fff;
border: none;
padding: 10px 15px;
font-size: 1.2rem;
cursor: pointer;
transition: all 0.2s;
}
.menu-btn:hover {
background-color: #ff3333;
transform: scale(1.05);
}
.status-bar {
display: flex;
gap: 5px;
}
.status-item {
width: 40px;
height: 40px;
background-color: #333;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.2rem;
cursor: pointer;
transition: all 0.2s;
}
.status-item:hover {
background-color: #555;
}
/* Menu Screens */
.pokemon-menu-screen, .bag-menu-screen {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.9);
display: none;
flex-direction: column;
padding: 20px;
box-sizing: border-box;
z-index: 20;
}
.menu-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.menu-title {
font-size: 2rem;
color: #f00;
text-shadow: 2px 2px 0 #000;
}
.close-btn {
background-color: #f00;
color: #fff;
border: none;
width: 40px;
height: 40px;
font-size: 1.5rem;
cursor: pointer;
transition: all 0.2s;
}
.close-btn:hover {
background-color: #ff3333;
transform: scale(1.05);
}
.pokemon-list, .bag-items {
flex: 1;
overflow-y: auto;
margin-bottom: 20px;
}
.pokemon-entry, .bag-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
margin-bottom: 10px;
background-color: #333;
border-radius: 5px;
}
.pokemon-entry img, .bag-item img {
width: 60px;
height: 60px;
}
.pokemon-details, .item-details {
flex: 1;
display: flex;
flex-direction: column;
}
.pokemon-name, .item-name {
font-size: 1.2rem;
color: #fff;
text-shadow: 1px 1px 0 #000;
}
.pokemon-level, .item-quantity {
font-size: 1rem;
color: #fff;
text-shadow: 1px 1px 0 #000;
}
.switch-btn, .menu-action-btn {
background-color: #f00;
color: #fff;
border: none;
padding: 5px 10px;
font-size: 1rem;
cursor: pointer;
transition: all 0.2s;
}
.switch-btn:hover, .menu-action-btn:hover {
background-color: #ff3333;
transform: scale(1.05);
}
.menu-actions {
display: flex;
justify-content: space-around;
margin-top: 20px;
}
.bag-tabs {
display: flex;
gap: 10px;
margin-bottom: 20px;
overflow-x: auto;
}
.bag-tab {
background-color: #333;
color: #fff;
border: none;
padding: 10px 15px;
font-size: 1.2rem;
cursor: pointer;
transition: all 0.2s;
white-space: nowrap;
}
.bag-tab.active {
background-color: #f00;
}
.bag-tab:hover {
background-color: #555;
}
// game.js
// Game state
const gameState = {
player: {
name: "Player",
money: 1000,
badges: 0,
pokemon: [
{ id: 1, name: "Pikachu", level: 10, hp: 100, maxHp: 100, moves: ["Thunder Shock", "Quick Attack", "Tail Whip", "Growl"] },
{ id: 4, name: "Charmander", level: 8, hp: 80, maxHp: 80, moves: ["Ember", "Scratch", "Growl", "Leer"] },
{ id: 7, name: "Squirtle", level: 6, hp: 50, maxHp: 50, moves: ["Tackle", "Tail Whip", "Bubble", "Withdraw"] }
],
activePokemon: 0
},
opponent: {
name: "Rival",
pokemon: [
{ id: 1, name: "Pikachu", level: 10, hp: 80, maxHp: 100, moves: ["Thunder Shock", "Quick Attack", "Tail Whip", "Growl"] },
{ id: 4, name: "Charmander", level: 8, hp: 70, maxHp: 80, moves: ["Ember", "Scratch", "Growl", "Leer"] }
],
activePokemon: 0
},
battle: {
inBattle: false,
messages: [],
turn: "player"
},
map: {
tiles: [],
playerPosition: { x: 5, y: 5 }
},
inventory: {
items: [
{ id: 1, name: "Master Ball", quantity: 1 },
{ id: 2, name: "Ultra Ball", quantity: 5 },
{ id: 3, name: "Great Ball", quantity: 10 },
{ id: 4, name: "Poké Ball", quantity: 20 },
{ id: 5, name: "Potion", quantity: 10 }
]
}
};
// DOM Elements
const elements = {
gameCanvas: document.getElementById('gameCanvas'),
battleScreen: document.getElementById('battleScreen'),
overworldUI: document.getElementById('overworldUI'),
pokemonMenu: document.getElementById('pokemonMenu'),
bagMenu: document.getElementById('bagMenu'),
playerName: document.querySelector('.player-name'),
playerMoney: document.querySelector('.player-money'),
playerBadges: document.querySelector('.player-badges'),
playerPokemonList: document.querySelectorAll('.player-pokemon-list .pokemon-icon'),
opponentPokemonList: document.querySelectorAll('.opponent-pokemon-list .pokemon-icon'),
battleMessages: document.querySelector('.battle-messages'),
moveSelection: document.getElementById('moveSelection'),
closeButtons: document.querySelectorAll('.close-btn'),
bagTabs: document.querySelectorAll('.bag-tab'),
menuButtons: document.querySelectorAll('.menu-btn'),
moveButtons: document.querySelectorAll('.move-btn'),
switchButtons: document.querySelectorAll('.switch-btn'),
menuActionButtons: document.querySelectorAll('.menu-action-btn'),
mapButtons: document.querySelectorAll('.map-btn'),
runButton: document.getElementById('run-btn')
};
// Initialize the game
function initGame() {
// Set up player info
elements.playerName.textContent = gameState.player.name;
elements.playerMoney.textContent = `$${gameState.player.money}`;
elements.playerBadges.textContent = `Badges: ${gameState.player.badges}/8`;
// Set up initial Pokémon selection
updatePokemonSelection();
// Set up event listeners
setupEventListeners();
// Start the game loop
gameLoop();
}
// Update Pokémon selection UI
function updatePokemonSelection() {
// Player Pokémon
gameState.player.pokemon.forEach((pokemon, index) => {
const icon = elements.playerPokemonList[index];
if (icon) {
icon.querySelector('img').src = `https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${pokemon.id}.png`;
icon.classList.toggle('active', index === gameState.player.activePokemon);
}
});
// Opponent Pokémon (if in battle)
if (gameState.battle.inBattle) {
gameState.opponent.pokemon.forEach((pokemon, index) => {
const icon = elements.opponentPokemonList[index];
if (icon) {
icon.querySelector('img').src = `https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${pokemon.id}.png`;
icon.classList.toggle('active', index === gameState.opponent.activePokemon);
}
});
}
}
// Set up event listeners
function setupEventListeners() {
// Battle screen buttons
document.querySelectorAll('.battle-btn').forEach(btn => {
btn.addEventListener('click', handleBattleButtonClick);
});
// Pokémon selection
elements.playerPokemonList.forEach((icon, index) => {
icon.addEventListener('click', () => {
if (gameState.battle.inBattle) {
gameState.player.activePokemon = index;
updatePokemonSelection();
}
});
});
elements.opponentPokemonList.forEach((icon, index) => {
icon.addEventListener('click', () => {
if (gameState.battle.inBattle) {
gameState.opponent.activePokemon = index;
updatePokemonSelection();
}
});
});
// Close buttons
elements.closeButtons.forEach(btn => {
btn.addEventListener('click', () => {
document.querySelector('.pokemon-menu-screen, .bag-menu-screen').style.display = 'none';
elements.overworldUI.style.display = 'flex';
});
});
// Bag tabs
elements.bagTabs.forEach(tab => {
tab.addEventListener('click', () => {
elements.bagTabs.forEach(t => t.classList.remove('active'));
tab.classList.add('active');
// In a real game, you would update the bag items based on the selected tab
});
});
// Menu buttons
elements.menuButtons.forEach(btn => {
btn.addEventListener('click', () => {
const buttonText = btn.textContent;
elements.overworldUI.style.display = 'none';
if (buttonText === 'Pokémon') {
elements.pokemonMenu.style.display = 'flex';
} else if (buttonText === 'Bag') {
elements.bagMenu.style.display = 'flex';
}
// Add more menu options as needed
});
});
// Move buttons
elements.moveButtons.forEach(btn => {
btn.addEventListener('click', () => {
const moveName = btn.textContent;
useMove(moveName);
});
});
// Switch buttons
elements.switchButtons.forEach(btn => {
btn.addEventListener('click', () => {
// In a real game, you would handle switching Pokémon here
addMessage(`${gameState.player.pokemon[gameState.player.activePokemon].name} was switched out!`);
elements.pokemonMenu.style.display = 'none';
elements.overworldUI.style.display = 'flex';
});
});
// Menu action buttons
elements.menuActionButtons.forEach(btn => {
btn.addEventListener('click', () => {
const action = btn.textContent;
if (action === 'Run Away') {
endBattle();
}
// Add more actions as needed
});
});
// Map movement buttons
elements.mapButtons.forEach(btn => {
btn.addEventListener('click', () => {
if (!gameState.battle.inBattle) {
const direction = btn.id.replace('move-', '');
movePlayer(direction);
}
});
});
// Run button
elements.runButton.addEventListener('click', () => {
if (!gameState.battle.inBattle) {
// In a real game, you would implement running mechanics
addMessage("Player is running!");
}
});
}
// Handle battle button clicks
function handleBattleButtonClick(e) {
const action = e.target.textContent;
if (action === 'Fight') {
showMoveSelection();
} else if (action === 'Bag') {
// In a real game, you would open the bag during battle
addMessage("Opening bag...");
} else if (action === 'Pokémon') {
// In a real game, you would open the Pokémon menu during battle
addMessage("Selecting a Pokémon...");
} else if (action === 'Run') {
endBattle();
}
}
// Show move selection
function showMoveSelection() {
const activePokemon = gameState.player.pokemon[gameState.player.activePokemon];
const moves = activePokemon.moves;
// Clear previous moves
elements.moveSelection.innerHTML = '';
// Add new moves
moves.forEach(move => {
const button = document.createElement('button');
button.className = 'move-btn';
button.textContent = move;
button.addEventListener('click', () => useMove(move));
elements.moveSelection.appendChild(button);
});
}
// Use a move in battle
function useMove(moveName) {
const playerPokemon = gameState.player.pokemon[gameState.player.activePokemon];
const opponentPokemon = gameState.opponent.pokemon[gameState.opponent.activePokemon];
addMessage(`${playerPokemon.name} used ${moveName}!`);
// Simple damage calculation (in a real game, this would be more complex)
const damage = Math.floor(Math.random() * 20) + 1;
opponentPokemon.hp -= damage;
if (opponentPokemon.hp <= 0) {
opponentPokemon.hp = 0;
addMessage(`${opponentPokemon.name} fainted!`);
// In a real game, you would check for battle victory
} else {
// Opponent's turn
gameState.battle.turn = "opponent";
setTimeout(opponentTurn, 1000);
}
updateHealthBars();
}
// Opponent's turn
function opponentTurn() {
const playerPokemon = gameState.player.pokemon[gameState.player.activePokemon];
const opponentPokemon = gameState.opponent.pokemon[gameState.opponent.activePokemon];
// Simple AI: choose a random move
const moves = opponentPokemon.moves;
const randomMove = moves[Math.floor(Math.random() * moves.length)];
addMessage(`${opponentPokemon.name} used ${randomMove}!`);
// Simple damage calculation
const damage = Math.floor(Math.random() * 20) + 1;
playerPokemon.hp -= damage;
if (playerPokemon.hp <= 0) {
playerPokemon.hp = 0;
addMessage(`${playerPokemon.name} fainted!`);
// In a real game, you would check for battle loss
} else {
// Player's turn again
gameState.battle.turn = "player";
}
updateHealthBars();
}
// Update health bars
function updateHealthBars() {
// Player health bar
const playerHealthBar = document.querySelector('.player-pokemon .health-bar');
const playerPokemon = gameState.player.pokemon[gameState.player.activePokemon];
playerHealthBar.style.width = `${(playerPokemon.hp / playerPokemon.maxHp) * 100}%`;
// Opponent health bar
const opponentHealthBar = document.querySelector('.opponent-pokemon .health-bar');
const opponentPokemon = gameState.opponent.pokemon[gameState.opponent.activePokemon];
opponentHealthBar.style.width = `${(opponentPokemon.hp / opponentPokemon.maxHp) * 100}%`;
}
// Add a message to the battle log
function addMessage(message) {
const messageElement = document.createElement('div');
messageElement.className = 'message';
messageElement.textContent = message;
elements.battleMessages.appendChild(messageElement);
elements.battleMessages.scrollTop = elements.battleMessages.scrollHeight;
}
// Start a battle
function startBattle() {
gameState.battle.inBattle = true;
elements.battleScreen.style.display = 'flex';
elements.overworldUI.style.display = 'none';
// Update battle UI with current Pokémon
const playerPokemon = gameState.player.pokemon[gameState.player.activePokemon];
const opponentPokemon = gameState.opponent.pokemon[gameState.opponent.activePokemon];
// Update player Pokémon display
document.querySelector('.player-pokemon img').src = `https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${playerPokemon.id}.png`;
document.querySelector('.player-pokemon .pokemon-name').textContent = playerPokemon.name;
document.querySelector('.player-pokemon .pokemon-level').textContent = `Lv. ${playerPokemon.level}`;
// Update opponent Pokémon display
document.querySelector('.opponent-pokemon img').src = `https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/back/${opponentPokemon.id}.png`;
document.querySelector('.opponent-pokemon .pokemon-name').textContent = opponentPokemon.name;
document.querySelector('.opponent-pokemon .pokemon-level').textContent = `Lv. ${opponentPokemon.level}`;
// Update health bars
updateHealthBars();
// Initial message
addMessage(`Wild ${opponentPokemon.name} appeared!`);
}
// End the battle
function endBattle() {
gameState.battle.inBattle = false;
elements.battleScreen.style.display = 'none';
elements.overworldUI.style.display = 'flex';
addMessage("Battle ended!");
}
// Move player on the map
function movePlayer(direction) {
// In a real game, you would update the player's position and check for encounters
addMessage(`Player moved ${direction}`);
// Random encounter chance (20% in this example)
if (Math.random() < 0.2) {
startBattle();
}
}
// Game loop
function gameLoop() {
// In a real game, you would update the game state and render the map here
requestAnimationFrame(gameLoop);
}
// Initialize the game when the page loads
window.addEventListener('load', initGame);