script.rpy
Code: Select all
screen race_selection():
frame:
has vbox
label "Choose your race:"
textbutton "Elf":
action [SetVariable("race", "Elf"), Jump("class_selection")]
textbutton "Human":
action [SetVariable("race", "Human"), Jump("class_selection")]
textbutton "Dwarf":
action [SetVariable("race", "Dwarf"),Jump("class_selection")]
screen class_selection():
frame:
has vbox
label "Choose your class:"
textbutton "Bard":
action [SetVariable("character_class", "Bard"), Jump("age_selection")]
textbutton "Rogue":
action [SetVariable("character_class", "Rogue"), Jump("age_selection")]
textbutton "Fighter":
action [SetVariable("character_class", "Fighter"), Jump("age_selection")]
textbutton "Wizard":
action [SetVariable("character_class", "Wizard"), Jump("age_selection")]
screen age_selection():
frame:
has vbox
label "Choose your age:"
textbutton "Young (18-30)":
action [SetVariable("age", "Young"),Jump("alignment_selection")]
textbutton "Adult (31-50)":
action [SetVariable("age", "Adult"),Jump("alignment_selection")]
textbutton "Elderly (51+)":
action [SetVariable("age", "Elderly"), Jump("alignment_selection")]
screen alignment_selection():
frame:
has vbox
label "Choose your alignment:"
textbutton "Lawful Good":
action [SetVariable("alignment", "Lawful Good"), Jump("confirm_character")]
textbutton "Neutral Good":
action [SetVariable("alignment", "Neutral Good"), Jump("confirm_character")]
textbutton "Chaotic Good":
action [SetVariable("alignment", "Chaotic Good"), Jump("confirm_character")]
textbutton "Lawful Neutral":
action [SetVariable("alignment", "Lawful Neutral"), Jump("confirm_character")]
textbutton "True Neutral":
action [SetVariable("alignment", "True Neutral"), Jump("confirm_character")]
textbutton "Chaotic Neutral":
action [SetVariable("alignment", "Chaotic Neutral"), Jump("confirm_character")]
textbutton "Lawful Evil":
action [SetVariable("alignment", "Lawful Evil"), Jump("confirm_character")]
textbutton "Neutral Evil":
action [SetVariable("alignment", "Neutral Evil"), Jump("confirm_character")]
textbutton "Chaotic Evil":
action [SetVariable("alignment", "Chaotic Evil"), Jump("confirm_character")]
screen character_info(player):
frame:
has vbox
text "You have chosen the [player.race] [player.character_class]."
add player.image
text player.description
text "Your ability scores are:"
hbox:
frame:
has vbox
text "Strength: [player.strength]"
text "Dexterity: [player.dexterity]"
text "Constitution: [player.constitution]"
frame:
has vbox
text "Intelligence: [player.intelligence]"
text "Wisdom: [player.wisdom]"
text "Charisma: [player.charisma]"
text "alignment: [player.alignment]"
text "Your race traits are:"
hbox:
frame:
has vbox
for trait in player.race_traits:
python:
import json
trait_data = json.load(renpy.file("traits.json"))[f"{player.race.lower()}_traits"]
trait_info = next((t for t in trait_data if t["name"] == trait), None)
if trait_info:
text "[trait_info['name']]: [trait_info['description']]"
else:
text f"[trait]"
text "Your class traits are:"
hbox:
frame:
has vbox
for trait in player.class_traits:
text f"[trait['name']]: [trait['description']]"
frame:
has vbox
label "Confirm your character:"
textbutton "Confirm":
action Jump("play_game")
textbutton "Go Back":
action Jump("race_selection")
label start:
python:
race = None
character_class = None
age = None
alignment = None
additional_traits = []
player = None
label race_selection:
call screen race_selection()
label class_selection:
call screen class_selection()
label age_selection:
call screen age_selection()
label alignment_selection:
call screen alignment_selection()
label additional_traits_selection:
call screen additional_traits_selection()
label confirm_character:
$ player = create_player(race, character_class, age, alignment, additional_traits)
call screen character_info(player)
call screen confirm_character(player)
label play_game:
"text test"
player.rpy
Code: Select all
init python:
import json
import os
def load_data(data_type, name):
# Get the current game directory
game_dir = os.path.dirname(renpy.config.gamedir)
# Determine the base path to the directory with files
base_dir = os.path.join(game_dir, "game")
# Determine the file path depending on the data type
if data_type == "race":
file_dir = os.path.join(base_dir, "race")
file_path = os.path.join(file_dir, f"{name.lower()}.json")
elif data_type == "class":
file_dir = os.path.join(base_dir, "class")
file_path = os.path.join(base_dir, f"{name.lower()}.json")
elif data_type == "additional_traits":
file_dir = os.path.join(base_dir, "traits")
file_path = os.path.join(base_dir, f"{name.lower()}.json")
else:
raise ValueError("Invalid data type")
# Check if the file exists
if not os.path.isfile(file_path):
raise FileNotFoundError(f "File not found: {file_path}")
# Read data from the file
with open(file_path, "r") as f:
data = json.load(f)
return data
def create_player(race, character_class, age, alignment, additional_traits):
race_data = load_data("race", race)
class_data = load_data("class", character_class)
additional_traits_data = [load_data("additional_traits", trait) for trait in additional_traits]
return Player(race_data, class_data, age, alignment, additional_traits_data)
class Player(object):
def __init__(self, race_data, class_data, age, alignment, additional_traits):
self.race = race_data["race"]
self.age = age
self.alignment = alignment
self.strength = race_data["strength"]
self.dexterity = race_data["dexterity"]
self.constitution = race_data["constitution"]
self.intelligence = race_data["intelligence"]
self.wisdom = race_data["wisdom"]
self.charisma = race_data["charisma"]
self.race_traits = race_data["race_traits"]
self.size = race_data["size"]
self.speed = race_data["speed"]
self.image = race_data["image"]
self.description = race_data["description"]
self.character_class = class_data["class"]
self.class_traits = class_data["class_traits"]
self.apply_racial_modifiers(race_data)
self.apply_additional_traits(additional_traits)
def apply_racial_modifiers(self, race_data):
modifiers = race_data.get("ability_modifiers", {})
self.strength += modifiers.get("strength", 0)
self.dexterity += modifiers.get("dexterity", 0)
self.constitution += modifiers.get("constitution", 0)
self.intelligence += modifiers.get("intelligence", 0)
self.wisdom += modifiers.get("wisdom", 0)
self.charisma += modifiers.get("charisma", 0)
def apply_additional_traits(self, additional_traits):
For trait in additional_traits:
modifiers = trait.get("ability_modifiers", {})
self.strength += modifiers.get("strength", 0)
self.dexterity += modifiers.get("dexterity", 0)
self.constitution += modifiers.get("constitution", 0)
self.intelligence += modifiers.get("intelligence", 0)
self.wisdom += modifiers.get("wisdom", 0)
self.charisma += modifiers.get("charisma", 0)