Certainly! Below is a simplified Pokémon-style RPG game implemented in a single HTML file using JavaScript and HTML5 Canvas for graphics. The game features:
- A player that can move around a simple map.
- Encounters with creatures (monsters) with types and stats.
- A basic battle system including STAB (Same Type Attack Bonus).
- A menu system for actions during battle.
- Items that can be used.
- A healing center where the player can heal their creatures.
Please note that this is a simplified version to demonstrate the core concepts.
<!DOCTYPE html>
<html>
<head>
<title>90s Style RPG Game</title>
<style>
body { margin: 0; overflow: hidden; background-color: black; }
canvas { display: block; margin: auto; background-color: #000; }
</style>
</head>
<body>
<canvas id="gameCanvas" width="640" height="480"></canvas>
<script>
// --- Game Variables ---
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
const tileSize = 32;
// Map dimensions
const mapWidth = 20;
const mapHeight = 15;
// Player object
const player = {
x: 8,
y: 7,
sprite: 'P',
creatures: [],
items: ['Potion'],
};
// Creature constructor
function Creature(name, type, hp, attack, moves) {
this.name = name;
this.type = type;
this.maxHp = hp;
this.hp = hp;
this.attack = attack;
this.moves = moves;
}
// Move constructor
function Move(name, type, power) {
this.name = name;
this.type = type;
this.power = power;
}
// Types effectiveness
const typeChart = {
Fire: { strongAgainst: 'Grass', weakAgainst: 'Water' },
Water: { strongAgainst: 'Fire', weakAgainst: 'Grass' },
Grass: { strongAgainst: 'Water', weakAgainst: 'Fire' },
};
// Wild creatures
const wildCreatures = [
new Creature('Flamio', 'Fire', 30, 10, [
new Move('Ember', 'Fire', 40),
new Move('Scratch', 'Normal', 30),
]),
new Creature('Aquata', 'Water', 35, 8, [
new Move('Water Gun', 'Water', 40),
new Move('Tackle', 'Normal', 35),
]),
new Creature('Leafy', 'Grass', 40, 7, [
new Move('Vine Whip', 'Grass', 45),
new Move('Headbutt', 'Normal', 40),
]),
];
// Healing Center
const healingCenter = { x: 10, y: 7 };
// Game state
let gameState = 'map'; // 'map', 'battle', 'menu', 'healing'
let battle = null;
// Initialize player creature
player.creatures.push(new Creature('Sparky', 'Electric', 35, 9, [
new Move('Thunder Shock', 'Electric', 40),
new Move('Quick Attack', 'Normal', 30),
]));
// --- Input Handling ---
let keys = {};
window.addEventListener('keydown', function (e) {
keys[e.key] = true;
});
window.addEventListener('keyup', function (e) {
keys[e.key] = false;
});
// --- Game Loop ---
function gameLoop() {
update();
draw();
requestAnimationFrame(gameLoop);
}
// --- Update Function ---
function update() {
if (gameState === 'map') {
updateMap();
} else if (gameState === 'battle') {
updateBattle();
} else if (gameState === 'healing') {
updateHealing();
}
}
function updateMap() {
let moved = false;
if (keys['ArrowUp']) {
player.y = Math.max(0, player.y - 1);
moved = true;
keys['ArrowUp'] = false;
}
if (keys['ArrowDown']) {
player.y = Math.min(mapHeight - 1, player.y + 1);
moved = true;
keys['ArrowDown'] = false;
}
if (keys['ArrowLeft']) {
player.x = Math.max(0, player.x - 1);
moved = true;
keys['ArrowLeft'] = false;
}
if (keys['ArrowRight']) {
player.x = Math.min(mapWidth - 1, player.x + 1);
moved = true;
keys['ArrowRight'] = false;
}
// Check for encounter
if (moved && Math.random() < 0.1) {
startBattle();
}
// Check for healing center
if (player.x === healingCenter.x && player.y === healingCenter.y) {
gameState = 'healing';
}
}
function updateBattle() {
if (battle.state === 'start') {
// Player turn
battle.state = 'player-turn';
} else if (battle.state === 'player-turn') {
if (keys['1']) {
playerAttack(0);
keys['1'] = false;
}
if (keys['2']) {
playerAttack(1);
keys['2'] = false;
}
if (keys['i']) {
useItem();
keys['i'] = false;
}
} else if (battle.state === 'enemy-turn') {
enemyAttack();
} else if (battle.state === 'won' || battle.state === 'lost') {
if (keys['Enter']) {
gameState = 'map';
battle = null;
keys['Enter'] = false;
}
}
}
function updateHealing() {
healCreatures();
gameState = 'map';
}
// --- Battle Functions ---
function startBattle() {
const wildCreature = wildCreatures[Math.floor(Math.random() * wildCreatures.length)];
battle = {
playerCreature: player.creatures[0],
enemyCreature: Object.assign({}, wildCreature),
state: 'start',
};
gameState = 'battle';
}
function playerAttack(moveIndex) {
const move = battle.playerCreature.moves[moveIndex];
const damage = calculateDamage(battle.playerCreature, battle.enemyCreature, move);
battle.enemyCreature.hp -= damage;
if (battle.enemyCreature.hp <= 0) {
battle.enemyCreature.hp = 0;
battle.state = 'won';
} else {
battle.state = 'enemy-turn';
}
}
function enemyAttack() {
const enemyMoves = battle.enemyCreature.moves;
const move = enemyMoves[Math.floor(Math.random() * enemyMoves.length)];
const damage = calculateDamage(battle.enemyCreature, battle.playerCreature, move);
battle.playerCreature.hp -= damage;
if (battle.playerCreature.hp <= 0) {
battle.playerCreature.hp = 0;
battle.state = 'lost';
} else {
battle.state = 'player-turn';
}
}
function calculateDamage(attacker, defender, move) {
let damage = move.power;
// STAB
if (move.type === attacker.type) {
damage *= 1.5;
}
// Type effectiveness
if (typeChart[move.type]) {
if (typeChart[move.type].strongAgainst === defender.type) {
damage *= 2;
} else if (typeChart[move.type].weakAgainst === defender.type) {
damage *= 0.5;
}
}
// Random variation
damage *= (0.85 + Math.random() * 0.15);
return Math.floor(damage);
}
function useItem() {
if (player.items.includes('Potion')) {
player.items.splice(player.items.indexOf('Potion'), 1);
battle.playerCreature.hp = Math.min(battle.playerCreature.maxHp, battle.playerCreature.hp + 20);
battle.state = 'enemy-turn';
}
}
function healCreatures() {
player.creatures.forEach(creature => {
creature.hp = creature.maxHp;
});
}
// --- Draw Function ---
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (gameState === 'map') {
drawMap();
} else if (gameState === 'battle') {
drawBattle();
} else if (gameState === 'healing') {
drawHealing();
}
}
function drawMap() {
// Draw ground
ctx.fillStyle = '#228B22';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw healing center
ctx.fillStyle = '#FF0000';
ctx.fillRect(healingCenter.x * tileSize, healingCenter.y * tileSize, tileSize, tileSize);
// Draw player
ctx.fillStyle = '#FFFF00';
ctx.fillRect(player.x * tileSize, player.y * tileSize, tileSize, tileSize);
}
function drawBattle() {
// Draw background
ctx.fillStyle = '#222';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw enemy creature
ctx.fillStyle = '#FF5555';
ctx.fillRect(400, 100, 80, 80);
ctx.fillStyle = '#FFF';
ctx.fillText(battle.enemyCreature.name, 400, 90);
ctx.fillText(`HP: ${battle.enemyCreature.hp}/${battle.enemyCreature.maxHp}`, 400, 190);
// Draw player creature
ctx.fillStyle = '#55FFFF';
ctx.fillRect(160, 280, 80, 80);
ctx.fillStyle = '#FFF';
ctx.fillText(battle.playerCreature.name, 160, 270);
ctx.fillText(`HP: ${battle.playerCreature.hp}/${battle.playerCreature.maxHp}`, 160, 370);
// Draw menu
ctx.fillStyle = '#333';
ctx.fillRect(0, 400, canvas.width, 80);
ctx.fillStyle = '#FFF';
if (battle.state === 'player-turn') {
ctx.fillText('Choose a move:', 20, 430);
battle.playerCreature.moves.forEach((move, index) => {
ctx.fillText(`${index + 1}. ${move.name}`, 20, 450 + index * 20);
});
ctx.fillText('Press "i" to use an item.', 20, 490);
} else if (battle.state === 'won') {
ctx.fillText('You won the battle! Press Enter to continue.', 20, 430);
} else if (battle.state === 'lost') {
ctx.fillText('You lost the battle... Press Enter to continue.', 20, 430);
} else {
ctx.fillText('Enemy is attacking...', 20, 430);
}
}
function drawHealing() {
ctx.fillStyle = '#FFA';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = '#000';
ctx.fillText('Healing your creatures...', 200, 240);
}
// Start the game loop
requestAnimationFrame(gameLoop);
</script>
</body>
</html>
How to Play:
- Use the arrow keys to move your character around the map.
- Random encounters may occur when moving.
- During battle:
- Press 1 or 2 to select a move.
- Press i to use an item (if available).
- Press Enter to continue after winning or losing a battle.
- When on the healing center (red tile), your creatures will be healed automatically.
Notes:
- This game uses simple rectangular shapes and text to represent graphics, emulating a retro, 90s-style look.
- The game logic includes checks for STAB and type effectiveness based on a simplified type chart.
- All actions are controlled via keyboard input; no buttons are used.
- Everything is contained within a single HTML file as requested.
Customization:
Feel free to expand upon this code by adding more creatures, moves, types, or by enhancing the graphics and game mechanics to create a more complex game.