Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Ignore held key...help?

Author
Message
RobGoldstein
14
Years of Service
User Offline
Joined: 2nd Feb 2010
Location:
Posted: 2nd Feb 2010 22:32
Hello,

I'm writing a program in Visual C++ Express with Dark GDK. The game uses the arrow keys to control the speed of a ball that bounces around arkanoid-style. I have a problem, though. If I hold down an arrow key, the ball goes faster and faster and faster. Is there a way to ignore the fact that the key is held down and just increment my counter once, regardless of how long the key is held? Here's the bit of code that's giving me grief:



Thanks!
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 3rd Feb 2010 00:32
You can download my InputState class to easily do this:
http://forum.thegamecreators.com/?m=forum_view&t=164488&b=22



Your_Health = (My_Mood == HAPPY) ? 100 : NULL;
RobGoldstein
14
Years of Service
User Offline
Joined: 2nd Feb 2010
Location:
Posted: 3rd Feb 2010 01:47
Thanks, Bran, but this program is for a class, so it has to work when I send it to my professor. Any ideas?
Aldur
16
Years of Service
User Offline
Joined: 8th Oct 2007
Location: Melbourne, Australia
Posted: 3rd Feb 2010 04:20 Edited at: 3rd Feb 2010 04:21
Could you just limit it with an if statement?

For example:


I may not be understanding what you actually want to do though!

Cetobasilius
14
Years of Service
User Offline
Joined: 29th Dec 2009
Location: Mexico
Posted: 3rd Feb 2010 05:54 Edited at: 3rd Feb 2010 06:09
do this:



declare the Rightkeytimer as an int, "int Rightkeytimer;" before void DarkGDK ()
and do the same for the other variables... obiously with their respective names.

what this code does is that it checks to see if right is being pressed. if it is pressed, then check if the timer is 0, if so, add 1 to movex and 1 to the timer... so next time it tries to enter to add 1 to movex it wont since the timer is 1 then 2 then 3 and so on... and, the most important part is resetting the timer if the key is not being held, that is done in the else. if the key is not being press the timer is 0.



Hope it helps it will work


OR you could in fact, use Bran flakes91093 inputstate class which is very handy.

hi
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 3rd Feb 2010 14:28


there can be several points for the if statement that make the object appeir to slow down. I am assuming that you are tring to make a 3rd person object slow down on a slope this is also a problem I had. The problem lies when the player gets closer and closer to a slope. It will decress speed as the slope increases.

Go through yourself at a wall.
RobGoldstein
14
Years of Service
User Offline
Joined: 2nd Feb 2010
Location:
Posted: 3rd Feb 2010 19:54
Thanks for your advice, everyone. I asked my professor and he told me to just put an empty while loop inside of my if statement, like so:



Simple, elegant, functional.

Thanks again!
Cetobasilius
14
Years of Service
User Offline
Joined: 29th Dec 2009
Location: Mexico
Posted: 4th Feb 2010 04:21 Edited at: 4th Feb 2010 04:22
oh well i guess that will be usefull sometime

hi
Cetobasilius
14
Years of Service
User Offline
Joined: 29th Dec 2009
Location: Mexico
Posted: 8th Feb 2010 02:03 Edited at: 8th Feb 2010 02:04
lol i just made that and what this does it loops indefinetly... youd better use my example or another method, i think what your proffesor made you do is simple, it may look elegant, but it does not function at all with all given respect!

hi
Aldur
16
Years of Service
User Offline
Joined: 8th Oct 2007
Location: Melbourne, Australia
Posted: 8th Feb 2010 03:42
I didn't think it looked right, because the while-loop is being terminated right after it's called. Are you sure this is the correct snippet, Rob?

Amnzero
15
Years of Service
User Offline
Joined: 1st Aug 2009
Location:
Posted: 9th Feb 2010 07:53 Edited at: 9th Feb 2010 07:54
Change the ; after your while statement to { } like so:



Oh and I don't think the != 0 is really needed...

if(enemy == Amnzero) runAway();
Amnzero->WebSite = L"http://neovance.com/";

Login to post a reply

Server time is: 2024-10-01 23:32:53
Your offset time is: 2024-10-01 23:32:53