Sign in to follow this  
Proudest

Tactical RPG movement

Recommended Posts

I'm designing a 2d tactical rpg like Shining Force I/II for sega and Fire Emblem and have a question. I'm looking for a method to draw the movable area indicator tiles based on a range value. Here's how the pattern looks as the range increases. The number indicates the range of the object. One idea I have is to use a 2d array large enough to fit the shape in it then hard code each tile value to indicate the shape. Another idea is to use some sort of radius equasion, althought I don't know it. What I'm looking for is a pattern/equasion/method to dynamically create this shape based on a range value. I could be approaching this from the wrong angle, if anyone knows a common way this type of game handles this, let me know. Thanks.

Share this post


Link to post
Share on other sites
Are you familiar with any path finding algorithms? There is a particular one which is very apt for this kind of problem.

Imagine your player is at the center of a 2d array. Mark his position in the array with a zero, and mark all the other positions with a -1.

For each block in the array
If the block is walkable, has a value of -1 and there is a 0 to the top,left,right or bottom
then mark that block with a 1.

For each block in the array
If the block is walkable, has a value of -1 and there is a 1 to the top,left,right or bottom
then mark that block with a 2.

etc...

You can write a general algorithm to do this very easily. After 4 iterations you'll end up with something like this (I have left out the -1's on the image for clarity. The big black blobs are obstacles)

(http://www24.brinkster.com/freydev/pathfill.png)

What you want to do for now is use this array to render stuff nicely - eg. stuff that is 4 blocks from the player will be red or whatever you want.

This technique can also be used to make a monster walk towards the player: Build up the map exactly as is done above. If a monster is on a tile marked with a 4 just check the surrounding blocks for a 3 then move towards that block.

Did that help?

[Edited by - FReY on July 5, 2005 2:10:15 AM]

Share this post


Link to post
Share on other sites
I just wanted to add that you can improve the algorithm by a general factor of 2 by using a small box centered around your player to start off with and increasing it's size every iteration.

Share this post


Link to post
Share on other sites
That's exactly what I needed, thanks. This solves the previously un-though of pathfinding issue I would soon face and my original question at the same time.

How would an algorhythm for a straight line pattern used for targeting rather than moving look like? The pattern would only deal with the four horizonal/vertical directions, and would be capable of ranging from two values (min/max range).

For example, a person with a spear could have a range of 1-2 or a magician could have a spell with the range of 2-3, but not 1.

Share this post


Link to post
Share on other sites
think of the attack as a movement, simply "move" the attack towards the target, and if it collides or the path is > weapon.range ....

or...

you could use the almighty pythagoras.... sqrt(X1-X2,Y1-Y2)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this