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.

Author
Message
Aarbear
15
Years of Service
User Offline
Joined: 29th Apr 2011
Location: New York
Posted: 22nd May 2011 02:20
Hi, I can't find any solutions to my question. I'm writing a 2d game, and I'm trying to get my character to have his speed increase every time a key is pressed (like the Joust in the atari game, if you'll remember). I'm not just talking about if leftkey() = 1 then dec playerX
It would be like... if leftkey() = waspressed then dec playerX
and the player would keep moving left even after the key was unpressed. However, if the key was pressed again, his speed would increase (or decrease ) another 1.
I own a copy of darkBasic pro game programming second edition for a class I'm taking, and I don't see a built in keypressed function anywhere.
I keep trying to build the code in my head, but I can't seem to figure out the logic for this one. :/
Any help is greatly appreciated.

Thanks for reading,
~Aaron

Str8^
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 22nd May 2011 03:10
the solution for your problem is very simple.
many solutions can arise,I will give you one of them:

do
game arguments

if leftkey()
inc leftspeed#,1
while leftkey()
moveleft(leftspeed#) // user defined function to move
your sprite left
game argument
endwhile
endif
loop
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 22nd May 2011 03:11
he solution for your problem is very simple.
many solutions can arise,I will give you one of them:

[do
game arguments

if leftkey()
inc leftspeed#,1
while leftkey()
moveleft(leftspeed#) // user defined function to move
your sprite left
game argument
endwhile
endif
loop ]
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 22nd May 2011 05:27 Edited at: 22nd May 2011 05:28
You separate the checking of the keys from the actual movement and use a variables for the current direction.

Instead of:


Use:


I'll let you try some more on increasing the speed aspect yourself.

Aarbear
15
Years of Service
User Offline
Joined: 29th Apr 2011
Location: New York
Posted: 22nd May 2011 07:01
Oh alright, thanks guys.

Str8^
Jimmy
22
Years of Service
User Offline
Joined: 20th Aug 2003
Location: Back in the USA
Posted: 22nd May 2011 09:40
This is how I do a quick key pressed check




May 10th / Jerico2day-OBese87 / VOTE NOW

Login to post a reply

Server time is: 2026-07-10 18:02:10
Your offset time is: 2026-07-10 18:02:10