Colliding not Working - BegC++ Tutorial 8

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
CKatt
Posts: 15
Joined: March 2nd, 2018, 8:37 pm

Colliding not Working - BegC++ Tutorial 8

Post by CKatt » March 2nd, 2018, 9:57 pm

Hi dudes,
I'm a super n00b so i'm having a tough time figuring this out.
There seem to be something wrong with collision detection. If I just manually change IsEaten to true then no problem so i think the problem is in the IsColliding function but I can't figure out what. I don't get any errors when I run the debugger so I'm not sure where to look.
Thanks to any one who can help.
Attachments
Chili Framework 2016 -game CKatt.zip
(89.88 KiB) Downloaded 128 times

CKatt
Posts: 15
Joined: March 2nd, 2018, 8:37 pm

Re: Colliding not Working - BegC++ Tutorial 8

Post by CKatt » March 2nd, 2018, 10:33 pm

No sooner did i post this then i found the problem:


const int right0 = x0 + width0;
const int bottom0 = y0 = height0;
const int right1 = x1 + width1;
const int bottom1 = y1 + height1;
return
right0 >= x1 &&
x0 <= right1 &&
bottom0 >= y1 &&
y0 <= bottom1;

i typed a = rather then a +. the old lazy shift finger problem. :oops:

Any way, my question now is: how could I have used the debugger to find this?
Thanks,

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Colliding not Working - BegC++ Tutorial 8

Post by albinopapa » March 3rd, 2018, 12:02 am

Breakpoint in the beginning of the collision code
F10 to step through each line, when something doesn't "add" up, you found your bug.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

nG Inverse
Posts: 115
Joined: April 27th, 2012, 11:49 pm

Re: Colliding not Working - BegC++ Tutorial 8

Post by nG Inverse » March 3rd, 2018, 12:44 am

Typographical errors like this which don't get caught by the compiler are the hardest to debug. Like albinopapa suggested, that is the only way the debugger is useful in this scenario.

This is why it is always recommended to make small changes to your code and test immediately. This way you have a smaller code base to scrimmage through to find the error.

CKatt
Posts: 15
Joined: March 2nd, 2018, 8:37 pm

Re: Colliding not Working - BegC++ Tutorial 8

Post by CKatt » March 4th, 2018, 6:37 pm

Thanks for the tips guys!

Post Reply