Your cart is currently empty!
Ren’Py How-To: Beginner’s Guide to a Simple Battle System
Posted by
–
Disclosure: This post may contain affiliate links. If you make a purchase through these links, I may earn a commission at no extra cost to you.
I started making my first game back in 2009.
To learn how to use Ren’py, I mostly used the Wiki (specifically the Quickstart Manual, FAQ, and Cookbook) and occasionally the built-in tutorial (once you’ve installed Ren’py, open it up, select “Tutorial” from the list of projects, and then Launch Project – or open the script files to see how it’s made and copy code from it). Honestly, a lot of learning Ren’py (and software development in general) is copying other people’s code and adapting it for your own purposes.
So, start with the Quickstart Manual to learn how to make a basic game. Then use the FAQ to start customizing it, and the Cookbook for adding specific features. Another great resource for that is the Questions and Announcements forum on LemmaSoft. Often, a search (as in, using the Search function at the top-right and then choosing the Q&A forum on the list of forums to search) will show that someone else asked the same question before, and the answers are generally pretty helpful. If not, though, you can always post your question. I would reserve this for when there’s a specific thing you want to do but can’t find how to do it anywhere else, or if there’s a bug in your program that you can’t figure out. The Cookbook forum has some useful stuff in it, too – specific code that creators want to share, and a few tutorials, too.
As for the mini-games in “Memoirs of an Angel (2010)”, since I still didn’t know what I was doing with Ren’py when I made them, they’re actually really simple code-wise (and yes, everything is done in Ren’py, so if you haven’t read the Quickstart Manual mentioned above, the following will confuse you). I just used a series of Menus and Jumps. The dancing game involves showing and hiding the arrow images one after another (and playing a sound with each one), and then giving the player a choice of which pattern was right, which was just a Menu where instead of the options being text, I inserted an image instead. If the right option is chosen, then the partner says something happy and the code Jumps to the next round. If the wrong option is chosen, the partner says something sad, and a “mistake” variable (see Python and If Statements) get incremented by 1. Then at the end of five rounds, there’s an If Statement that makes it so that if the “mistake” value is greater than 3, the player loses the competition. There’s also a bar at the top which marks your progress through the competition, but that’s just a ConditionSwitch that changes the image based on a “round” Python variable.
The battle game is similar, except there are two bars at the top and instead of being based on what round it is, they’re ConditionSwitch images based on an “HP” variable that is set for each side (so there’s “HP” for your character, “EHP” for the enemy). Each round, you’re given three options in a Menu: Attack, Defend, or Forfeit. I didn’t bother with probabilities or battle statistics or anything like that, so attack values are fixed. So when you attack, the “EHP” variable changes a certain amount and so does the “HP” variable. Add in a Shake effect and change the characters’ expressions when they’re being hit or doing the attacking, and you’ve got a really simple battle using mainly just Menus, Jumps, and Python variables: all basic code. To mix things up in my game, I also used If Statements to add in critical hits and misses depending on the round (also fixed).
Now, if you’re planning on making a battle system as the backbone of your game (which I don’t suggest until you’ve gotten very familiar with Ren’py and probably Python too), you’ll need something more flexible than that, with room for character stats and inventory and things like that. Jake on LemmaSoft developed a Battle Engine for Ren’py for that purpose, but it’s pretty complicated unless you know what you’re doing, which is probably why I haven’t seen many games made with it. Still, if that’s something you’re interested in, you might want to check it out.
Code Example
Below is a simplified battle in the mini-game format of “Memoirs”, with appropriate expression changes and dialogue.
It may look complicated from the start, but it’s really not. Again, it utilizes only three very basic, beginner Ren’py techniques: menus (the essence of visual novels), setting variables (with the $
), and if/else statements to check the values of those variables. Even if you had never worked with Ren’py before, as long as you had looked through the Quickstart Manual and FAQ, you could do this.
Remember that lines starting with ##
are comments, lines with $
are Python variables, and lines starting with a letter are character dialogue (‘p’ is Player, ‘e’ is Enemy). This will not work if you just paste it into Ren’py as-is because the characters and their sprites aren’t defined. This is just the battle itself.
label battle:
## Each side starts with 100 HP...
$ playerHP = 100
$ enemyHP = 100
## Bring in the fighters...
show player normal at left
show enemy normal at right
p "You're going down, Enemy!"
e "No way, Player, I'll beat you!"
label battle_menu:
## Here are the options...
menu:
"Attack":
jump attack
"Defend":
jump defend
"Run":
jump battle_lose
label attack:
show player angry at left
p "Take this!"
show enemy sad at right
$ enemyHP -= 15
"Enemy lost 15 HP!"
## Check to see if enemy is dead...
if enemyHP <= 0:
## Do something if enemy is dead
Originally posted April 6, 2014 on Tumblr.
Leave a Reply