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 / bitmap collision

Author
Message
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 17th Jun 2009 23:50 Edited at: 18th Jun 2009 01:01
If you had a 2000 by 2000 bitmap(or more)and you had a island in the middle of the bitmap how would you make collision for the ends of the oddly shaped island?

If at first you don't succeed-Pause-Go to last checkpoint
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 18th Jun 2009 01:08
this is just one idea but you could do the same thing we were planning on doing with the DarkNoobs project, use a GOOD image editing software with alpha editing ability (ask ashigda which one he used) and change the alpha for either the water or the island

then in game make a memblock of the bitmap (I think you can do that with bmps as well as images, but check) and check the alpha value of the pixel(s) needing checking, thats the 4th byte of data for a pixel in a memblock, after the bgr (rgb backwards, thats how a memblock store color data)

There are only 10 kinds of people in the world, those who understand binary and those who dont
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 18th Jun 2009 01:26
I'm not sure what you just said.Do you mean I can use a command
called alpha value on a pixel and if it equals a certain thing then do somthing.Could you leave a example thats the best way I'll understand.thx

If at first you don't succeed-Pause-Go to last checkpoint
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 18th Jun 2009 03:36
You'll need to learn about memblocks and how bitmaps are stored in them.
Have a look at my memblock bitmap functions in my code bonanza! thread. I have a point function that works like DBC's point but it is much faster because it uses memblocks.
Point is a command that returns the RGB of the given pixel incase you didn't know.

There is an eight letter word. You can insert a letter into it or remove a letter from it without changing its meaning. Answer
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 18th Jun 2009 05:54 Edited at: 18th Jun 2009 05:55

2 questions
1.how do you "paste" a memblock bitmap on the screen?
2.why is my print command not working?

If at first you don't succeed-Pause-Go to last checkpoint
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 18th Jun 2009 07:28
The alpha channel thing is fine if you are using 32 bit or if you are going to convert 16 bit into 655 format or rather 1555 format in which case you check a single bit for the presence of alpha, and you are sure that you are not manipulating the graphics with DBC commands (i.e. taking part of a larger image with get image i,x,y,x1,y1). But a more general way to approach it is to get the boundaries between two images that overlap and only check those pixels. if you are using transparency then you check for a black pixel in either image in which case there would be no collision at that point. As soon as two pixels have color in the same position, you have collision and exit the check.

If your images don't change, you can use arrays instead of memblocks which are faster. If you want super fast, then use memblocks with a DLL (because you can't pass arrays to a DLL).

Enjoy your day.
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 18th Jun 2009 07:29 Edited at: 18th Jun 2009 07:32
I think this memblock thing is going to be too complicated for me right now.So is there anyother easyer way to make collisions?
And if not then I'll make the island just a box.[]

@latch,
You say I can use arrays?(I missed your post)

If at first you don't succeed-Pause-Go to last checkpoint
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 18th Jun 2009 07:44
If your images dont change, load up the colors into arrays. It's the same process as the memblocks except you use arrays to check the positions. The reason arrays are faster than memblocks in this case is because you have to use math to find the x,y positions in the memblock. In an array, you can access directly without the math.

If you look through the DBC challenges, I made a matrix 3d text program. In there is a formula to read a bitmap out of a file and convert the colors to heights. If you use that formula, you can read your bitmap colors directly from disk into an array(s). I think it worked in both 16 bit and 32 bit. I can't test it because I'm using a non windows OS at the moment. But anyway, once you have your images converted to arrays, you just use the x,y for each and find out if they overlap. You'd have to calculate the offset so that the x and ys line up correctly.

Enjoy your day.
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 18th Jun 2009 07:57 Edited at: 18th Jun 2009 07:58
alright,thanks latch.I'll see if I can find it.32 bit is fine

If at first you don't succeed-Pause-Go to last checkpoint
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 18th Jun 2009 08:53
Quote: "1555 format"

I haven't even tried that, I'm going to play around with that now ^_^
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 18th Jun 2009 23:51
or another way would be our 1st plan for collision in the DarkNOOBS project

have an offscreen bitmap and color each pixel that has collision red on the new bitmap, then when you are checking for collision just check the pixel on the other bitmap and if red then you have collision

There are only 10 kinds of people in the world, those who understand binary and those who dont
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 19th Jun 2009 06:14
would'nt that use the point() command?

If at first you don't succeed-Pause-Go to last checkpoint
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 19th Jun 2009 06:26
not if you experiment with memblocks, image memblocks arent complicated:



so you just use

memblock dword(memblock number,12+4*(height*y+x))

to return the color value of the pixel at x,y

the reason we use memblock dword instead of byte (which is what the individual rgb is stored as) is because this checks the total color value, rather than the r,g, or b value

just make sure you are in 32 bit color depth or this formula doesnt work

on second thought, you could just get the image at x,y,x+1,y+1

then it is a smaller image and should be faster, then you would just use

memblock dword(memblock number,12)

to get the color value, since its only 1 pixel

sorry for huge post

There are only 10 kinds of people in the world, those who understand binary and those who dont
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 19th Jun 2009 06:36 Edited at: 19th Jun 2009 06:39
Thanks for the huge post.I'm going to be messin around with this memblock stuff,but for now I'll just make my island a box.Then when I figure this stuff out I'll change it or somthing.

If at first you don't succeed-Pause-Go to last checkpoint
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 19th Jun 2009 17:49 Edited at: 19th Jun 2009 17:50
Actually, couldn't you just make your program approximate your island as a series of rectangles, and check each rectangle for a collision?

Or alternatively, could you draw your backdrop of (presumably) the sea, draw a sprite of your island at the required location (the island's bitmap image would have to be on a black backdrop, so it didn't have a black border when DBC drew it to screen) and then just use DBC's pixel perfect sprite collision to check if another sprite has touched it?

I'm not sure how fast this would run, I'm afraid I haven't used 2D much!

"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 19th Jun 2009 20:54
Hi there!

Right, I dug around and found my code for my 2D game maker. In that code, there is a section where I import every pixel from the bitmap, and that code came from TDK.

So here is what I would do.

Lets say this is your island:



The graphics for your island can be higher than this. Then you make a background image. This image never really gets displayed, but is used for collision checking. It would look something like this:



This background image defines where the island is using one colour. So all you do then, is import that image with the following code:



And then you check for collision in your code by checking if collision(playerx,playery)=1. And that's that!

I hope that helped you out, thanks very much and goodbye!

TheComet


Make the path of your enemies easier with Waypoint Pro!
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 19th Jun 2009 21:03
very interesting comet, cool use of file data

There are only 10 kinds of people in the world, those who understand binary and those who dont
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 20th Jun 2009 00:06
Thanks comet that should work.

If at first you don't succeed-Pause-Go to last checkpoint
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 20th Jun 2009 00:52
Is there anything im missing?

What I'm doing is im doing this check then I start my loop and in my
loop I have...

So if the mousex() and mousey() position is'nt green then it should
print "hit" right.But whats wrong is it randomly prints "hit" and somtimes not at diffren parts of the map.and my whole collisionmap is green.

If at first you don't succeed-Pause-Go to last checkpoint
Brick Break
User Banned
Posted: 20th Jun 2009 01:19 Edited at: 20th Jun 2009 01:24
Just make a monochrome (black & white) collision map and load in into an offscreen bitmap. Then check the coordinates against that bitmap using the point() function. It would run incredibly slow, however. If you had the enhancement pack, you could just use sprite collision and a textured or colored backdrop. I think there may even be a 2d collision function somebody made. Diggsey may be able to help you with that.

t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 20th Jun 2009 05:26 Edited at: 20th Jun 2009 05:31
nevermind.

If at first you don't succeed-Pause-Go to last checkpoint
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 21st Jun 2009 02:11 Edited at: 21st Jun 2009 10:33
I did what Brick Break said and I don't know what to put if there is a collision.This is what I put and it does'nt work.

The oldx,oldy thing does'nt work ethier.

EDIT:

Nevermind the problem was just that I did'nt paste after the movement,I did it before so ya.

If at first you don't succeed-Pause-Go to last checkpoint

Login to post a reply

Server time is: 2024-05-20 12:22:49
Your offset time is: 2024-05-20 12:22:49