Simple battle system and item drops

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
nerupuff
Veteran
Posts: 211
Joined: Sat Dec 02, 2017 2:24 am
Contact:

Simple battle system and item drops

#1 Post by nerupuff »

Hi all. It's actually my first time posting in this subforum.

I've so far only coded a generic VN with just the branching paths and points system for romance routes. Now, I'm looking for help to make a simple battle system. I know that Sheepstorm (in the Ren'Py cookbook) exists, but it's a bit too complicated for my needs, and I'm not a good programmer to understand what needs to be done yet (I only know basic Ren'Py! :c)

What I was thinking of is having a choice that asks "Do you want to fight?"and choosing to say yes sends you to a screen that just has one "choice button" which is to "hit/attack". You see your enemy, and they have a health bar displayed. You would have one too. It would be turn-based in action, and the damage is random. Once the enemy is defeated, you get an item drop.

I don't know if there's any code for this, so if you can share yours or if you can point me in the right direction, I'd appreciate it!

tl;dr: need battle system with simple hit mechanic, random amount of damage, and item drops + inventory
ImageImage
Hire me for proofreading, editing, and (maybe) writing! ♡ Check here!

DannX
Regular
Posts: 99
Joined: Mon Mar 12, 2018 11:15 am
Contact:

Re: Simple battle system and item drops

#2 Post by DannX »

I just made a really simple battle system, it's pretty basic but it hopefully gives you a start:

Code: Select all

default hero_hp = 100
default enemy_hp = 100
default damage = 0

default player_turn = False
default enemy_turn = False

screen battle_hud():

    frame:
        xalign .2 yalign .7
        
        if hero_hp > 0:
            text "Hero HP:[hero_hp]" 
        else:
            text "Hero HP:0" 

    frame:
        xalign .7 yalign .2
        if enemy_hp > 0:
            text "Enemy HP:[enemy_hp]" 
        else:
            text "Enemy HP:0" 

screen battle_control():

    frame:
        xalign .5 yalign .5
        textbutton "Attack" action [SetVariable('enemy_hp', enemy_hp-damage), Return] 
    # removed the other buttons since you don't want any other choices

label battle1:

    "Enemy want's to fight!"

    show screen battle_hud

    while hero_hp > 0 and enemy_hp > 0:

        # Player's Turn

        "Your turn!"

        $ damage = renpy.random.randint(10,50) #calculate random damage

        call screen battle_control()

        "You dealt [damage] points of damage!"

        if enemy_hp <= 0:

            "You win!"

            "Enemy drops item!"

            jump .end_battle

        # Enemy's turn

        "The enemy is preparing an attack..."

        $ damage = renpy.random.randint(10,50)

        $ hero_hp -= damage

        "You were dealt [damage] points of damage!"

        if hero_hp <= 0:

            "You lost!"

            jump .end_battle

    label .end_battle:

        hide screen battle_hud

        "Battle end!"

    return

User avatar
nerupuff
Veteran
Posts: 211
Joined: Sat Dec 02, 2017 2:24 am
Contact:

Re: Simple battle system and item drops

#3 Post by nerupuff »

DannX wrote: Thu Nov 01, 2018 1:54 pm I just made a really simple battle system, it's pretty basic but it hopefully gives you a start:
This is ultra useful and gives me an idea of how it works! I really appreciate this. Is it okay to use and start off with this code and further customize it for my game? I guess I learned that random numbers also work on renpy, which I wasn't aware of originally. I thought it needed some extreme python programming. Thanks a bunch!
ImageImage
Hire me for proofreading, editing, and (maybe) writing! ♡ Check here!

DannX
Regular
Posts: 99
Joined: Mon Mar 12, 2018 11:15 am
Contact:

Re: Simple battle system and item drops

#4 Post by DannX »

nerupuff wrote: Thu Nov 01, 2018 10:31 pm Is it okay to use and start off with this code and further customize it for my game?
Yes, of course, I tried to make it as simple and straightforward as possible, but it will be helpful if you also understand the python behind it, so if you have any questions feel free to ask around or search the documentation for the keywords of functions you need to clarify.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]