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.

2D All the way! / Question on 2D Tile Mapping Collsion Detection

Author
Message
MagiKnight
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location:
Posted: 24th Sep 2003 22:36 Edited at: 24th Sep 2003 22:52
Hi I was thinking (Oh no he was thinking ahhhh everyone run!!!)

LOL Well anyways if I made a huge map out of data statements that where 1 pixel by 1 pixel and tell the computer that 00 is passible and 01 is impassible would this slow my program down to a slug state?

MMMMMM Low level programmimg...
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 25th Sep 2003 01:59 Edited at: 25th Sep 2003 02:00
Personally I think it would be fine, more of a memory issue. But is your main sprite going to be moving just 1 pixel at a time? Mathematically, you might not need all those checks if your sprite moves 2 pixels at a time.

Pacman actually moves 32 pixels before a collision check is made.

Pincho.
MagiKnight
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location:
Posted: 25th Sep 2003 02:59
i could make my charactor move 2 pixels .. i dont think it would matter ..lol

MMMMMM Low level programmimg...
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 25th Sep 2003 11:32
Anything more than the size of the screen would need a lot of memory, perhaps there's a more conservative ways to do it.

If your engine uses tiles on a grid, like maybe a mario style game - you could use the tile numbers and a pre-stored bytemap for each tile. Your map could be any size really, because you'd only need to grab the tile number under the check location, which is a simple case of dividing the location by the tile size. After that you get the mod of the location to work out where in the tile the location is - then check it with the bytemap array.

Could you elaborate on what you need, there's always a shortcut .


Van-B

My cats breath smells of cat food.
MagiKnight
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location:
Posted: 25th Sep 2003 14:26
Hey Van B this is what I want to do
I have an array that defines all the tiles on the screen i have another one for the sprites but i tried making another array only consesting of 1 and 0 sorta like binary 1 = impassible 0 = passible
and i "dim"'ed a map of data statements that are the exact same size as my tilemap ... the only problem is my tile map is 512x384 and my collision map is only 11x11 and I have no idea how to make it see that there is a muitliplyer cause my array dementions are 11,11 on every array! ...if anyone knows whats wrong or how to fix it
please tell me

MMMMMM Low level programmimg...
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 25th Sep 2003 15:00 Edited at: 25th Sep 2003 15:01
Yeah, I thought that. Firstly you need to get the tile location, like the tile number where your checking collision on - then use a sorta mask array which is the same size as a tile.

Say your map array was called MAP, and you had a 2D array with 1's and 0's for the mask of each tile called MASK - it has to be the same size. Assuming a tile size of 32x32 and an 11x11 map, you'd do this to check a specific point:

` Map array
DIM MAP(11,11)
` Ten different masks
DIM MASK(10,32,32)

do
if col(mousex(),mousey())=1 then text 0,0,"Col"
sync
loop

`Collision function
Function Col(x,y)
xx=x/32
yy=y/32
col=0
if xx>-1 and xx<11 and yy>-1 and yy<11
tile=map(xx,yy)
mx=x-(xx*32)
my=y-(yy*32)
if MASK(tile,mx,my)=1 then col=1
endif

Endfunction col


Now that's not designed as a copy and paste style demo, it's to give you the basic principles, you'll have to work on it.

To get the mask data into the array, you can just paste your image onto a bitmap and use the point command, anything but 0 should be set to 1. If you want to check collisions with another mask, like if you had a mask for your character too, you'd step through each pixel on the mask and check it's location - this can easily be done with offsets on the original collision location, however it will be a lot slower. Remember to exit the loop when finding a collision if you do this to speed things up.

There is another option that is too complex to go into here in detail, just watch for the Jetpac2003 source next month, it uses a weird sorta wave collision. Like the object would be cut into vertical slices, and the 2 heights are stored, so a platform would be easy to make a slice collision mask for, but really complex objects need to be split up. It looks sorta like a low res sound waveform. Because it's only checking 2 heights for each segment along the X axis, it's much faster than checking every point. All my slice collision needs to do is step through each nearby platform and check to see if there's any overlap. I won't pretend the code is easy, but there is a program for making the slice maps easily (and automatically would you believe) - and if I can, I'll make a simple demo of using the system. It could well be among the very fastest 2D collision methods. Note that Jetpac has been debugged more, and the collision is much smoother now than the released version.


Van-B

My cats breath smells of cat food.
MagiKnight
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location:
Posted: 26th Sep 2003 05:34
Thanks but I do beleave I've found away to use my Assembly skills in DB Pro

MMMMMM Low level programmimg...

Login to post a reply

Server time is: 2024-05-05 19:24:28
Your offset time is: 2024-05-05 19:24:28