Trying the Snek game again, small issue.

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
SamCam
Posts: 20
Joined: January 8th, 2020, 3:24 pm

Trying the Snek game again, small issue.

Post by SamCam » March 13th, 2020, 11:00 am

Hey guys;

Just working through these tutorials again after some time away, thought it would be good to rebuild the projects again before moving on.
I was trying to watch then code (&peek); rather than code along this time which helps me learn but also helps me break things...

Having a weird issue with the snek game, I ended up building a constructor for the Location.cpp as I wasn't following exactly along with Chili's vid, but it looks like because of this I'm getting a body segment of the snake put at either the default (0,0) position for Loc or wherever I construct it too...
It's not a massive setback or anything just a curiosity, I'm having a hard time debugging it!


repo link:
https://github.com/SamuelLouisCampbell/ ... ng_Two.git

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

Re: Trying the Snek game again, small issue.

Post by albinopapa » March 14th, 2020, 6:28 am

Your bug is here:

Code: Select all

void Snake::Draw(Board& brd)
{
	for (int i = 0; i < segNo; i++)
	{
		segments[i].Draw(brd);
	}
}
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

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

Re: Trying the Snek game again, small issue.

Post by albinopapa » March 14th, 2020, 6:32 am

Some things that helped me realize where it was:

1. Moving over the affected block ( 2, 2 ) didn't cause a game over, so it is just a visual glitch.
2. Stepping through the update portion of the code, the head moved and no other segments were updated since I hadn't eaten a goal yet.
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

SamCam
Posts: 20
Joined: January 8th, 2020, 3:24 pm

Re: Trying the Snek game again, small issue.

Post by SamCam » March 16th, 2020, 2:30 pm

Thanks once again albinopapa!

It was an issue with pre vs post incrementing, I think I can get my head around that.

Be back soon with many more questions no doubt, thanks for your time :-)

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

Re: Trying the Snek game again, small issue.

Post by albinopapa » March 16th, 2020, 3:37 pm

Lol, well I'm surprised that worked for you, because what I was actually pointing out was

for (int i = 0; i < segNo; i++)

probably should have been

for (int i = 0; i < segIndex; i++)

segNo is a constant 200 and you only want to iterate through the segments that are spawned.
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

SamCam
Posts: 20
Joined: January 8th, 2020, 3:24 pm

Re: Trying the Snek game again, small issue.

Post by SamCam » March 16th, 2020, 6:46 pm

Whoops, no, you were right. I was changing two things before testing. Bad form!

Post Reply