Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Comparing Colors works sometimes

This thread is locked; no one can reply to it. rss feed Print
Comparing Colors works sometimes
InfiniteLoop
Member #8,434
March 2007

Hello everyone, here is the scenario. Making a 2D platformer, I have my standard background image, and a completely black and white version also loaded into memory. The black and white image is almost completely white, with the platforms themselves being completely black (no gradiant). Every cycle, I am comparing the color on my BW background against the color black to determine if I am standing on the ground. This works, until randomnly my avatar falls through the ground. It seems to be random at any given place and I cannot figure out why. Can you tell me what I am doing wrong? Furthermore, is there a better way to handle platforming?

#SelectExpand
1int color_equiv(ALLEGRO_COLOR c1, ALLEGRO_COLOR c2) { 2 3 unsigned char r1, g1, b1, r2, g2, b2; 4 5 al_unmap_rgb(c1, &r1, &g1, &b1); 6 al_unmap_rgb(c2, &r2, &g2, &b2); 7 8 if (r1 != r2 || g1 != g2 || b1 != b2) 9 return 0; 10 else 11 return 1; 12 13} 14 15//in my update 16if(!color_equiv(al_get_pixel(image, x, tempY + 6), al_map_rgb(0, 0, 0))) 17{ 18y = tempY; 19}

The color_equiv function was by another user on these forums. Thanks for your help

EDIT: Nevermind, figured it out. The question still stands though whether or not there is a better way to handle this

taronĀ 
Member #10,584
January 2009
avatar

Why not use tilemaps. Or a list of bounding boxes or maybe a list of polygons?

The only game where I can imagine a bitmap to be truly useful for collision detection is a game like worms.

InfiniteLoop
Member #8,434
March 2007

I figured tilemaps would not be accurate enough. Also, I figured that collision detection against many, large, bounding boxes would be less efficient that comparing a single point. Finally, I figured using bitmaps would allow for rapid map development.

Am I wrong?

taronĀ 
Member #10,584
January 2009
avatar

Well you could always put bounding boxes in a grid. So you only have to check for boxes close to the entities.

Or, although more difficult, you could use a quadtree to put your boxes in.

Also comparing to a single point is not going to be very accurate, at all.

Audric
Member #907
January 2001

I figured using bitmaps would allow for rapid map development

If you have found the right tools to keep the "map" and the "collision map" synchronized, then it's a good development method.

Go to: