Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Camus

Input/Speed problem...

This topic is 6240 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to write a tetris clone using DelphiX. I want my blocks (sprites) to move one square at a time when I press left or right on the keyboard EVEN IF THEY ARE HELD DOWN! How can I do this? Another thing...if the user holds down the down key I want the blocks to go down faster, but currently they are going way to fast. How can I control the speed of the blocks when the down key is held down? Thanx in advance. Regards, Bergsteinn Einarsson

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
quote:

I want my blocks (sprites) to move one square at a time when I press left or right on the keyboard EVEN IF THEY ARE HELD DOWN!



Let me see if I understand you. You want the pieces to move only one square to the left or right each time the respective movement key is pressed? And if the key is held down no further movement should take place. If you want to move again, you need to release and re-press the key again? If this is what you want you''ll need to track the OnKeyUp/OnKeyPress/OnKeyDown events of your TDXDraw object for the respective keys and just make sure the sprite only moves according to your preferences.

quote:

Another thing...if the user holds down the down key I want the blocks to go down faster, but currently they are going way to fast. How can I control the speed of the blocks when the down key is held down?



To throttle the speed you either need to put a pause in so only a certain amount of keytstrokes are processed, or simply use a timer check for instance:

  
procedure MoveDown();
const
ROD := 100; {Rate of decent 100ms)
ExitTime: LongInt := 0; {Static Variable}
var
EnterTime: LongInt;
begin
//Get Procedure Entry Time

EnterTime := LongInt(GetTickCount);
//Check

if (ExitTime < EnterTime) then begin
Sprite.Y := Sprite.Y + 16;
ExitTime := LongInt(GetTickCount) + ROD;
end;
end;


At least that''s my take on it, but there could be a better way. I just wrote this code now, so if it doesn''t work let me know. It should "throttle" the code so that if MoveDown is constantly called the Sprite.Y will only change every 100 milliseconds. That value may need to be higher, but at least it''s a starting point.

Anyone have a better way? I have yet to delv into DXInput so I''m not sure if there are any methods of modifying the rate at which input devices are polled. I''m sure there is a way though.

Share this post


Link to post
Share on other sites
Whoops... that was me. And just so you know those consts should be set like this:

  
const
ROD = 100; {Rate of decent 100ms)
ExitTime: LongInt = 0; {Static Variable}


not like this:

  
const
ROD := 100; {Rate of decent 100ms)
ExitTime: LongInt := 0; {Static Variable}


I always make that mistake. I''m so used to adding ":" to those equal signs... force of habit

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!