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.

Newcomers DBPro Corner / Tile Collision, How to improve?

Author
Message
Binary Coder
17
Years of Service
User Offline
Joined: 26th Feb 2007
Location: Queensland, Australia
Posted: 24th Dec 2009 06:44
Hey Everyone! I've been away from DBPro for a long time now, and i just picked it up again last week something to do in the holidays (australia, not sure about the rest of the world )
For the past week I've been learning as much as I can, pretty much from scratch, desperate to actually get somewhere with it this time

Anyways, I've kinda been struggling for a couple of days. I'm attempting to make a small 2D plaformer, in hopes to learn alot. I finally worked out how to make a level from tiles (see code), but now Im kinda lost where to go with the collision. I've searched what there was on the forum and found what i have now, but its realy bad imo.



So anyone have any ideas on how to better the collision?
oh and any tips on how to clean up my code are welcome too

Cheers, BC
oh and Merry Christmas!!!
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 24th Dec 2009 12:34
Nice to see another Aussie on the forums! Damn you being on holidays - I get the weekend off, that's it.

Anyway for collision, look into using the SPRITE HIT command. For example, if the sprite for the player hits the sprite for a wall or something, then the player stops moving. You could do the same thing for falling - if you're not colliding with the floor sprites, then move the sprite downwards until you are.

Having said all that - i'm not the greatest with 2D.

Binary Coder
17
Years of Service
User Offline
Joined: 26th Feb 2007
Location: Queensland, Australia
Posted: 26th Dec 2009 08:30
Not too many of us around is there? lol I'm on holidays from school

I thought of that one, although, im only using a sprite for the player character. The rest are just images pasted to the screen. Thanks helping out though
I think I may have heard of collision based on arrays or something? Is that a possible solution? Does anyone know how this may be done?

Cheers,BC
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 27th Dec 2009 23:52
Hey, enjoying your holidays? I am on holidays as well.

Anyway, I have seen from other threads that both the 'sprite collision' and 'sprite hit' commands don't work and I have tried both of them to no sucess, for pixel perfect collision anyway. For pixel perfect collision I use eXtends commands. They do the job pretty well.

Here is the link

http://darkbasicpro.thegamecreators.com/?f=extends

Hope this helps

A clever person solves a problem, a wise person avoids it - Albert Einstein
Binary Coder
17
Years of Service
User Offline
Joined: 26th Feb 2007
Location: Queensland, Australia
Posted: 28th Dec 2009 03:46 Edited at: 28th Dec 2009 04:00
Yeah, enjoying them, if a little boring

Wow, thanks for the link I will definately look into it Having pixel perfect collision will definately be a great thing to have.

Otherwise, does anyone know how i may be able to find the current tile of the player sprite? That way i may be able to find the adjacent tiles around it, and go from there. Is that a good alternative?

Cheers, BC
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 28th Dec 2009 11:38 Edited at: 28th Dec 2009 12:21
I'm certain that if you check the code snippets board you'll find at least a couple of ways of doing this without plugins.

I just did a quick search (using the search box at the bottom) for "pixel perfect" and there were indeed at least 2 examples there.

I would link you but I'm using my mobile phone atm.

I remember looking into this years ago and I remember seeing an example using memblocks to do it.

Sorry thats all a bit vague

>edit<

here is one example

Binary Coder
17
Years of Service
User Offline
Joined: 26th Feb 2007
Location: Queensland, Australia
Posted: 29th Dec 2009 10:22 Edited at: 29th Dec 2009 11:31
Thank you very much for that example of pixel perfect collision Unfortunately I have no understanding of memblocks at this stage. Definately look into it when i have that down though. Thanks very much.

I wrote up a quick snipet today to test out something I had in mind for finding the adjacent tiles.



So thats what I have so far. It finds the four corners of the sprite, and what tile they currently occupy.

Any feedback?

EDIT: I just coded up this subroutine that sorta handles the collision. It seems like an overly tedious way to do this. Is there any other way?


Cheers, BC
Binary Coder
17
Years of Service
User Offline
Joined: 26th Feb 2007
Location: Queensland, Australia
Posted: 2nd Jan 2010 14:55 Edited at: 2nd Jan 2010 14:56
Sorry for the double post.

Does anyone have any feedback? Any ideas on how to check the tiles around the character?

BC
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 3rd Jan 2010 16:52 Edited at: 3rd Jan 2010 16:54
I checked your quick snippet and made a few edits. This makes a few blocks in the center and then allows you to move around with proper collision.



Hope this is helpful,

LB

So many games to code......so little time.
Binary Coder
17
Years of Service
User Offline
Joined: 26th Feb 2007
Location: Queensland, Australia
Posted: 5th Jan 2010 23:39
Thank you! Thats what I was looking for. So it would be the same idea when implementing into a platform game?

BC
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 6th Jan 2010 17:37
You're welcome.

Sure, code similar to this could be used to make a platform game. Bear in mind that it is based upon square tiles, so if you have a graphic that does not take up the entire square, your collision will not be pixel-perfect. You should be able to design something that would work, though.

So many games to code......so little time.

Login to post a reply

Server time is: 2024-11-24 20:45:12
Your offset time is: 2024-11-24 20:45:12