Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Pixel Perfect Exercise

This thread is locked; no one can reply to it. rss feed Print
Pixel Perfect Exercise
Scooter
Member #16,799
January 2018

Hi Dizzy:
Don't understand why my last post is locked.
Anyway, to continue our last discussion, I have posted above what I
have been working on the last few weeks. I believe what I needed was
pixel perfect collision to work out my problem. I got some info off
the internet but it was C++ code. I tried to convert to simple C but
got too many errors, so T put my C code in the same program and got
it to work. I still have the same problem I have had for weeks. The
ball will NOT enter the slot in the disc. Take a look at what I have
and you will see the problem. Just click mouse in lower part of the
frame and the ball will take off. It will bounce around the diameter
of the disc but never enters the slot. Could never fix this problem.
If you have some time take a peek at what I have. Thanks!

Dizzy Egg
Member #10,824
March 2009
avatar

Hello Scooter, I cannot see any code?

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Scooter
Member #16,799
January 2018

Hi Dizzy:
Let me try this again!

It won't accept my zip file!

Here are all files except the background file.

It would not load that file for some reason.

Thanks!

DanielH
Member #934
January 2001
avatar

You create the mask on a stationary image, but the image is rotating. You would need to also rotate the mask.

Scooter
Member #16,799
January 2018

Hi Dizzy:
I have written another program. This time in pure C code.
Uses the same items as the one posted before. You will have
to use your own background because the site will not upload
the one I use. It is much less complicated than the one before
but still suffers from the same problem: ball will not enter
the slot in the rotating disc. Anyway, maybe it will be able
to help someone.

Thanks

Daniel posted that I needed to rotate the mask instead of the bitmap.
I agree, but I never found a way to do this since Allegro is looking
for a bitmap, not a mask. Oh well, problems continue.

Dizzy Egg
Member #10,824
March 2009
avatar

Hello Scooter. I made some changes to the attached code, the ball will now go in the gap, even when rotating. Couple of things, when you were filling the mask, you had:

mask->bits[y * width + x] = (color.a != 0);

but should have been:

mask->bits[x * width + y] = (color.a != 0);

(had the x/y the wrong way round).

Secondly, your check_collision code wasn't right, meaning that the ball could never go in the gap, even if not rotating. I've added a new function called CheckCollision that does a bounding box first, then properly finds the collision range for both masks to do per-bit checking.

Also, I recalculate the mask every time the disc is rotated, so that the mask reflects the rotated disc image, which you can see in the timer update/draw.

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Scooter
Member #16,799
January 2018

Hi Dizzy:
Yeah, I agree with Edgar, nice work! I would have never got
it to work since I was missing so much. Looks and works great!
This is the first time I have done much with pixel perfect and
I have much more to learn. Thanks again for all your help!!!!

Go to: