Is color collission possible?

BlitzPlus Forums/BlitzPlus Programming/Is color collission possible?

koekebakker(Posted 2004) [#1]
Okay, here is the case... I was able to generate
a line drawing (outlines) out of a edited map for a 2d
platform game.

But is it also possible to USE a line drawing for colission? In other words can B+ notice if 2 colors over-
lapping eachother. Let say if a red pixel overlaps a bluepixel then you have bumped into a wall. If this is possible, what command do I have to use?

Mucho gracias


Ryan Moody(Posted 2004) [#2]
Use the GetColor command to check for the wall's colour, and use your character's x and y co-ordinates (with appropriate offsets) as your reference point for checking if a collision has occured.

Ryan


Mr Brine(Posted 2004) [#3]
I'd recommend the rectsoverlap command, as in my experince this command is very fast!

Mr Brine


aab(Posted 2004) [#4]
possible, but far too slow for any way i would do it.
commands like readpixelfast() are ironic to their own name.

Instead of checking colours on an image overlapping, what about making a version of the image that has only the blue/red etc, and check that for overlapping. :faster?
;
i made a program that saves a copy of an image with only the colour you specified retained (and all other pixels are 'void' coloured to the void colour you specify:default 0,0,0). if you think it'd be any use i could post it in.
;
Edit: i then take my isolated colour bmp, into paint, and save it as a monochrome bmp to take up less stored mem.


koekebakker(Posted 2004) [#5]
thanks aab (and others). the only thing I need now is a 486
emu for testing :)


King(Posted 2004) [#6]
I use GetColor for collision detection between the player sprite and the monsters. I find that is it way too slow, but I have got round it in two ways.

Firstly of course you only do the pixel by pixel check if the rectangles over lap and only between the player and the monsters (I make monsters bump into each other or whatever just by checking their rectangles, not he pixels).

Secondly, here's the clever bit. Well I think it's clever anyway. I make it only check the pixels every ten game loops, and even then I only check every one in twenty pixels randomly.

This may seem odd but in practical terms it works perfectly well. If you land on the monster it may take a second or so before the pixel collision is detected but this doesn't harm the game play at all, in fact it makes it seem more fair as you can maybe overlap the corner of the monster and you don't die, for example if you are jumping over the monster and your foot touches the monster's ear. But if you really land on it by more than a few pixels you die.


aab(Posted 2004) [#7]
interesting.. I'll be giving some of that a try myself


Who was John Galt?(Posted 2004) [#8]
Unless you want to see what colour you landed on, why not just use imagescollide?


Moore(Posted 2004) [#9]
Here's one for you; the heck with getColor and readPixelFast store your image's aRGB values into a bank or simple array and run your collision detection against that its much faster and I think there even is a native imageToBank function in B+.


Zenith(Posted 2004) [#10]
faster yet, use an array or a bank with multidimensional code


monkeybot(Posted 2004) [#11]
i really like those last two ideas...


Berserker [swe](Posted 2004) [#12]
"faster yet, use an array or a bank with multidimensional code"

Me to. My 2D maps are made by a mapeditor wich i made myself, anyway when it saves the map (after you've vritten the name) it does as follows:

SaveFile = WriteFile("..\whatever\"+ThisFile$+".whatever")
For x = 0 To 800
For y = 0 To 100
For z = 1 To 2
WriteInt(SaveFile,map(x,y,z))
Next
Next
Next
CloseFile(SaveFile)

And then when i load it it looks (much similar) like this:

LoadFile = ReadFile(ChoosenFile$)
For x = 1 To 800
For y = 1 To 100
For z = 1 To 2
map(x,y,z) = ReadInt(LoadFile)
Next
Next
Next
CloseFile(LoadFile)

The map is only loaded once at the start of the application and the values of the map is stored in the array.

To display things at the screen here is an easy example:

For x = ScrollX To (ScrollX + 10)
For y = ScrollY To (ScrollY + 5)
Select map(x,y,1)
Case 1
DrawImage Sand,x*20,y*20
Case 2
DrawImage Dirt,x*20,y*20
End Select
Next
Next

As you may understand i use pictures that are 20*20p in size. I also use animated pics but thats not relevant code for now.

A easy Player-Check could look something like this:
(The player pic is 50*50p in size)

If map((Player_X+50),(Player_Y+50),1) = 0 Then
;If theres no ground 1pixel ahed of the player
;Then do whatever you want

Fall = True
Score = Score + 99
YourMamma$ = "Betty"
;or whatever

Endif
;And so on
;Make differnt checks for enemies or something
;Maybe the player gets hurt if he/she walks on lava?
;Only your fantasy may stop you

Good Luck!