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 / Basic collision mapping

Author
Message
Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 20th Feb 2008 18:02
Hi all,

Another n00b here, i used to use Div games studio 1+2 a few years back but haven't really done much in recent times, so im starting out with Darkbasic now.

Ok so, simple question:
Is there a function where i can create a bitmap as a collision map?
For example, a certain colour, lets say red, would be a surface?

I know there used to be a function in div where you could say:
"red is a solid colour"

then write the functions for moving a character for example, and if that character came into contact with "red" it would collide.

I think what i did once was to have this collision map loaded, and then on top of that load an identical map with the graphics on, and have the collision map hidden.

I've googled and searched through the forum but havent yet found if this is a possibility?

cheers for any advice,
Paul
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 20th Feb 2008 21:29 Edited at: 20th Feb 2008 21:32
i don't think a function exists, per se, (you should look through the code base, though) but since you're considering a 2D-image for collision, you could:

a) make an array from the image and use the array to check for collision. (ie, as you analyze the map, insert 1's for "red"/impassable blocks, 0's for areas you can move over/through, or vice versa).

b) keep the image on another bitmap (or, make a memblock from it) and check against the corresponding pixel color (using point or memblock commands, if you are familiar with them).

either options shouldn't be too difficult to incorporate.

Virtual Nomad
AMD XP 1800+ (~1.6 Ghz) / 1.5 GB RAM
ATI Radeon 8700LE 128 MB / Windows XP
Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 20th Feb 2008 21:43
interesting, so really you'd suggest I hard code either each level in turn, or a small "engine" (if you can call it that) which in turn can create the maps/levels ?

Thanks anyway I was just putting the feelers out to see if there was a simpler way of doing things.

I suppose this way I will explore more of darkbasic and maybe even utilise 3d functions.

Cheers
Paul
Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 20th Feb 2008 22:20
i've found:
http://www.thegamecreators.com/?m=codebase_view_code&i=3cec3902285ee84ce03f737c596dbe73
by: Zac Romero

does anyone know where i can find a contact point for him? as i am having some trouble to get his code to run, no errors, perhaps just a compatability error as it wont run with dbp.

Look forward to hearing from someone,
Paul
Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 22nd Feb 2008 19:21
sorry to drag this up again, and i hate to sound like i know what im on about when i clearly dont, but i have noticed:
http://forum.thegamecreators.com/?m=forum_view&t=122191&b=4

"aluseus God" - i think, has used a collision map idea, just waiting to hear back from him on how he achieved it as i would find this way of collisions easier for a basic game.

but if he doesn't get back to me, has anyone else tried this? and was the result good or bad?

the codebase had a game with a submarine in it, but i couldnt actually get it to run so gave up with that.

thanks again,
Paul
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th Feb 2008 07:28
Should be pretty simple. You can either translate your world position into a position on your collision image then check the color at that point/pixel, or you can read in the image and parse its data into an array for simple grid-based collision.


jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 28th Feb 2008 20:08
I know this might be complex for a new user but - You can load a image (Collision map like you said) and then do MAKE MEMBLOCK FROM IMAGE. (Its easier if its a 32bit depth image... Or your screen is 32bit depth ... I forget BUT..)

Now you have a memblock where the first 12 bytes are about the image:

First 4 Bytes = Unsigned Integer = DWORD = Image Width
Next 4 Bytes = Unsigned Integer = DWORD = Image Height
Next 4 Bytes = Unsigned Integer = DWORD = Image Depth
(pseudo code)


Now from OFFSET 12 thru (ImgWidth * ImgHeight * 4) is your picture.
Now that your image is in a memblock - you can delete the image you loaded.

Now you write code that treats the image pixels like an array. Note Each PIXEL is 4 bytes Wide - RGBA (But not in that order) Pixels Are arranged ACROSS, down a row, ACROSS, down a row etc....

This can be useful to manually use a collision map the way you describe.

BatVink knows the RGBA order... and might be more knowledgable here than me and/or explain it better

Login to post a reply

Server time is: 2024-11-25 07:22:23
Your offset time is: 2024-11-25 07:22:23