Objects use tile or world corrdinates.

Started by
7 comments, last by rob0a 23 years, 7 months ago
I''m new to the concept of game programming and am looking into making a tile based graphics engine for fun. I am doing much reading first so I can get proper direction. I''ve read all of the articles here and many tile articles elsewhere. I still have a quesiton though: Do objects (characters, things that move) use tile coordinates or world coordinates? Objects need to move in amounts smaller that a tile right? Keeping a linked list in the tile structure to point to objects on that tile seems easy, but how can an object move to the tile next door and have maybe 10 different positions on the way? If objects use world corrdinates, where do you keep the objects? Do you still keep them in a tile? Or do you have a list of all of your objects, each of them with real world corrdinates? If this question is way off, or incorrectly phrased, tell me. I''m new, I could use the direction. Thanks in advance. -rob
Advertisement
No, as far as I have seen, objects/player use tile co-ordinates combined with a status (current status of what they are doing) and a value that represents how much of that task they have done...

Thus, a player whom is walking is in a tile, with a walking (walking in direction) status and a value for how far they have walked. It is really quite simple

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-Chris Bennett of Dwarfsoft
"The Philosophers' Stone of Programming Alchemy"
IOL (The list formerly known as NPCAI) - A GDNet production
Our Doc - The future of RPGs
Thanks to all the goblins over in our little Game Design Corner niche
I recommend using both. Have a struct that contains the world coordinates and then the coordinates within a map point/tile.

typedef struct OBJCOORD{     long MapX;     long MapY;     char OffsetX;     char OffsetY;     char Altitude;};


This way you can quickly determine which map point/tile an object is over and it''s exact location over that point.

Dino M. Gambone

Good judgement is gained through experience. Experience, however, is gained through bad judgement.

Dino M. Gambone
Good judgment is gained through experience. Experience, however, is gained through bad judgment.

Currently working on Rise of Praxis MUD: http://www.riseofpraxis.net/

Oh, and also, I store over each map point a linked list of all the objects over that point.



Dino M. Gambone

Good judgement is gained through experience. Experience, however, is gained through bad judgement.

Dino M. Gambone
Good judgment is gained through experience. Experience, however, is gained through bad judgment.

Currently working on Rise of Praxis MUD: http://www.riseofpraxis.net/

Dino, dwarfsoft, thanks much for responding. I appreciate your input. The advice and perspective from people with more experience is always most valuable.

Dino, using your combined approach, when you want to locate an object to a new position in the world (world map x and y), do you then have to figure out if the object has crossed the bounds of the tile and asign it to the list of the tile under its new location?

Thanks,
-rob
I have thought of maybe a better way to phrase my quesiton.


Objects move in fine grained matter. They might take a few small steps. Because if this do objects move and live in tile space? or fine coordinate (as Jim Adams put it in his smooth scrolling tutorial) space?

Dino, you''ve said that they should live in both? to use your struct as an example:

use OBJCOORD.MapX and MapY for location in the world and moving around, but keep track of what tile you belong to and use the tile''s location plus OJBCOORD.OffsetX and OffsetY for drawing the object to the screen?

Is this correct?

Sorry if these are rudimentary quesitons, but this particular issue wasn''t addressed anywhere I could find.


Thanks, I appreciate it!
-rob
Let me see if I can explain everything clearly...

The world consists of an array of structs called MAPPT:

struct MAPPTNODE{     cMapObj *Obj;         //cMapObj base class     MAPPTNODE *Next;      //Pointer to the next                            // cMapObj in the list.};struct MAPPT{     long Flags;           //Common properties of the point     MAPPTNODE *ObjList;   //Linked list of objs over this point};MAPPT *Map;                //The map


cMapObj is a base class that all my objects inherit. In cMapObj are the variables that contain MapX, MapY, OffsetX, OffsetY, and Altitude.

MapX and MapY represent a map point/tile that the map object is over. These are used to determine generally where the object is. 1 tile will normally cover up 1 map point completely.

OffsetX, OffsetY, and Altitude are used to determine where within the map point the object is located. It allows objects to move smoothly through the map instead of jumping from one map point to another, thus causing a pretty choppy appearance if not done properly.

It also allows multiple objects to reside on the same map point. This way you can stand on the same map point/tile as something else.

Whenever an object moves, I need to check if it has moved to another map point. There are a couple of ways to implement this. I prefer using a method like Tanstaafl''s mouse point to map point conversion. Quick array lookup is the way to go in my opinion.

If the object does move from one point to another, I simply drop it from the linked list of one point and toss it in the linked list of the other point. The linked lists are sorted based on Altitude of the object.

I hope this makes things clear for you. If you got more questions, feel free to post them.

Dino


Dino M. Gambone

Good judgement is gained through experience. Experience, however, is gained through bad judgement.

Dino M. Gambone
Good judgment is gained through experience. Experience, however, is gained through bad judgment.

Currently working on Rise of Praxis MUD: http://www.riseofpraxis.net/

Encapsulate, guys...

    const int TILE_SIZE = 32; // Or whatever...class Entity{    // These are your co-ordinates, fine-grained    int fineX;    int fineY;    // These functions return the tile you''re in    int GetTileX() const { return fineX / TILE_SIZE; }        // These functions return your fine-grained position    int GetFineX() const { return fineX; }    // These functions return your offset    int GetOffsetX() const { return fineX % TILE_SIZE; }}     
Thanks Dino, drarfsoft and Kylotan. I appreciate all of your input. I''ll be sure to come back when I have something together.

-rob

This topic is closed to new replies.

Advertisement