RPG Battle Engine - Alpha 7.5, downloads in first post

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author
Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: RPG Battle Engine - Alpha 7, downloads in first post

#31 Post by Jake »

Eiliya wrote:Quick Question: I wish to implement the Active type battle you have shown here in a game I am making. How do I actually go about doing that? Do I just copy/paste the script you wrote in the first page in this thread, or do I need to do some more detailed work? Thank you for your time.
Copying and pasting the script in the first page would be a good start - you'd need the engine files and (at the very least) the assets.rpy from the battle engine demos (the download in the first post) as well, of course, since that script uses skills which were set up in assets.rpy.
(It may be that there are other dependencies, I'm at work on lunch right now so I can't check.)


However, that gets you one battle - so if you want to construct a game around battles, you'd need to do more work. For example, you'd probably want to create your fighter instances - 'bob' and 'geoff' in that example code - somewhere near the beginning of the game, so you only have to set their skills up once. If you want experience and levelling, you'd want to look at the example in the xp demo in the battle engine package. If you want items, you'd want to look at the example in the items demo, and so on.

Of course, if you need any help with any of that then feel free to post here or mail me through my website contact form.
Server error: user 'Jake' not found

Eiliya
Regular
Posts: 148
Joined: Tue Dec 04, 2012 6:21 am
Contact:

Re: RPG Battle Engine - Alpha 7, downloads in first post

#32 Post by Eiliya »

Hi again, and thank you for the swift reply.
I have begun taking a look at the assets file, and already I have encountered a problem. Or well, it is not really a problem as much as it is an uncertanity from me.

I figured I would begin by replacing all the images in the assets file with the ones I would use for my own game (I am allowed to do that, I hope..?) and encountered my own lack of knowledge in the size-limits for the images. By researching the files used in your demos, I realized that most images used (for characters, monsters and effects, that is) are somewhere around 200x200 pixels. Is there any specific reason for this, or can I use whichever size I see fit? In case it matters, I am only after the Active battle function for this test of mine.

For now, my goal is somewhat simple. I have one character that is fighting in an Arena. She is pitted against 3 opponents, one at a time. After each battle, she gets to decide if she wants to engage in the next combat right away, or rest. If she rests, her HP is restored (she has no MP) but she has to restart from the first battle. Each cleared battle earns her experience, and with enough of it, she will get stronger (level up). To win, the player must grind exp on the first and maybe second encounter until the character is strong enough to clear all three in one go.

I intend to use three different backgrounds and four character sprites for the fights and I would like to use some kind of animation or other effect to indicate which character is doing what (like a sword-slash or something) but I have no art for that yet. So now we come to my second question: Which .rpy files will I have to study and eventually modify in order to get what I am looking for, and how difficult will it be for a complete programming beginner like myself?

Once again, thank you for taking the time to read this far, and I look forward to your reply.

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: RPG Battle Engine - Alpha 7, downloads in first post

#33 Post by Jake »

Eiliya wrote: I figured I would begin by replacing all the images in the assets file with the ones I would use for my own game (I am allowed to do that, I hope..?) and encountered my own lack of knowledge in the size-limits for the images. By researching the files used in your demos, I realized that most images used (for characters, monsters and effects, that is) are somewhere around 200x200 pixels. Is there any specific reason for this, or can I use whichever size I see fit? In case it matters, I am only after the Active battle function for this test of mine.
With regard to permissions - presuming you are making a non-commercial game, you're welcome to use any or all of the code in the downloadable release; the only parts I request people not to make use of are the images, and even there you're welcome to ask, I'm not necessarily going to be inflexible. It'd be nice if not everyone using the engine had exactly the same effect graphics and everything, but the only bit I'm really absolutely sure I don't want people using are the isometric tilesets used in the elevation demos, 'cause I have plans for a game using those myself! Of course, you're free to use all the graphics supplied as placeholders until your own art is ready.

You can use images of any size you want, just bear in mind that:
- larger images will obviously take up more screen size, so plan your sizes accordingly
- you'll probably want to play with the 'anchor' and 'placeMark' parameters to BattleSprite if you change the sprites much from the examples.

The 'anchor' parameter when you create a BattleSprite tells the engine which part of the sprite should be positioned at the point on the screen that the fighter is 'standing'. Essentially, you should change these values to be the point on the sprite where the fighter's feet are.

The 'placeMark' property - which is actually only set on the enemy sprite in the active demo, because there's no reason to be selecting friendlies - tells the engine an offset to point to with the little pointy-finger when selecting it. You'll need this if you want to include anything that targets friendly fighters, like heal spells, potion items, and so on. Otherwise it'll just point to their feet, because it defaults to the anchor position. Because Ren'Py coordinates start in the top left, a placemark of (0, -75) means '75 pixels up from the anchor point'.
Eiliya wrote: I would like to use some kind of animation or other effect to indicate which character is doing what (like a sword-slash or something) but I have no art for that yet. So now we come to my second question: Which .rpy files will I have to study and eventually modify in order to get what I am looking for, and how difficult will it be for a complete programming beginner like myself?
Do you know how to define animations in Ren'Py using ATL? That's the easiest option - you can find documentation for ATL in the Ren'Py documentation.

Once you've done that, you'll need to assign your animations to 'state transitions' on the fighter. The battle engine sets a fighter's 'state' property depending on what they're doing - if they're doing nothing special, they'll have the 'default' state, if they're in the middle of a melee attack they'll have the 'melee' state, if they're taking damage they'll have the 'damage' state, and so on. You can define different sprites for different states, by writing Python code like this:

Code: Select all

  geoffSprite = BattleSprite('geoff default', anchor=(0.5, 0.8))      # This creates a sprite using the image called 'geoff default' as the default state image.
  geoffSprite.AddStateSprite('damage', 'geoff damage')                # This adds the image called 'geoff damage' to be used when in the 'damage' state.
Now, the tricky part is that the fighter is only actually in that state for as long as it takes the engine to work out the effect - so it's in the 'melee' state for as long as it takes to calculate damage, and it's in the 'damage' state for as long as it takes to reduce the fighter's HP by the appropriate amount... which generally means "a fraction of a second", which isn't very useful!

If you want an animation to play - say, the character swinging a sword, or reeling back taking damage - you'll want it to stay there long enough to see the whole animation. So instead of just setting the state sprite, you're better off creating a 'state transition' sprite. This is a special sprite that gets shown for a defined period of time whenever the fighter changes state from one state to another. So for our melee-attack animation, we'll need to create a state transition from 'default' to 'melee', and place the animation in there, telling the engine how long the animation needs to be shown for:

Code: Select all

  # The following line of code shows the image called 'geoff sword attack' for 0.75 seconds whenever the sprite changes from the 'default' state to the 'melee' state
  geoffSprite.AddStateTransition('default', 'melee', 'geoff sword attack', 0.75)
Like this, we ensure that every time the fighter makes a melee attack, we see our sword-attack animation for the whole 0.75 seconds it runs for, then we let the engine move on to actually calculating the damage and applying it to the enemy and all that.


These images - 'geoff default', 'geoff damage' or 'geoff sword attack' in the examples - are simply Ren'Py image names. So you can set them up as straight static images if you like, or you can create an ATL animation however you like for geoff swinging a sword, call it 'geoff sword attack', and the engine will play that animation instead of just showing a static image.




You can find some examples of state animations in directional_sprites.rpy starting around line 250 - be aware, though, that these are for the grid battlefields so there are multiple versions of each sprite for facing in different directions. If you're just using the active battle mode, then you can just leave off all the 'facing', 'fromFacing' and 'toFacing' parameters entirely, don't worry about them.
Server error: user 'Jake' not found

Eiliya
Regular
Posts: 148
Joined: Tue Dec 04, 2012 6:21 am
Contact:

Re: RPG Battle Engine - Alpha 7, downloads in first post

#34 Post by Eiliya »

Alright, thank you for your time.

I will get into this in more detail when I get up tomorrow. If I encounter any further difficulties, I will report them here.

Eiliya
Regular
Posts: 148
Joined: Tue Dec 04, 2012 6:21 am
Contact:

Re: RPG Battle Engine - Alpha 7, downloads in first post

#35 Post by Eiliya »

Hi again, and sorry for the double post.

I have been playing around somewhat with the various scripts now, and I have encountered a few problems that I figured I would ask about here.
Image
First Question: Before I added the battle engine all text appeared where Ruzzy is talking, at the bottom of the screen with the background slightly darker. Now all text that isn't character-specific appears on a blue frame at the top of the screen. Why is that and how do I fix it?
Image
Second Question - Reformed: Ok, so I managed to solve the height (anchor?) on my own, but I still do not quite understand how the place marker thing works. Would it be possible to get an explanation on that? (I will keep experimenting on my own while I wait, so if I solve it, I will update here).

Thank you for your time.

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: RPG Battle Engine - Alpha 7, downloads in first post

#36 Post by Jake »

Eiliya wrote: First Question: Before I added the battle engine all text appeared where Ruzzy is talking, at the bottom of the screen with the background slightly darker. Now all text that isn't character-specific appears on a blue frame at the top of the screen. Why is that and how do I fix it?
That's caused by the 'narrator' character (which is used for all non-character dialogue by Ren'Py) being used in the demos and for battle announcements, so in the demo code there's styling set on the narrator. I don't recall exactly where it's done - probably either in assets.rpy or engine.rpy.

If you remove that styling, then it'll revert to the way it worked before, although also the battle announcements will use the same styling as your Ren'Py narration.

If you want to keep the battle announcements using a separate styling, then you'll have to change the name of the character that's styled like that from 'narrator' to something else, and also change the function those announcements are made in. Off the top of my head I think it's called "Announce", and it's probably in the schema class, but if you want help with it I'll have a look when I have the time.
Eiliya wrote: Second Question: I want the sprites to stand a short bit further down on the screen (now it looks like they are both floating in the air). Also, when I click to target the zombie, the marker is placed really strange. I know these problems are related to the 'anchor' and 'place markers' you mentioned in your previous post, but I do not understand how to manipulate them. Could you give me a quick explanation of that, maybe?
The anchor works basically the same way as the Ren'Py style property with the same name. The position of the sprite (which is determined by the battlefield in this case) tells Ren'Py where on the screen to draw, and the anchor tells it which part of the sprite to draw at that position.

So if you have a position of (0,0) - the top left corner - and an anchor of (0,0) as well, then the top-left corner of the sprite will be drawn at the top left corner of the screen. If you have an anchor of (0.5, 0.5) - halfway down and halfway across the sprite, the absolute centre - then the centre of the sprite will be drawn at the top-left corner, meaning you'll only see the bottom-right quarter of the image, because the top half and the left half will be off the screen.

In this case, the position is determined by the battlefield - if you want to see exactly where it is, set your characters' sprite to be a very small graphic with an anchor of (0.5, 0.5), and see where that gets shown. Presuming that you don't want to fiddle with the way the battlefield is set up, the easiest way to modify the position of your characters is to play with the anchor points. You'll need to determine which point on your character sprite you want to be positioned at that exact position on the screen, and set your anchor to that.

So if you want your character positioned such that the battlefield position - where the tiny graphic got shown - would be two-thirds of the way down the sprite (from up to down), and halfway across the character (from left to right), then you'd set the anchor to (0.66, 0.5) - which equates to two-thirds and half, respectively. I believe you can also set the anchor points in terms of pixels from the top-left (just use whole numbers instead of decimals), but I can't remember for certain off the top of my head.



As to the place mark, this is set as an offset in pixels from the anchor point. The default is (0,0), meaning it'll point directly at the anchor position; this is a coordinate value starting in the top-left, like all Ren'Py coordinates, so if you want to move it 20 pixels to the right and 50 pixels up you would set the placemark to be (20, -50). The 20 is positive because the left-right numbers get bigger as you to go the right, but since the top-bottom numbers get bigger as you go down, you need a negative number to go up again.


I hope all that made sense! Let me know if it doesn't, I can knock up an example image when I have the time. Although I'm busy this evening, so it'll probably be at the weekend.
Server error: user 'Jake' not found

Eiliya
Regular
Posts: 148
Joined: Tue Dec 04, 2012 6:21 am
Contact:

Re: RPG Battle Engine - Alpha 7, downloads in first post

#37 Post by Eiliya »

The anchor and placemark things made somewhat sense, the announce/narrator part did not. I do remember seeing something that might be the style you mentioned though, so I'll try experimenting with that some. If I run into any more trouble, I'll come back. Once again, thank you for your help.

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: RPG Battle Engine - Alpha 7, downloads in first post

#38 Post by Jake »

Eiliya wrote:the announce/narrator part did not
'narrator' is the name of a default character Ren'Py uses to output those no-character-talking bits of dialogue. If you want to style those boxes separately from regular characters' dialogue you need to define the 'narrator' character and set them to use particular styles.

In the demos, I used the narrator character for the battle announcements, so I re-styled it to show as that blue bordered at-the-top box. If you remove that styling then your narration lines will show up like they used to, but the battle announcements will also show up like your narration used to.

The other alternative is to create a new character for the announcements (which is what I should have done in the first place really, and I'll try and remember to make this change for the next release), but to do that I believe you'll need to find the function in the engine code (I think it's probably in engine-schema.rpy) that uses the 'narrator' character for announcements and change that to a different character name.
Server error: user 'Jake' not found

Eiliya
Regular
Posts: 148
Joined: Tue Dec 04, 2012 6:21 am
Contact:

Re: RPG Battle Engine - Alpha 7, downloads in first post

#39 Post by Eiliya »

New problem located: So I played around quite alot with the anchor/placeMark functions, and as I was finally feeling like it worked I decided to make a test run. And of course it screwed me up. The sprites are placed where I want them to be, the small white thumb points at the head of the enemy, damage pops up above him when I attack him, but when he attacks me, the damage is way of. I tried experimenting with the battle.AddExtra(RPGDamage(offset=(0, -75))) code in the activedemo file, changing the offset values abit, but nothing happened. Some aide would be greatly appreciated.

Thank you.

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: RPG Battle Engine - Alpha 7, downloads in first post

#40 Post by Jake »

Eiliya wrote:when he attacks me, the damage is way of. I tried experimenting with the battle.AddExtra(RPGDamage(offset=(0, -75))) code in the activedemo file, changing the offset values abit, but nothing happened. Some aide would be greatly appreciated.
Yeah, apparently the offset parameter is completely ignored! I think I used to use that before the placeMark stuff was added. Thanks for pointing out the bug, I'll add it to the list to correct before the next release.


Essentially, the RPGDamage number bounces out from the placeMark point - so you just need to set one of those up for your friendly characters as well. Which is something else I should probably do in the next release, for that matter!





For what it's worth, since I'm home and can check now, in case you've not found it already: the narrator styling is at the bottom of assets.rpy, and the Announce method in around line 40 of engine-ui.rpy. If you want to make a fix to un-style the narration but keep the battle announcements in the pop-up box, then you'll just need to:

- in assets.rpy, change (near the end):

Code: Select all

narrator=Character(None, window_style=style.NarratorTextWindow, what_style=style.NarratorText)
to:

Code: Select all

announcer=Character(None, window_style=style.NarratorTextWindow, what_style=style.NarratorText)
- in engine-ui.rpy, change (~line 44):

Code: Select all

renpy.say(narrator, text + "{fast}{w="+str(pause)+"}{nw}")
to:

Code: Select all

renpy.say(announcer, text + "{fast}{w="+str(pause)+"}{nw}")
Server error: user 'Jake' not found

Eiliya
Regular
Posts: 148
Joined: Tue Dec 04, 2012 6:21 am
Contact:

Re: RPG Battle Engine - Alpha 7, downloads in first post

#41 Post by Eiliya »

Uh... There is no engine-ui.rpy file in the demo I downloaded...

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: RPG Battle Engine - Alpha 7, downloads in first post

#42 Post by Jake »

Eiliya wrote:Uh... There is no engine-ui.rpy file in the demo I downloaded...
Ah! Sorry, I thought I'd separated that out in the last release. The file will exist will be in the next one... which doesn't help you much, 'cause I'll have made this change already in the next release!

In the meantime, try searching for that line in engine-display.rpy (IIRC).
Server error: user 'Jake' not found

User avatar
AERenoir
Veteran
Posts: 320
Joined: Fri May 27, 2011 8:23 pm
Contact:

Re: RPG Battle Engine - Alpha 7, downloads in first post

#43 Post by AERenoir »

A little confused. How do I use the engine? Do I just put all the files into my main project, or do I put it in a separate folder and only copy-paste the bits of code and assets that I need?

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: RPG Battle Engine - Alpha 7, downloads in first post

#44 Post by Jake »

AERenoir wrote:A little confused. How do I use the engine? Do I just put all the files into my main project, or do I put it in a separate folder and only copy-paste the bits of code and assets that I need?
It's best to copy over the engine directory into a subdirectory of your game, and then just copy the bits of code that you need. If you copy over everything, the demo code will overwrite bits of your game.
Server error: user 'Jake' not found

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: RPG Battle Engine - Alpha 7, downloads in first post

#45 Post by xela »

It's hard to post a simple thanks with stuff like this hanging under the message body:

---
Your message will be seen by thousands of people. Please take some time to proofread it and to ensure that it advances the discussion. If your post is short consider elaborating - explaining WHAT you like, or WHY you hold your position. Before you click submit, ask yourself "Is this worth the time of all those readers?"
---

but still...

Thanks for the amazing Battle Engine! :)

and apologies if this doesn't really advance the discussion.

Post Reply

Who is online

Users browsing this forum: Andredron