Page 1 of 1 [ 10 posts ]

 Print view Previous topic | Next topic

Author Message
 Post subject: Help please? (SOLVED)  Posted: April 14th, 2017, 5:16 pm

Joined: April 14th, 2017, 5:01 pm
Posts: 4
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.

Last edited by Henris on April 17th, 2017, 7:01 pm, edited 2 times in total.

 Post subject: Re: Help please?  Posted: April 15th, 2017, 6:29 am

Joined: February 28th, 2013, 3:23 am
Posts: 2669
Location: Oklahoma, United States
Here's one issue,
Code:
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:
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:
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

 Post subject: Re: Help please?  Posted: April 15th, 2017, 6:38 am

Joined: February 28th, 2013, 3:23 am
Posts: 2669
Location: Oklahoma, United States
Another issue
Code:
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

 Post subject: Re: Help please?  Posted: April 16th, 2017, 5:42 pm

Joined: April 14th, 2017, 5:01 pm
Posts: 4
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. -_- 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.

 Post subject: Re: Help please?  Posted: April 17th, 2017, 12:40 am

Joined: February 28th, 2013, 3:23 am
Posts: 2669
Location: Oklahoma, United States
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

 Post subject: Re: Help please?  Posted: April 17th, 2017, 6:56 am

Joined: May 23rd, 2013, 3:52 pm
Posts: 1232
Location: USA
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.
irc://irc.freenode.net/#pchili alt -- join up if ever want real-time help or to just chat --

 Post subject: Re: Help please?  Posted: April 17th, 2017, 1:33 pm

Joined: April 14th, 2017, 5:01 pm
Posts: 4
@LuisR14 not sure what you mean bro, should I put clamping in ComposeFrame() or what?

 Post subject: Re: Help please?  Posted: April 17th, 2017, 2:19 pm

Joined: February 28th, 2013, 3:23 am
Posts: 2669
Location: Oklahoma, United States
Well, close
Code:
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

 Post subject: Re: Help please?  Posted: April 17th, 2017, 3:46 pm

Joined: April 14th, 2017, 5:01 pm
Posts: 4
I feel stupid asf now... thank you, works fine.

 Post subject: Re: Help please?  Posted: April 17th, 2017, 4:05 pm

Joined: February 28th, 2013, 3:23 am
Posts: 2669
Location: Oklahoma, United States
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

Display posts from previous:  Sort by

 Page 1 of 1 [ 10 posts ]

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

 Search for: