Archived

This topic is now archived and is closed to further replies.

Kuno

A math problem I believe...

Recommended Posts

I''ve been mulling over what type of game I should make. Seems everyone and there mother is making an RPG. Not that this is a bad thing mind you, I love RPGs. But I wanted to create something different. So I thought I''d try my hand at making a turn-based strategy game. Kinda like Advance Wars for the Gameboy Advance. Now I''m not designing the game at the moment. I''m trying different things out to see how to do them. Like little demos. I have made a Bitblt demo, I''ve moved a character tile-by-tile with collision detection and I''ve done smooth walking with collision detection. But now I''ve hit a road block and I believe its because my math background isn''t what it needs to be. As an example I will use Advance Wars to explain this. The infantry unit is able to move 3 spaces and its vision range is 2. When you goto move the unit a movement diamond appears. It looks like this: * *** ***** ***P*** ***** *** * ''P'' is the unit I know there are ways of doing this with out complex math. But I''m looking for the easiest way possible. I''ve never taken Calc or Trig so I''m hoping the answer doesn''t involve either of them. If it does please use small words Kuno

Share this post


Link to post
Share on other sites
actually if it could move three spaces it would look like this:
*
***
*****
***P***
*****
***
*
i have the game and the idea is great. but regarding math. hm...... im taking pre-cal right now. u know what? im gonna go work on a program to find it out for u. k?

Share this post


Link to post
Share on other sites
I think I''ve figured something out:

The infantry unit is in the center. Movement is in 2-dimensions. This is how the possible movements break down:

1) 3 UP
2) 2 UP 1 LEFT or 2 UP 1 RIGHT
3) 1 UP 2 LEFT or 1 UP 2 RIGHT
4) 0 UP/DOWN 3 LEFT or 0 UP/DOWN 3 RIGHT
5) 1 DOWN 2 LEFT or 1 DOWN 2 RIGHT
6) 2 DOWN 1 LEFT or 2 DOWN 2 RIGHT
7) 3 DOWN

Now what if the unit can move n squares?

If the unit can move n squares, the pattern starts by highlighting the space n squares above the unit. Then it moves one square down from that and highlights n - 1 squares to its left and right, then it moves down one square and highlights n - 2 squares to its left and right.

Follow this pattern again from the bottom working your way up and you have the desired diamond. There''s probably a more efficient solution and hopefully this idea will help you find it more quickly. I''m interested in finding a simple solution to this problem myself.

This isn''''t life in the fast lane, it''''s life in the oncoming traffic.
-- Terry Pratchett

Share this post


Link to post
Share on other sites
two ways: either just decide by distance for each cell within a rectangle around your pos (dist=sqrt((c-p)*(c-p)))

or the better way: already start finding the path:

start at p, move 1 in each possible direction and store the new cell in a list/array, highlight cell. for each cell in list repeat this until you moved n fields (and only add fields that arent in the list, except you like jumping back and forth between two cells *g*).

just imagine a tree, each node has 4 children and you collect all leafs to a depth of n.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you''re standing in position p=(px,py) then you can walk to every position q=(qx,qy) iff |px-qx|+|py-qy|<=n, where n is the maximumm number of moves.

|x| = x if x>=0, -x otherwise.

Share this post


Link to post
Share on other sites