Help please? (SOLVED)
Help please? (SOLVED)
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.
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.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Help please?
Here's one issue,
I suppose return x - ( 2 * x ) is the same as return -x, but it confuses me
So here's a real issue
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
int Game::invert(int x)
{
return x - x - x;
}
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 );
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
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Help please?
Another issue
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.
Code: Select all
if (x >= gfx.ScreenWidth - width || x < 0 ||
y >= gfx.ScreenHeight - height || y < 0 )
{
return invert(pooSpeed);
}
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
Re: Help please?
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.
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.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Help please?
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
Re: Help please?
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 --
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 --
Re: Help please?
OK reuploaded the file.
@LuisR14 not sure what you mean bro, should I put clamping in ComposeFrame() or what?
@LuisR14 not sure what you mean bro, should I put clamping in ComposeFrame() or what?
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Help please?
Well, close
Do you see an issue here?
I actually already posted the correct way, look back up a few posts to compare the two.
Code: Select all
pooSpeed0 = invertDirection(pooX0, pooY1, pooW, pooH, pooSpeed0);
pooSpeed1 = invertDirection(pooX0, pooY1, pooW, pooH, pooSpeed1);
pooSpeed2 = invertDirection(pooX0, pooY1, pooW, pooH, pooSpeed2);
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
Re: Help please?
I feel stupid asf now... thank you, works fine.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Help please?
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