Create a pokemon style rpg. Add in stats, STAB, types, several creatures, moves, a menu, items, a place to heal that you can enter an exit like a pokemon center. Use programmatic graphics for now.
Assistant
Certainly! Below is a simplified Pokémon-style RPG game implemented in Python using the pygame library for graphics. The game includes:
Creatures with stats and types
Moves with types, power, and STAB (Same Type Attack Bonus)
A simple menu system
Items that can be used to heal
A healing place (like a Pokémon Center) that the player can enter and exit
Note: Before running the code, make sure you have pygame installed. You can install it via pip:
bash
pip install pygame
Now, here's the code for the game:
python
import pygame
import sys
import random
# Initialize Pygame
pygame.init()
# Set up display
WIDTH, HEIGHT = 640, 480
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Pokémon Style RPG")
# Define colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
# Define fonts
FONT = pygame.font.SysFont('arial', 20)
# Creature types
TYPES = ['Fire', 'Water', 'Grass']
# Type effectiveness (simplified)
TYPE_EFFECTIVENESS = {
('Fire', 'Grass'): 2,
('Fire', 'Water'): 0.5,
('Water', 'Fire'): 2,
('Water', 'Grass'): 0.5,
('Grass', 'Water'): 2,
('Grass', 'Fire'): 0.5,
}
# Creature class
class Creature:
def __init__(self, name, level, ctype):
self.name = name
self.level = level
self.type = ctype
self.max_hp = level * 10
self.hp = self.max_hp
self.attack = level * 2
self.moves = []
def is_alive(self):
return self.hp > 0
def heal(self):
self.hp = self.max_hp
# Move class
class Move:
def __init__(self, name, power, mtype):
self.name = name
self.power = power
self.type = mtype
# Player class
class Player:
def __init__(self):
self.creature = None
self.items = {'Potion': 2}
# Enemy class
class Enemy:
def __init__(self, creature):
self.creature = creature
# Functions
def calculate_damage(attacker, defender, move):
# Base damage
damage = move.power * (attacker.attack / defender.attack)
# Type effectiveness
effectiveness = TYPE_EFFECTIVENESS.get((move.type, defender.type), 1)
# STAB
stab = 1.5 if move.type == attacker.type else 1
# Calculate final damage
final_damage = damage * effectiveness * stab
return max(1, int(final_damage))
def draw_text(text, x, y):
img = FONT.render(text, True, BLACK)
WIN.blit(img, (x, y))
def battle(player, enemy):
in_battle = True
while in_battle:
WIN.fill(WHITE)
draw_text(f"You: {player.creature.name} HP: {player.creature.hp}/{player.creature.max_hp}", 20, 20)
draw_text(f"Enemy: {enemy.creature.name} HP: {enemy.creature.hp}/{enemy.creature.max_hp}", 20, 50)
draw_text("Choose an action:", 20, 100)
draw_text("1. Fight", 40, 130)
draw_text("2. Use Item", 40, 160)
draw_text("3. Run", 40, 190)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_1:
# Fight
move = player.creature.moves[0]
damage = calculate_damage(player.creature, enemy.creature, move)
enemy.creature.hp -= damage
draw_text(f"You used {move.name}! It did {damage} damage.", 20, 220)
pygame.display.update()
pygame.time.delay(1000)
if not enemy.creature.is_alive():
draw_text("Enemy defeated!", 20, 250)
pygame.display.update()
pygame.time.delay(1000)
in_battle = False
break
# Enemy's turn
enemy_move = enemy.creature.moves[0]
damage = calculate_damage(enemy.creature, player.creature, enemy_move)
player.creature.hp -= damage
draw_text(f"Enemy used {enemy_move.name}! It did {damage} damage.", 20, 220)
pygame.display.update()
pygame.time.delay(1000)
if not player.creature.is_alive():
draw_text("You are defeated!", 20, 250)
pygame.display.update()
pygame.time.delay(1000)
in_battle = False
break
elif event.key == pygame.K_2:
# Use Item
if player.items.get('Potion', 0) > 0:
player.creature.heal()
player.items['Potion'] -= 1
draw_text("You used a Potion. HP restored.", 20, 220)
pygame.display.update()
pygame.time.delay(1000)
else:
draw_text("No Potions left!", 20, 220)
pygame.display.update()
pygame.time.delay(1000)
elif event.key == pygame.K_3:
# Run
draw_text("You ran away!", 20, 220)
pygame.display.update()
pygame.time.delay(1000)
in_battle = False
break
def main():
clock = pygame.time.Clock()
player = Player()
# Create player's creature
player_creature = Creature(name='Pyro', level=5, ctype='Fire')
fire_move = Move(name='Ember', power=40, mtype='Fire')
player_creature.moves.append(fire_move)
player.creature = player_creature
# Game loop
in_pokemon_center = False
while True:
WIN.fill(WHITE)
draw_text("You are in the town.", 20, 20)
draw_text("Actions:", 20, 60)
draw_text("1. Go to tall grass (Battle)", 40, 90)
draw_text("2. Go to Pokémon Center", 40, 120)
draw_text("3. Check Creature", 40, 150)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_1:
# Battle
enemy_creature = Creature(name='Aqua', level=5, ctype='Water')
water_move = Move(name='Water Gun', power=40, mtype='Water')
enemy_creature.moves.append(water_move)
enemy = Enemy(creature=enemy_creature)
battle(player, enemy)
elif event.key == pygame.K_2:
# Pokémon Center
in_pokemon_center = True
while in_pokemon_center:
WIN.fill(WHITE)
draw_text("You are in the Pokémon Center.", 20, 20)
draw_text("Actions:", 20, 60)
draw_text("1. Heal your creature", 40, 90)
draw_text("2. Leave", 40, 120)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_1:
player.creature.heal()
draw_text("Your creature is healed!", 20, 150)
pygame.display.update()
pygame.time.delay(1000)
elif event.key == pygame.K_2:
in_pokemon_center = False
elif event.key == pygame.K_3:
# Check Creature
WIN.fill(WHITE)
draw_text(f"Name: {player.creature.name}", 20, 20)
draw_text(f"Level: {player.creature.level}", 20, 50)
draw_text(f"Type: {player.creature.type}", 20, 80)
draw_text(f"HP: {player.creature.hp}/{player.creature.max_hp}", 20, 110)
draw_text(f"Attack: {player.creature.attack}", 20, 140)
draw_text("Press any key to go back.", 20, 180)
pygame.display.update()
waiting = True
while waiting:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
waiting = False
clock.tick(60)
if __name__ == "__main__":
main()
How the Code Works
Creature Class: Represents a creature (similar to a Pokémon) with stats like HP, attack, type, and moves.
Move Class: Represents a move that creatures can use, with attributes like name, power, and type.
Player and Enemy Classes: Hold the player's creature and items, and the enemy's creature, respectively.
Type Effectiveness and STAB:
TYPE_EFFECTIVENESS is a dictionary that defines how effective one type is against another.
The calculate_damage function calculates damage based on the attacker's stats, the move used, type effectiveness, and STAB.
Menu System:
The main game loop displays options for the player to choose from: battling, going to the Pokémon Center, or checking their creature.
Within battles and the Pokémon Center, there are sub-menus for actions.
Features Included
Stats: Creatures have stats like HP, level, attack power.
STAB (Same Type Attack Bonus): If a creature uses a move that matches its type, the move's effectiveness is increased.
Types: Creatures and moves have types (Fire, Water, Grass), and type effectiveness is considered in damage calculations.
Moves: Creatures have moves they can use in battle.
Items: The player starts with Potions that can be used to heal their creature during battle.
Menu: The game includes menus for navigating actions both in and out of battle.
Healing Place: There's a simple Pokémon Center where the player can heal their creature and then exit back to the town.
Running the Game
Install Pygame: Ensure you have the pygame library installed.
Save the Code: Copy the code into a file named pokemon_rpg.py.
Run the Game: Execute the script using Python 3.
bash
python pokemon_rpg.py
Controls
Main Menu:
Press 1 to enter a battle.
Press 2 to go to the Pokémon Center.
Press 3 to check your creature's stats.
Battle Menu:
Press 1 to fight.
Press 2 to use an item.
Press 3 to run away.
Pokémon Center:
Press 1 to heal your creature.
Press 2 to leave the Pokémon Center.
Notes
This is a simplified version of a Pokémon-style RPG intended to demonstrate the requested features.
The game uses basic rectangles and text for graphics (programmatic graphics).
You can expand the game by adding more creatures, moves, types, and features like experience points and leveling up.
Feel free to experiment with the code, add new features, or adjust the existing ones to enhance the game experience!