Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Tile Based Collision

Author
Message
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 23rd Jun 2009 20:34
I have a game mapped out where each tile is 32x32 and the character walks by going tile to tile. I want to figure out a way to find collision between him and a wall without actually having him touch the wall, but by finding a way to see if the wall is there so I can't go that way.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 23rd Jun 2009 20:52
......this is the Exact same situation the DarkNoobs team went thru in the initial planning

There are only 10 kinds of people in the world, those who understand binary and those who dont
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 23rd Jun 2009 21:51
Lol that's where I got my idea to make my game from. If you guys encountered this problem too, did you find a solution?
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 23rd Jun 2009 22:37
here is kinda how we originally thought to do it:

along with each tile that will accept collision (walls, tress, etc) is a matching collision tile which is black and red with the red being areas of collision

in game all these collision tiles are assembled over their counterparts on an off-screen bitmap then when the player moves you use memblocks (or point() ) to check the bitmap and if collision would occur (the player would be touching red) then forbid the movement

There are only 10 kinds of people in the world, those who understand binary and those who dont
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 23rd Jun 2009 23:56
Wait are you saying to have another layer resembling the one I would collide with,but just with black and red, then place it under everything and put it on a bitmap or in a memblock to check for collision?
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 24th Jun 2009 00:13
sorta, look back through the DarkNOOBS prject 3 thread and find and somewhere is a post by ashingda I think that has images of how the collision system works

There are only 10 kinds of people in the world, those who understand binary and those who dont
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 24th Jun 2009 01:04
The other way is to just look at the array holding the map. If you have tiles 3 to 10 as wall like tiles you check the array and don't let the player move that way if tiles 3 to 10 are in his way. You can do that for other effects also. Tiles 11 to 17 could be deep water and the player looses health when he's on tiles 11 to 17... or lava, acid, anything dangerous.

That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 24th Jun 2009 01:06
ok tat would also work howevr my method allows pixel perfect collision rather that tile collision

There are only 10 kinds of people in the world, those who understand binary and those who dont
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 24th Jun 2009 01:46
Thanks for the help guys I'll check up on the DarkNOOBs thread and see how it works out.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 24th Jun 2009 04:55
For our first project, tile based collision was based off of an array. The array was declared as DIM Map(Width,Height). This probably is a BAD idea for large maps, but it worked. If the array held a 0, that meant that the corresponding tile location was passable. If it held a 1, it wasn't. To prevent a lot of similar information we linked the Collision to tile codes, that is, the map was generated from a file using numbers from 1 to (I think) 10. Each value was hard coded into the code that would dictate how to handle it.

Alternatively, if your map is generated using a tileset, you could have a file along with the tileset image that contains the values for each tile, which is read into the program at the load.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 24th Jun 2009 04:59 Edited at: 24th Jun 2009 05:04
I just figured out an easier way using That1SmartGuy's idea.

I'm going to create the layer of red and black, but instead of using bitmap or memblock, I'm going to hide the sprites and use sprite collision between the two, I checked it out already and it works. I'll post a snippet to show in a second.

EDIT:

Here it is.



EDIT:

Sorry BN2 didn't see your post, that could work if i were using tilesets, but my map is just one large picture with multiple layers.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 24th Jun 2009 05:38
ok but you are aware that in large quantities sprites are slow, right?

There are only 10 kinds of people in the world, those who understand binary and those who dont
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 24th Jun 2009 06:40
He only needs 2 sprites. A red/black collision layer can be set up easily on a separate bitmap using paste image. Then you can grab the image and make a sprite.

As long as the map doesn't change much there shouldn't be a big performance hit. If the map is changing a lot (and thus, a collision map would need to be re-generated frequently), you would probably take a sizable performance hit.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 24th Jun 2009 07:12
No, there's not going to be very many sprites, so it won't, I'm going to cheat my way around and avoid that for now.
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 24th Jun 2009 23:43 Edited at: 24th Jun 2009 23:43
Quote: "I'm going to cheat my way around and avoid that for now. "


We don't call them cheats... their workarounds.

http://www.merriam-webster.com/dictionary/workaround

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 25th Jun 2009 22:12
Quote: "I'm going to create the layer of red and black, but instead of using bitmap or memblock, I'm going to hide the sprites and use sprite collision between the two,"


and if the sprites are hidden, that should very little processing impact. good plan.

Enjoy your day.

Login to post a reply

Server time is: 2024-05-20 10:39:23
Your offset time is: 2024-05-20 10:39:23