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! / 2d Collison advice

Author
Message
ConorH
22
Years of Service
User Offline
Joined: 5th Feb 2003
Location:
Posted: 3rd Jan 2005 02:34
Im trying to get my game to load a map and have the little sprite character walk about and not walk into certain things. Does anyone have any good resouces for tutorials or methods to create a system like mine. I noticed that DBPro has a dodgy Pixel perfect collison detection, but this doesnt bother me much as the map is based on 32*32 tiles.

Would it be wise to make each tile a sprite, or just to paste the whole map to the screen. I Also tried to use Sprite collision(1,0) but it returned it even when my only sprite on the screen is the main character (1). Any advice on that and anything else is appreciated

Thanks

its my new rat tail dog!
pizzaman
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location: Gateshead, UK
Posted: 3rd Jan 2005 05:04
hi

Heres something I made a while ago - its kind of a mini tutorial. Its split into 2 programs, the first deals with collision of a tile map, the second part scrolls it with collision implemented. If you just run the code the second part is automatically run.



pizzaman
ConorH
22
Years of Service
User Offline
Joined: 5th Feb 2003
Location:
Posted: 3rd Jan 2005 06:20
hey thanks looks like you might have solved my problem.

its my new rat tail dog!
Tapewormz
22
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 17th Jan 2005 09:08 Edited at: 17th Jan 2005 09:11
Hey pizzaman, what do you think of this idea I posted. Is this the same thing you're doing here? I'm checking 5 directions instead of 4. The method I proposed offers the abillity to have angles, curves and other irregular collision surfaces.

http://forum.thegamecreators.com/?m=forum_view&t=46069&b=4

pizzaman
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location: Gateshead, UK
Posted: 17th Jan 2005 20:42 Edited at: 18th Jan 2005 00:24
Hi Tapewormz

I'm a bit confused as to how your theory works, could you elaborate on it.

The way I usually do my collision (which is not in the supplied code above - as I thought it would confuse people), is have a memblock with all your tile data in it. This data is used to draw the tiles to the screen and acts as which areas that are passable or not. Using your current and old (previous loop) player co-ordinates, you can distinguish what direction they moved in, and whether they are now on an impassable tile.
If they are on an impassable tile you can find out whether its x, or y, or both ordinates that caused the new player's position to be on an impassable tile and take the appropiate action by considering which direction they moved in.

Also though to allow more than just square based collision, you can have a list of tiles with specific collision routines and have them act however you want them to, say for ramps in a 2D platformer etc.

Hope that explains something

ATM I'm working on a 2D Tile Mapper/Level Editor, and once made I'll be able to show off some programs. It's only about 5% done at most, but looks very professional and is working at a basic level. Hopefully by March I'll be able to show it off, along with some collision routines, although that might be a bit optimistic.

Tapewormz
22
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 18th Jan 2005 10:01 Edited at: 18th Jan 2005 10:01
Well I use two arrays to hold the x and y pixel locations of where a sprite would be pasted if it was incontact with that tile at that x,y coord. Then you would apply your jumping and so on based on that. This would allow for curved collision, angles and irregular collisions with tiles.

So 100 8x8 sprites would be dimensionised as:
Dim tilex(99,8) as integer
Dim tiley(99,8) as integer

I'll code an example and come back.

pizzaman
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location: Gateshead, UK
Posted: 18th Jan 2005 10:55 Edited at: 18th Jan 2005 23:10
I get what your saying now. Basically your applying a kind of pixel perfect collision to your tiles, at certain collision points on the tile you move the player by a certain amount of pixels in the desired directions - if I'm reading this correctly. The only small problem with that method is that you would be using a lot of memory especially if your maps were larger. Infact this is the method I was thinking about using.

The other method I thought up was to apply simple mathematical rules to the tiles for collision - it works great for straight ramps, however it might be processor intensive for curved collisions due to use of sin,cos,tan to define the curve - altough curves can be approximated pretty well with multiple straight lines. This method would be fractionally slower than yours, but does use less memory.

Tapewormz
22
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 19th Jan 2005 07:12 Edited at: 19th Jan 2005 07:25
It doesn't use very much memory at all actually. Alot of games will have 512 tiles or less. It might take up 64K or so at the most for the collision. That's not a whole lot of memory, not at all.

It's not processor intensive at all, all the program is doing is moving the sprite along a pre-determined path. The path is the collision zone for each tile. Since most of these tiles will be repeated over and over again, it won't take up alot of memory because the angle tile and the strait tile's will be repeated hundreds of times and that's only a few bytes.

It's also not using any math for collision. It's just an invisable path for each tile.

I'll upload a snipit that show's how this method works. Basically, I got the idea by examining the method in which Tankoid's used it's collision.

pizzaman
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location: Gateshead, UK
Posted: 19th Jan 2005 08:52
I fully understand your method, so you don't have to upload a snippet, unless you want to of course . Yeah your right about the memory, my mistake (wasn't thinking properly ), however to lower the memory usage further you should use an array of UDT's and declare the collision parts as bytes, or use memblocks.

Tapewormz
22
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 20th Jan 2005 09:24 Edited at: 20th Jan 2005 09:24
Yeah, I'm sure that alot of optimisation could be done to the idea that I haven't touched on yet. I'm sure there are better methods, but this one. I'm gonna look into optimisation like you suggested. Using bytes would work great, assuming that all the tiles are under 255x255 in size. I imagine that they would be no larger than 255x255.

You said you're working on a tile based map editor? I've got some good suggestions for one if you're working on one.

pizzaman
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location: Gateshead, UK
Posted: 20th Jan 2005 11:37
Good luck with the collision, I'm sure you'll make it fast and efficient. Actually you've intrigued me with this, I might have a go later on. Keep me up to date on this please.

Yeah I am making a tile based map editor, at the moment I have 4-5 sides of A4 paper on all the features I have planned. Could you email me the suggestions you have, its just I don't want any features posted until I can get my demo out (March roughly), and make a WIP thread for feedback and suggestions.

Its been good bouncing ideas around with you, o and btw I like some of your art on deviant, especially your most recent piece - I take it your some sort of artist?

Login to post a reply

Server time is: 2025-05-17 19:46:58
Your offset time is: 2025-05-17 19:46:58