Jump to content
  • Advertisement
Sign in to follow this  
Poskusin

Restricted Movement

This topic is 4673 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm have a little, ok, maybe a lot of trouble with how to do this problem. It seems like it should be so simple but I just can't figure it out. Let me try to explain. If you've ever played Shining Force (I or II) for sega genesis (and I'm sure many other games) then you will understand what I'm trying to do. In battle when you get to move, if your movement stat is equal to 1 then: XOX OOO XOX Your allowed movement grid looks like this, for 2 it would be: XXOXX XOOOX OOOOO XOOOX XXOXX 3: XXXOXXX XXOOOXX XOOOOOX OOOOOOO XOOOOOX XXOOOXX XXXOXXX ect. I'm having so much trouble figure out how to do this either in an embedded loop such as for x = -move to move for y = -move to move Am I going about this all wrong? Is there an easier way to do this? If it is a tile that you can walk on, it blt's a square to the x,y. I'm sorry, this is probably making no sence, but that goes to show how confused I am about it. So if you understand please lend me a hand. I'm writing it in VB, but I understand enough about c/c++ to try and translate if it's easier for you to explain it that way. Thanks. :)

Share this post


Link to post
Share on other sites
Advertisement
They just can't move diagonally. If you count the number of straight steps to each tile, it always matches the number you specified.

If you're just having trouble coding it, try using a rectangle. Size the rectangle by the number of steps in both deminsions, then add 1 for the center. For each tile of this rectangle, simply try to move back to the center tile and count the number of steps it took.

The pathfinding can be done really generically by reducing the path directions to two (toward the center, like upper-left tile can only move either down or right - just check for walls and other characters), but then your characters won't be able to get around objects. The possible paths will be more like line of sight. To do this correctly, you'll have to impliment some kind of path finding routine.

For a generic system, something like this for each tile in the rectangle..


loop (for each step)
{
if( center.y < current.y )
movedown();
else if( center.y > current.y )
moveup();
else if( center.x > current.x )
moveright();
else if( center.x < current.x )
moveleft();
else
finishwithtile();
}

Count the number of steps, and if it becomes too much, break from the loop and mark it as though they can't move to it.

edit: Oh yeah, up might be negative in your coordinates, so moveup() and movedown() might need swapped.

Share this post


Link to post
Share on other sites
I'm not sure what you are trying to do, but the following code will enumerate all the possible spots you could move to (assuming the maximum distance is measured by the "manhattan" distance):

for ( int i = -move; i <= move; ++i )
{
y = center.y + i;

int move_x = move - abs(i);
for ( int j = -move_x; j <= move_x; ++j )
{
x = center.x + j;
// do something with x,y
}
}

Share this post


Link to post
Share on other sites
Thanks you guys. Took some trying but I finally got it. Hope you will check out the screenshots in the announcments. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!