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.

Newcomers DBPro Corner / Rapid pressing?

Author
Message
Camronas
14
Years of Service
User Offline
Joined: 2nd Jul 2010
Location:
Posted: 17th Sep 2010 01:41
Hey im making a turn based racing game "odd I know" I know how to do most of it or at least ahev a good idea. But during the players turn they have to hit a key rapidly, I know the IF RIGHTKEY()=1 but that wont work for what i need, any ideas?
Dia
19
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 17th Sep 2010 16:22
without knowing exactly what it is you need it is a bit hard to come up with ideas.

for example how quickly do the players have to hit the arrow key?

This is not the Sig you are looking for....
Camronas
14
Years of Service
User Offline
Joined: 2nd Jul 2010
Location:
Posted: 18th Sep 2010 01:12
Basicly the players each have 5 seconds to hit the key as many times as they can, not sure how much more detail I can give about the pressing.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 18th Sep 2010 05:01 Edited at: 18th Sep 2010 05:05
When they hit the key you can make a loop that'll wait till the user lets go of the key. That way the amount of actual hitting of the key is counted and not holding down the key (which is probably why you say you can't do it that way).

In this snip I used the spacebar:


Dia
19
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 19th Sep 2010 04:43
or you can try something like this to record your keypresses



This is not the Sig you are looking for....
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Sep 2010 09:12
Camronas, you must still be on post approval. I didn't see the 5 second bit when I posted.

Here's the same code with a 5 second timer:


Camronas
14
Years of Service
User Offline
Joined: 2nd Jul 2010
Location:
Posted: 21st Sep 2010 04:27
Oh my God this is amazing! Thank you very much, I was happy with just the first code you gave me but this is great, thank you so much. You are a god sent!
Camronas
14
Years of Service
User Offline
Joined: 2nd Jul 2010
Location:
Posted: 21st Sep 2010 04:49
Hey just found somthing interesting in the code, if I hold space the timer doesnt move, and when I let go it jumps to the remaining time
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 21st Sep 2010 06:52 Edited at: 21st Sep 2010 06:56
Np. It's because of this:



It stays in the REPEAT/UNTIL loop till you let go of the spacebar.

I have another version that you'll like better. It eliminates that bit of code in the above snip. It's a couple of commands I just noticed in the help files. I don't know when they were added to Darkbasic Pro but it's a nice set of commands that allow us to make any key a toggle switch. It'll do the same thing as a switch in code without the need to create a switch (a switch in programming is either Off (0) or On (1)). To find out all the virtual keys just click on GET KEY STATE() and hit F1 to bring up the help file for that command. In the example code in that help file you'll see all the hex codes for each virtual key.

In this code holding down the spacebar doesn't stop the action:


To further explain it checks if the spacebar is being hit with GET KEY STATE(0x20)=1 then it increases the counter and resets the spacebar toggle to zero with SET KEY STATE TOGGLE 0x20,0. Without resetting it to zero the spacebar would have to be hit twice to return the toggle to zero (and in that code if SET KEY STATE TOGGLE was remed off it would increase the counter till the spacebar is hit again). I can see many uses for those commands.

Camronas
14
Years of Service
User Offline
Joined: 2nd Jul 2010
Location:
Posted: 21st Sep 2010 09:06
Ahh very nice, works very well. Now im just trying to break it down into functions so I can make players take turns. So far not much luck but gunna keep working on it, cant get better if I dont try
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 23rd Sep 2010 07:40 Edited at: 23rd Sep 2010 07:44
i was tinkering with an example here a couple days ago (and got a little carried away):


included with the belief that you may want to do "other things" while you're mashing the space bar vs just counting key-presses, etc.

hope that helps

Virtual Nomad @ California, USA . DBPro V7.5
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit
Camronas
14
Years of Service
User Offline
Joined: 2nd Jul 2010
Location:
Posted: 29th Sep 2010 00:26
Very nice Virtual Nomad, I really like the set up with the timer and stuff. Only issue is I can hold the key down, but ill think of somthing cheers
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 30th Sep 2010 00:32
hmm? sure you can hold the key down but it won't "count" unless it was released first. you're not mistaking the first line (where the elapsed variable is being displayed and is just a visible timer) with the total Count or number of keypresses, right? that's line 3 labeled "Count" which doesn't increase unless the spacebar was released before pressing it (again and again). otherwise, i'm a little confused now as to what you're trying to accomplish. :/

Virtual Nomad @ California, USA . DBPro V7.5
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit

Login to post a reply

Server time is: 2024-11-23 07:23:25
Your offset time is: 2024-11-23 07:23:25