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 / Slippy Keyboard controls

Author
Message
Dizzy
20
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Brit in the US
Posted: 26th Sep 2003 07:24
So I just bought Dark Basic a couple of weeks ago and decided to get back into programming with a simple project, good old Tetris.

Well, I'm pretty darned pleased with myself - I coded it in just a few hours and it's already playable. The problem is that it's too fast - not so much the speed of the blocks, but the speed the keyboard is read.

Is there a simple command I can use to fix this without slowing down the sync rate?

I have included my main game loop code.

Cheers!

===
"Life would be so simple if only we had the source code!" - someone else
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Sep 2003 11:59
You could force the program to detect individual keypresses by ignoring DOWNKEY() = 1 until you have detected a DOWNKEY()=0. Does that make sense - you have to let go of the key before it will accept the next keypress.

Or...You could create a timestamp field of the last time you processed the down key, and not process it again for the next 250 ms or so.

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
MagiKnight
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location:
Posted: 26th Sep 2003 13:14
You could always put a "Wait 100" in your control routines but thats nasty cause it still slows everything down after upkey() or what ever key your holding down.

MMMMMM Low level programmimg...
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 26th Sep 2003 21:07
Quote: "Or...You could create a timestamp field of the last time you processed the down key, and not process it again for the next 250 ms or so.
"


this is the best way to go imho. you won't stop your loop from running as fast as it can.

-RUST-
Dizzy
20
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Brit in the US
Posted: 26th Sep 2003 21:22
It's not the down key I have a problem with, it's the rotate key. But your answers are still relevant.

The spacekey()=0 seems like the simple solution, I might have to play the original Tetris to see if it allowed multiple rotations with one button press.

The Timestamp solution seems a little cumbersome, but I might try to implement a function as it could be useful for future projects. My concern with this is that the game my seem unresponsive if someone hits the spacebar twice in quick succession.

Thanks for the suggestions!

===
"Life would be so simple if only we had the source code!" - someone else
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Sep 2003 23:54 Edited at: 26th Sep 2003 23:55
I do the individual click thing with the mouse button, it's not cumbersome honest! The following code is just like a toggle switch

gMousePressed is a global



BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
Dizzy
20
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Brit in the US
Posted: 27th Sep 2003 00:19
Thanks for the example, I agree with you that this looks like a simple solution. It's the timestamp that I think would be a little tricker.

But then I guess you would just have to set a variable to equal timer(), on each click you would then check the current value of timer() against the varibale and if the difference is less than 250ms you would ignore the command. If it is greater then 250ms carry out the command and update the variable to the new timer() value.

I don't know why I tried to write that in English, psuedocode would probably have been much clearer - oh well!

===
"Life would be so simple if only we had the source code!" - someone else
Xander
21
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 27th Sep 2003 07:58
I always use the timestamp method. It allows you to still hold down the key and make it do actions multiple times when holding down the key (or mouse button). It is really easy:

if upkey()=1 then timer()-keytime>250
keytime=timer()
(do whatever)
endif

Xander - Bolt Software

It doesn't matter if it is confusing, as long as it works
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Sep 2003 13:33
if upkey()=1 and timer()-keytime>250

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
Symon
21
Years of Service
User Offline
Joined: 29th Aug 2003
Location:
Posted: 29th Sep 2003 03:08
cheers been looking for this sort of code for ages just like the pic object command thanks again heres how it should look

250 is the delay time
if you want the time to be shorter then make the number smaller

Login to post a reply

Server time is: 2024-09-21 01:02:48
Your offset time is: 2024-09-21 01:02:48