Tilemap collision

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Tilemap collision

Post by Lafolie »

Another interpretation, judging from this thread's 'sister thread' could be that he wants bigger tiles as in, say, 64x64px tiles instead of 16x16px.

You should really clarity man, people do want to help.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Tilemap collision

Post by miko »

Anxiety wrote:You know how you make a tilemap by taking a part of a picture and placing it on a quad and drawing it? Pff, thats easy. Now theres only one problem. How can i detect a collision with a certain tile? Im using a character which can move (obviously). I havent made the tilemap yet.
You need following information:
- the position (coordinates) of your "hero" (in "tile" units)
- if the tile at this position is "free" or "occupied" (with some static "rock" or a dynamic "enemy")

Then if you try to move your hero to the new position, and that new position is "occupied", there is a collision.
If you have "enemies", and try to move each/any of them to the new position, and that new position is "occupied" (by a static "rock", another "enemy" or your "hero"), then there is a collision.
In fact, the collision detection has nothing to do with how your picture actually looks like (except some cases, which I will omit here). Of course, if you have a "rock" in a picture, you want to mark the position corresponding to this part of image as "occupied by a rock".
Hopefully I understood what you are trying to do. If not, show us a code sample.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
User avatar
Wulfie
Prole
Posts: 12
Joined: Mon Apr 11, 2011 6:46 pm

Re: Tilemap collision

Post by Wulfie »

Anxiety - looking at both of your posts it sounds like you are wanting to make a large continuous map for your game, instead of chunks of maps..

If I have that right I can think of a few theoretical ways of doing this.

using tiled mapeditor the data is output to XML (map editor does the typing work for the tile grid location and using another layer you can gui in your collision). You could pull the data from the XML and save yourself having to hand code all of the commas etc.

Or if you dont want to deal with pulling XML data, then you can take the XML/TMX map and convert it to CSV with minor tweaks (likely less work than typing out all of the comma seperated data) you could pop this into you map.lua file and load it right from there - using the XML to simple do the work of typing everything for you.

Being new myself to Love, I am not 100% sure of the limits of map size and overhead/load time. However I have some thoughts that may work (everyone can correct me if im wrong).

Rather than load a 100x100 map all at once break it up using the method above or another. Take the smaller map using the example below; the numbers would be your map numbers.

2 4
1 3

From map 1 you would be able to walk to map 2 3 or 4. You could set it up to load / render current map and joining maps. at the most you would only be loading 9 maps. if the character moves from one map to another it would check for for joining maps, any non joining maps would be sent to the null gods and any non loaded joining maps could them be loaded.

Pair the above with seemless/scrolling map transition, and to the player you have one large map.

Then again, my original assumption could be wrong and this whole post was a rambling of nothingness that may one day know the glory of use, or end up in the depths of the forums to think about what it could have been.

Either way good luck in your project.

Wulfie
"We do not stop playing because we grow old. We grow old because we stop playing." -- Unknown
User avatar
Anxiety
Prole
Posts: 49
Joined: Sat Apr 02, 2011 9:36 am
Location: Finland

Re: Tilemap collision

Post by Anxiety »

Finally someone who realised what im asking! Thanks Wuflie!
I can't come up with a good signature!
Post Reply

Who is online

Users browsing this forum: No registered users and 87 guests