Beginning to get what you're saying, and sorry for the double post. Do you think you could make a short example for me to off of?
I'll just post my code in here, wanted to change with the class Actor but through trial and error I haven't made much progress.
Code: Select all
label start:
# Create skills (name, hit, power, type)
$Slash = Skill("Slash", 90, 335, "attack")
$Pound = Skill("Pound", 90, 120, "attack")
$Decapitation = Skill("Decapitation", 80, 510, "attack")
$FreeStrike = Skill("Free Flowing Strike", 100, 420, "stun")
$Precision = Skill("Precision", 100, 150, "attack")
# Create battle actors (name, max_hp, skills, type)
$player = Actor("Nix",2100, [Slash, Decapitation, FreeStrike])
$Demon = Actor("Demon",6300,[Pound, Precision])
label battle:
show screen battle_ui
"Demon appeared"
while Demon.hp>0:
$ player.command(Demon)
if player.hp <1:
"gameover"
$ renpy.full_restart()
"You win"
hide screen battle_ui
$ player.reset(Demon)
jump story
init -1 python:
from copy import copy
class Skill():
def __init__(self, name, hit, power, type):
self.name = name
self.hit = hit
self.power = power
self.type = type
class Actor(renpy.store.object):
def __init__(self, name, max_hp=0, skills=[]):
self.name=name
self.max_hp=max_hp
self.hp=max_hp
self.skills = skills
def command(self, target):
self.skill = renpy.call_screen("command")
target.skill = renpy.random.choice(target.skills)
self.attack(self.skill, target)
if target.hp < 1:
return
target.attack(target.skill, self)
def attack(self,skill,target):
if self.skill.hit<renpy.random.randint (0,100):
narrator ("{} nimbly dodges {}'s attack".format(target.name,self.name))
elif self.skill.type=="stun":
target.hp -= self.skill.power-renpy.random.randint (0,30)
narrator ("{} stuns {} with a powerful blow!".format(self.name,target.name))
else:
target.hp -= self.skill.power-renpy.random.randint (0,28)
narrator ("{} strikes {}!".format(self.name,target.name))
def reset(self, target):
self.hp = self.max_hp
target.hp = target.max_hp
init:
screen command:
vbox align (.05,.9):
for i in player.skills:
textbutton "[i.name]" action Return (value=i)
screen battle_ui:
use battle_frame(char=player, position=(.05,.05))
use battle_frame(char=Demon, position=(.95,.05))
screen battle_frame:
frame area (0, 0, 180, 80) align position:
vbox yfill True:
text "[char.name]"
hbox xfill True:
text "HP"
text "[char.hp]/[char.max_hp]" xalign 1.0
label story:
"That wasn't too hard, was it?"
call battle
As you can see I've added types into my skills, so one of my moves has the type "stun". I tested to see if it worked with the
Code: Select all
elif self.skill.type=="stun":
target.hp -= self.skill.power-renpy.random.randint (0,30)
narrator ("{} stuns {} with a powerful blow!".format(self.name,target.name))
and sure enough it added new dialogue. Now all I need is a proper way to add the function. Any suggestions?