Own code for tut8, poos are being eaten randomly?

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Maestro
Posts: 2
Joined: April 25th, 2017, 3:42 pm

Own code for tut8, poos are being eaten randomly?

Post by Maestro » April 25th, 2017, 4:21 pm

Im new here and loving the beginner tutorial series so far. I was watching tutorial 8 and following what Chili was doing, but afterwards i started to write my own code that would do the same things as his (better practice i assumed). I had was at the point in writing the code were the poos would disappear if the face went over them. But when i tested it things got weird. Most of the time when i went over them nothing would happen, sometimes they would disappear, other times they would disappear when the face wasn't even near them (0_0). I honestly have no idea whats wrong with the code, i even tried using the debugger to try to find the problem and only got more confused due to my lack of knowledge with it.

Help please :)
Attachments
chiliframworkcopy.zip
Hopefully i followed the instructions on how to make it smaller
(2.42 MiB) Downloaded 106 times

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

Re: Own code for tut8, poos are being eaten randomly?

Post by albinopapa » April 25th, 2017, 7:11 pm

Code: Select all

		face_x + 20 <= poo1_x + 24 &&
		face_x >= poo1_x &&
		face_y + 20 <= poo1_y + 24 &&
		face_y > poo1_y
The collision algorithm is incorrect. Should be
if left_a <= right_b and right_a >= left_b and
top_a <= bottom_b and bottom_a >= top_b

What you have is
if right_a <= right_b and left_a >= left_b and
bottom_a <= bottom_b and top_a > top_b

Code: Select all

		face_x + 20 <= poo2_x + 24 &&
		face_x >= poo1_x &&
		face_y + 20 <= poo2_y + 24 &&
		face_y > poo2_y
There is a typo here.
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

Maestro
Posts: 2
Joined: April 25th, 2017, 3:42 pm

Re: Own code for tut8, poos are being eaten randomly?

Post by Maestro » April 26th, 2017, 3:12 pm

Yeah that worked. Thanks so much!

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

Re: Own code for tut8, poos are being eaten randomly?

Post by albinopapa » April 26th, 2017, 5:03 pm

Glad to help.
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

Post Reply