Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

So for my tile based platformer, It has a grid of tiles Occupying 1x1 block for each one.

However, What if I want larger tiles? Maybe doors, tables, etc. They wouldnt fit in a 1x1 tile, so what I need is a way to let any method trying to access my tile array, know that a tile could be occupying a larger space.

I can already render larger objects correctly, But I simply am looking for a method to let evrything else know a larger tile is there, So I can perform collision on it, and so other tiles cant be placed on it.

share|improve this question
    
I'm not sure you should be using "the grid"... unless all your tiles completely occupy the space? Otherwise, you might have "floating" collisions. –  Vaughan Hilts Aug 9 '12 at 19:05
    
Well I am assuming games like terraria or minecraft, That seem to use a grid system, however have a few objects that are different –  Cyral Aug 9 '12 at 19:06
    
In that case, just assign the tile as occupied and give each object a width and height (so your GridObject that is occupied there) When you query for collisions, just take into account the existence of that many tiles vertically and horizontally as well. –  Vaughan Hilts Aug 9 '12 at 19:08
    
@VaughanHilts Ive already defined the width/height of each tile, I should have explained clearer, My problem is, How will it know that? I would have to check tiles in each direction, for however long my largest tile is just to find a larger tile –  Cyral Aug 9 '12 at 19:16
1  
Why not flag them all as 'occupied' then and then just have them all point to the same object? –  Vaughan Hilts Aug 9 '12 at 19:20
show 5 more comments

3 Answers 3

up vote 1 down vote accepted

So, if you have objects that are larger and you wish to fill a simple collision map (perhaps for sanity checking... you'll want to consider the use of bounding rectangles if that suits your game) let us take a look at how one might implement this using a simple 2D array.

Let us use the example for our collision map:

0, 0, 0, 0
0, 0, 0, 0 
0, 1, 1, 0  
0, 1, 1, 2


0 = null
1 = object with ID 1
2  = object with ID 2

If we use this simple model, upon placing the object we can fill all adjacent nodes in the array that are occupied with the object width and height. When checking for collisions, you can simply check for a 0.. anything else can be assumed to need further checking. If some objects can be passed through, either just write a 0 there to begin with... (you might be able to get away with this) or query for the object from your entity lookup table and check for more information.

share|improve this answer
    
I got it so it can set the reference and such (When I add a tile to my array, It will automaticly see how big it is, and add references for tiles near it). Is there a way I can get it so when I use the accessor, it will automaticly redirect to the referenced tile? –  Cyral Aug 10 '12 at 19:39
    
Sure, store an array of GameObjects instead. A space that's open can just be null; the rest of objects can be just be pointers/reference to the actual tile. If it's not null, you know somethings there to collide with. –  Vaughan Hilts Aug 10 '12 at 19:41
    
Yea I understand that, But In the accessor, I was wondering how to make it point to it, Or SEARCH and get the pointed tile everytime I need to access that tile –  Cyral Aug 10 '12 at 20:12
    
I'm not sure I understand the terminology "accessor" here. Do you mean the array? Just store the reference to the object in the array... but I'm sure you knew that. Could you flesh your question out a bit more? –  Vaughan Hilts Aug 10 '12 at 20:15
    
I mean using encapsulation (get{} set{}) to retrive/redirect to the correct tile –  Cyral Aug 10 '12 at 21:22
show 2 more comments

I plan to solve that by aggregating larger objects out of simple tiles.

For example, if you want your door to be 3*5 tiles big, you could construct it like this:

000
010
010

1 is a tile that, upon collision, leads you to another map (specified in the tile-descriptor) and 0 is simply a pretty picture.

share|improve this answer
    
Im confused. Are you saying that I need to create a new tile array for each of those objects? –  Cyral Aug 9 '12 at 19:08
    
No. Wherever you describe your tiles, simply create 1 and 0 like normal tiles. And then, in your map editor, place them near to eachother to form a door. –  jco Aug 9 '12 at 19:09
    
He's implying you should place each chunk of your object as a separate tile. Painful. –  Vaughan Hilts Aug 9 '12 at 19:10
1  
Because now you need to set each one separately, and don't forget if that object needs a special property.. such as a door that can be opened and closed. It now needs to be applied to every tile. –  Vaughan Hilts Aug 9 '12 at 19:15
2  
You don't need to necessarily have each chunk as a separate object. As far as the graphics is concerned, you can draw the door. But it still sets the appropriate bits in the collision map that indicate "non-placeable/non-walkable" –  Jimmy Aug 9 '12 at 19:27
show 4 more comments

My first idea for a solution would be to have objects that can span several tiles and then have a reference to that object in the tile so you know it's a door or whatever in case you need to open it later. So if an object spans 3x3 tiles when you add a reference to it to all adjacent tiles as well. Then you know that all those tiles contain that specific door with that state (open/closed, hitpoints etc).

If you want to go all crazy maybe you could look at using quadtrees for very large worlds but that might be a later issue. Never done that myself, it just seems really really cool :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.