Page 1 of 1

Help with turn attacks and defense

Posted: Thu Nov 19, 2015 9:14 pm
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

Re: Help with turn attacks and defense

Posted: Thu Nov 19, 2015 10:03 pm
by philat
I don't understand the question. What do you want this code to do that it doesn't?

Re: Help with turn attacks and defense

Posted: Thu Nov 19, 2015 11:00 pm
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.

Re: Help with turn attacks and defense

Posted: Fri Nov 20, 2015 12:44 am
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.

Re: Help with turn attacks and defense

Posted: Fri Nov 20, 2015 4:38 pm
by Alex