Help please? (SOLVED)

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Henris
Posts: 4
Joined: April 14th, 2017, 5:01 pm

Help please? (SOLVED)

Post by Henris » April 14th, 2017, 5:16 pm

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.
Attachments
Game.cpp
Updated
(1.26 MiB) Downloaded 142 times
Game.h
(2.61 KiB) Downloaded 141 times
Last edited by Henris on April 17th, 2017, 7:01 pm, edited 2 times in total.

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

Re: Help please?

Post by albinopapa » April 15th, 2017, 6:29 am

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 );
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: Help please?

Post by albinopapa » April 15th, 2017, 6:38 am

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.
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

Henris
Posts: 4
Joined: April 14th, 2017, 5:01 pm

Re: Help please?

Post by Henris » April 16th, 2017, 5:42 pm

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.

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

Re: Help please?

Post by albinopapa » April 17th, 2017, 12:40 am

Upload your changes, won't be able to tell what still needs to be checked.
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

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Help please?

Post by LuisR14 » April 17th, 2017, 6:56 am

i'm thinking that you should clamp after updating
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

Henris
Posts: 4
Joined: April 14th, 2017, 5:01 pm

Re: Help please?

Post by Henris » April 17th, 2017, 1:33 pm

OK reuploaded the file.
@LuisR14 not sure what you mean bro, should I put clamping in ComposeFrame() or what? :)

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

Re: Help please?

Post by albinopapa » April 17th, 2017, 2:19 pm

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.
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

Henris
Posts: 4
Joined: April 14th, 2017, 5:01 pm

Re: Help please?

Post by Henris » April 17th, 2017, 3:46 pm

I feel stupid asf now... thank you, works fine.

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

Re: Help please?

Post by albinopapa » April 17th, 2017, 4:05 pm

No prob.
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