Help with turn attacks and defense

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
firecat
Miko-Class Veteran
Posts: 540
Joined: Sat Oct 25, 2014 6:20 pm
Completed: The Unknowns Saga series
Projects: The Unknown Saga series
Tumblr: bigattck
Deviantart: bigattck
Skype: bigattck firecat
Soundcloud: bigattck-firecat
Contact:

Help with turn attacks and defense

#1 Post by firecat »

Has everyone knows i was hiring to build the simple rpg even from outside renpy forums, right now its nearly done. every button works as it should, one problem with it is how the enemy fights. currently with this code it can only attack the hero or anyone who you add, thats why i'm asking anyone who can help with the final, final code. please help, it will change renpy as we know it.

Code: Select all

init python:
    def stats_frame(name, level, hp, maxhp, **properties):
    
        ui.frame(xfill=False, yminimum=None, **properties)
    
        ui.hbox() # (name, "HP", bar) from (level, hp, maxhp)
        ui.vbox() # name from ("HP", bar)
    
        ui.text(name, size=20)
    
        ui.hbox() # "HP" from bar
        ui.text("HP", size=20)
    
        ui.close()
        ui.close()
    
        ui.vbox() # Level from (hp/maxhp)

        ui.text("Lv. %d" % level, xalign=0.5, size=20)
        ui.text("%d/%d" % (hp, maxhp), xalign=0.5, size=20)
    
        ui.close()
        ui.close()
        
    def battle(win, lose, hero_HP, extra_HP, tiger_HP, evil_HP, **properties):
        ui.textbutton("Attack", clicked=ui.returns(("hit", True)), xalign=.5,yalign=.5)
        ui.textbutton("Defense", clicked=ui.returns(("block", True)), xalign=.6,yalign=.6)
        ui.textbutton("Heal", clicked=ui.returns(("help", True)), xalign=.7,yalign=.7)
        
        while True:
            type, value = ui.interact()
            previous_HP = hero_HP
            if type == "hit":
                if tiger_HP > 1:
                    tiger_HP = tiger_HP - 1000
                    tiger_damage = renpy.random.randint(100, 200)
                    hero_HP -= tiger_damage
                elif evil_HP > 1:
                    evil_HP = evil_HP - 1000
                    evil_damage = renpy.random.randint(100, 200)
                    extra_HP -= evil_damage
            if type == 'block':
                if hero_HP < previous_HP:
                    hero_HP = hero_HP + (previous_HP - hero_HP)/2
            if type == 'help':
                if hero_HP < 2500:
                    hero_HP = hero_HP + 1000
                    if hero_HP > 2500:
                        hero_HP = 2500
            if hero_HP < 1:
                renpy.jump(lose)
            if evil_HP < 1 and tiger_HP < 1:
                renpy.jump(win)
            stats_frame("ExtraP", 9, extra_HP, extramax_HP, xalign=0.20, yalign=0.05)
            stats_frame("Tiger", 4, tiger_HP, tigermax_HP, xalign=0.98, yalign=0.8)
            stats_frame("Hero", 1, hero_HP, heromax_HP, xalign=0.02, yalign=0.05)
            stats_frame("Evil", 5, evil_HP, evilmax_HP, xalign=0.80, yalign=0.8)
            ui.textbutton("Attack", clicked=ui.returns(("hit", True)), xalign=.5,yalign=.5)
            ui.textbutton("Defense", clicked=ui.returns(("block", True)), xalign=.6,yalign=.6)
            ui.textbutton("Heal", clicked=ui.returns(("help", True)), xalign=.7,yalign=.7)
            
        
label start:
    $ potions_left = 10
    with None
    jump fight
    
label fight:
    
    python:
        
        heromax_HP = 1000
        hero_HP = 1000
        
        tigermax_HP = 2000
        tiger_HP = 2000
        
        extramax_HP = 9000
        extra_HP = 9000
        
        evilmax_HP = 5000
        evil_HP = 5000
        
        while(hero_HP > 0):
            
            stats_frame("ExtraP", 9, extra_HP, extramax_HP, xalign=0.20, yalign=0.05)
            stats_frame("Tiger", 4, tiger_HP, tigermax_HP, xalign=0.98, yalign=0.8)
            stats_frame("Hero", 1, hero_HP, heromax_HP, xalign=0.02, yalign=0.05)
            stats_frame("Evil", 5, evil_HP, evilmax_HP, xalign=0.80, yalign=0.8)
            battle("win", "lose", hero_HP, extra_HP, tiger_HP, evil_HP, xalign=0.5, yalign=0.5)
            
label win:
    
    "yay"
    
    return
    
label lose:
    
    "noo"
    
    return
Image


Image


special thanks to nantoka.main.jp and iichan_lolbot

philat
Eileen-Class Veteran
Posts: 1900
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Help with turn attacks and defense

#2 Post by philat »

I don't understand the question. What do you want this code to do that it doesn't?

User avatar
firecat
Miko-Class Veteran
Posts: 540
Joined: Sat Oct 25, 2014 6:20 pm
Completed: The Unknowns Saga series
Projects: The Unknown Saga series
Tumblr: bigattck
Deviantart: bigattck
Skype: bigattck firecat
Soundcloud: bigattck-firecat
Contact:

Re: Help with turn attacks and defense

#3 Post by firecat »

philat wrote:I don't understand the question. What do you want this code to do that it doesn't?
it doesnt select the opponent, it only hits the opponent you added, the defense button works but not useful without the enemy selecting the player.
Image


Image


special thanks to nantoka.main.jp and iichan_lolbot

philat
Eileen-Class Veteran
Posts: 1900
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Help with turn attacks and defense

#4 Post by philat »

...well, yes, but there is no actual enemy turn in this code (the enemy essentially reflects some random amount of damage back on its attacker), so of course the enemy does not select an opponent to attack. I mean, forget the enemy selecting a player party character to attack -- there's no way for the player to 1) select which player character (hero or extra) is going to attack, or 2) select which enemy (tiger or evil) to attack. That's why I was confused. What you're asking for is fundamentally not considered in the structure of the code. If you want to build an rpg engine like the old school turn-based JRPGs, this is kind of not the framework you're looking for, and you'll have to rewrite it from the ground up. Did you hire someone else to write this? It seems like you should ask them to fix it.

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Help with turn attacks and defense

#5 Post by Alex »


Post Reply

Who is online

Users browsing this forum: No registered users