Page 1 of 1

Help please? (SOLVED)

Posted: April 14th, 2017, 5:16 pm
by Henris
Hello, so I`m stuck on homework 8.
So what I came up with was:
Each poo has a speed variable which is 1 or -1.
I subtract that speed variable to each poo X and Y so it moves diagonally.
Then I check if poo has reached the wall and invert the speed variable.
I get an error if poo hits top or the bottom, but if it hits side wall it does work, the only problem is that all poos suddenly invert instead of 1 of them.
I have debugged this and found out that all 3 poo speed becomes same when I check for collision with player, which is weird, collision check is right after poo movement.
I have tried commenting collision check out then program crashes completely.

If you could please have a quick look into my code, to see if you know what the problem is.
Thank you.

Re: Help please?

Posted: April 15th, 2017, 6:29 am
by albinopapa
Here's one issue,

Code: Select all

int Game::invert(int x)
{
	return x - x - x;
}
I suppose return x - ( 2 * x ) is the same as return -x, but it confuses me :)

So here's a real issue

Code: Select all

		pooSpeed0 = invertDirection( pooX0, pooX1, pooW, pooH, pooSpeed0 );
		pooSpeed1 = invertDirection( pooX0, pooX1, pooW, pooH, pooSpeed1 );
		pooSpeed2 = invertDirection( pooX0, pooX1, pooW, pooH, pooSpeed2 );
You pass pooX0 and pooX1 when the parameter list for the invertDirection function wants an X and a Y.
And they're all the same pooX0 and pooX1,
Shouldn't it be

Code: Select all

		pooSpeed0 = invertDirection( pooX0, pooY0, pooW, pooH, pooSpeed0 );
		pooSpeed1 = invertDirection( pooX1, pooY1, pooW, pooH, pooSpeed1 );
		pooSpeed2 = invertDirection( pooX2, pooY2, pooW, pooH, pooSpeed2 );

Re: Help please?

Posted: April 15th, 2017, 6:38 am
by albinopapa
Another issue

Code: Select all

	if (x >= gfx.ScreenWidth - width || x < 0 ||
		y >= gfx.ScreenHeight - height || y < 0  )
	{
		return invert(pooSpeed);
	}
What do you thing the function will return if the statement isn't true? You don't have an else condition, so the compiler makes up a value for you. So if the condition is true, the function returns invert(pooSpeed); otherwise the compiler makes one up.

Re: Help please?

Posted: April 16th, 2017, 5:42 pm
by Henris
Cheers bro, I`m such a dickhead how did I miss that Y lol. -_- Fixed all these though, but it still doesn't work. I mean sometimes it does, if a poo touches lets say - bottom of the screen it either inverts direction or sometimes throws up an error, I think it depends on whether its poo1, poo2 or poo3, also I just tried it again and I had 2 poos that hits the sidewall, one of them wraps around while the other one inverts direction. The other problem is, on start they going in different directions, but whenever first poo touches the wall it inverts all the poos, and makes them go the same direction.

If you got any ideas please share. Otherwise ill just continue watching the next video and do it how Chilli done it, but leave this without sorting it out would feel shit. -_- :D anyway I cant get my head around it it feels like I`ve checked everybit now and it looks allright to me, so yh please check out the code if u got spare time. Thanks.

Re: Help please?

Posted: April 17th, 2017, 12:40 am
by albinopapa
Upload your changes, won't be able to tell what still needs to be checked.

Re: Help please?

Posted: April 17th, 2017, 6:56 am
by LuisR14
i'm thinking that you should clamp after updating

Re: Help please?

Posted: April 17th, 2017, 1:33 pm
by Henris
OK reuploaded the file.
@LuisR14 not sure what you mean bro, should I put clamping in ComposeFrame() or what? :)

Re: Help please?

Posted: April 17th, 2017, 2:19 pm
by albinopapa
Well, close

Code: Select all

		pooSpeed0 = invertDirection(pooX0, pooY1, pooW, pooH, pooSpeed0);
		pooSpeed1 = invertDirection(pooX0, pooY1, pooW, pooH, pooSpeed1);
		pooSpeed2 = invertDirection(pooX0, pooY1, pooW, pooH, pooSpeed2);
Do you see an issue here?

I actually already posted the correct way, look back up a few posts to compare the two.

Re: Help please?

Posted: April 17th, 2017, 3:46 pm
by Henris
I feel stupid asf now... thank you, works fine.

Re: Help please?

Posted: April 17th, 2017, 4:05 pm
by albinopapa
No prob.