Sign in to follow this  
stenny

objects [varifications and suggestions]

Recommended Posts

Hello! I have set up my own tilesystem and now I want to add objects to it, starting with the player himself. I don't know how I'll order them though, but let me first basicly explain the tilesystem. A map is built out of blocks, which can be best compared to actual lego blocks. You put them next to each other and stack them upon each other and thus create a complete map. This way you can add heights in a map. Now for the objects. I was planning to do sómething like the following. Imagine you have a block at column 2, row 4 and floor 3. I'd want to add a 'object' there, and thus I give the block at that corresponding location ad pointer to the objects. Now I want to add another 'object', but that pointer is added to the latest object in the list...I'm creating a linked list yes. Now I want to first add the player himself. BUT, should I just see the player as an object too? Or shouldn't I 'add' the player anywhere at all and just have three variables that define it's position? And what about the more specific position of the player. The player doesn't move 16 pixels per frame (more like 4 or so), but still I need to define it's precise location. What's best? -Stenny

Share this post


Link to post
Share on other sites
I think your second approach is far better and is what I always do.

Draw a clear distintion between map cells, which are grid aligned, and free objects which may or may not be, depending on your game type.

Represent cells by values in a grid and free objects via X,Y world co-ordinates, stored in some kind of list. You can easily translate between the two for collision and so on.

Share this post


Link to post
Share on other sites
Hmm...Well the bíg advantage of the linked list idea is thah whenever a block is rendered, that linked list is rendered with it too. So the depth is automaticly right then.

Share this post


Link to post
Share on other sites
I see what you mean. I'm looking at it from the point of view of a 2D side-on game where the map is rendered first, then the items.

Could you perhaps come up with a hybrid solution, where you store as above, but set up a linked list of pointers to free objects for each cell then, before each render, run through the list of free objects and add each one to the linked list of the cell it is within, then use that info to render?

Only thing I don't understand is how you handle an object that is over several cells at once. This is an interesting topic, though.

Share this post


Link to post
Share on other sites
I found another 'way'. First, I created a new class, cNPlayer. Then I added a function to the map-class (cNMap) that sets the plater (on of the arguments is cNPlayer *Player).

Now, everytime a block is rendered (which is done via a func in the Mapclass...so we're in the scope of the mapclass) it checks if the column, row and floor of that block are the same as the CRF of the playerclass. If so, it renders.

Now, the actual cNPlayerclass is still outside all other classes (the on in the mapclass is just a pointer to this one), so I can still easily change the CRF. However, it is nót in a linked list, and thus if it changes position it doesn't error up the whole list.

I hope you understand me.

Quote:
Only thing I don't understand is how you handle an object that is over several cells at once.


First of all, I must congratulate you for that excellent question. I don't know the anser yet though, but I'm on it. xD lol

[EDIT]
Yes I do!

Imagine we have an object that takes up four blocks.

blocks:
+-+-+
|0|1|
+-+-+
|2|3|
+-+-+
image:
+---+
|4 5|
|6 7|
+---+

Let's assume the origin of the image is at 4, and we place the whole image on block 0. That wouldn't work, because later on block 1, block 2 and block 3 would be drawn over part 5, 6 and 7 of the image.
Now we're going to move the origin. To the left will not work, because exactly the same would happen as with origin = 0. But what if we say the origin of the image is on 6, and we draw on block 2. It will overlap block 0 and 1 now, simply because they were drawn beforehand. But still would block 3 overlap part 7. Thus:

When you place the origin on part 7 and draw the image on block 3.

Quote:
This is an interesting topic, though.

Too bad we're the only ones who see that ;D.

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