Character (NPC / PC) movement?

Started by
11 comments, last by Christiaan 23 years, 11 months ago
Christiaan,
With a tile based system you can also incorporat a pixel based coord system too.

For an example we will use a 10x10 tile based system. For simplicity we will be using square tiles but the same method can be used for iso tiles (hex a bit more complicated). Lets say our square tiles are 32x32... that would make our pixel based coord system 320x320.
So, if the NPC is in tile coordinate 2,4 you can find his world coord by doing this 2*32 = 64 and 4*32 = 128. To find the fine coodinate you use 64,128 and then determine where within the 2,4 the NPC is. If the NPC is at 16, 16 within that grid just add 64+16= 80 and 128+16= 144
so the players fine coords are 80,144.
I hope that helps.

David "Dak Lozar" Loeser
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
Advertisement
Christian,

It all depends on how you want the game to be structured, even if you plan on it being turn-based. You can have PCs/NPCs confined to one or more tiles (xcom comes to mind), and simply animate their movement between the tiles, or you can allow greater freedom of movement, so that they can move within a tile (was fallout like this? I forget...).

I would recommend the second, as the first is a bit outdated. Unless, ofcourse, you''re going for the feel of the original battletech game, where the units would be confined to single hex tiles. AD&D doesn''t have any cut-and-dried combat movement rules, so you would have more leeway there.

The way to do the second version is to simply store both tile coords and pixel offsets for your sprites. To move, just cycle through your animation while changing the pixel offsets, and (when they go off the edge of a tile) the tile coords.

I hope that helps.


while( strcmp(reply,flame) )    followThread();


random-nomad
I used to have a real hard time with this subject. I would try to imagine it happening in my mind and everything would blow up. Dak Lozar is the closest to the best solution. On one hand, you can''t have an exclusively tile based, and on the other, you can''t have an exclusivly pixel based. Also, you can''t have both of those systems but into the same world at the same time! You can only feasably have one co-ordinate system at one time. If my man is in a pixel environment and my house is in a tile environment, I would have a nightmare detecting when I ran into the walls and when I walked through the door!

What you have to do is make a hybrid. It is easiest to think about each tile being an independent pixel system. My man knows what tile he is in and if the next tile over is "walkable" (for lack of better terms) but he also knows the indevidual pixels in that tile. This lets you keep the terrain height and everything!

Happy coding!

If you can''t win, make sure the one that beats you breaks the record!
If you can''t win, make sure the one that beats you breaks the record!

This topic is closed to new replies.

Advertisement