Is there a way to check pixel color?

BlitzMax Forums/BlitzMax Beginners Area/Is there a way to check pixel color?

Booticus(Posted 2005) [#1]
Hey guys, Im a total Blitzmax newb so bear with me. Is there a way to check the color of a pixel? Here's a link of my screenshot (17k, small):


I wanted to figure out how to have the guys run ALONG the terrain, and I was thinking of basically checking the color of the terrain beneath him (the orange stuff). Any clues? I saw the collideimage functions, but wasnt sure if it was overkill.

Oh and can someone point me to the FAQs on how to submit code in a code window? I've seen the link before but naturally I cant find it now! Thaaanks!


-Mario


Perturbatio(Posted 2005) [#2]
I think that doing pixel checks might be a little processor intensive since you would presumably need to convert it to a pixmap first.

But since you appear to be drawing the lines manually, why not simply move a point along each line and use that as a handle to offset the drawing of the image from?

faq
see what are the forum codes?


Booticus(Posted 2005) [#3]
Cool. Is there a ridiculously easy way to do that? I already have a formula to find the "heading" of a dot from another dot. I can make it move like that by using the sample code from the asteroids game, etc......or am I over-complicating things again?

And thanks for the FAQ link!!!


Booticus(Posted 2005) [#4]
I guess I should clarify this is a little rip off of the Atari ST game OIDS (Yes I know its been remade!) But I'm doing this as a break from my other project. :) Im aiming to have the guys running around pell-mell on the terrain randomly changing directions from left to right, trying to escape the UFO (you) before you beam 'em up. :)


Robert(Posted 2005) [#5]
The trouble with pixel colour checking is that you would have to update the code if you make the terrain more pretty. What I do is to maintain a series of images which make up the 'visual' terrain, and a series of pixmaps which make up the 'collision' terrain, which has white in solid areas and black in non-solid areas.


Booticus(Posted 2005) [#6]
Robert would you have any source examples to share? I'm doing it with math for now, just to see how it works. For my way, its kinda complex...my terrain points have x,y coords, I pick a random one to start my people on, then I have my people select a random destination terrain coord, and then make em run to that by moving them from terrain coord to terrain coord....well...ugh! You get the point :) You can see I LOVE to complicate things. But in the end, it works. Just hate reinventing the wheel when someone knows an easier way.


Perturbatio(Posted 2005) [#7]
I just knocked this little example up, it plots points along the length of a line, should be easy enough to modify for movement along a line.



*EDIT*
Changed


DredPirateRoberts(Posted 2005) [#8]
To read a pixel from screen use code below

Local pix:Byte[4]

glReadPixels ( screenx, screeny-1, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, byte ptr pix )

pix then will have r,g,b in pix[0] pix[1] and pix[2]

Or just make an array the width of the terrain and keep the heights in it for each verticle scanline then just use the x position in array to read in height.


Booticus(Posted 2005) [#9]
Thanks all of you! I'll give it a try and let you know how it works out! You guys are the best!


Booticus(Posted 2005) [#10]
Well guys it works! I used the array idea by DredPirateRoberts

"
Or just make an array the width of the terrain and keep the heights in it for each verticle scanline then just use the x position in array to read in height."

The lin code provided is also great for stuff too!! AND so did the glReadPixels ( screenx, screeny-1, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, byte ptr pix ) too! I just had to invert the Y axis! Thank you all guys! I'll be sure to post the game when I got somn workin. Again you guys rule!!