flushing keyboard buffer for fluid arrow key movements

hi guys. i'm new to the forum. need some help with character movement in my game. now i'm quite experienced and been programming with turbo pascal since 2004. currently making a rpg game engine. been working on it for 3 months now (not my first attempt but my 4th). almost done. currently programming the battle system. however, the character movement has been bothering me ever since i started programming games. i can't get my character to move fluidly on screen. for example, pressing and holding the right arrow key makes the character move right once, then there is a slight pause and then the character keeps moving until i stop pressing the right arrow key. i would like to eliminate that pause/delay in character movement. i do understand that this happens because the keyboard buffer is not cleared/flushed. i am using booleans to remember which arrow keys are being pressed and setting the boolean to true when it is pressed. what i need to be able to do is to clear the keyboard buffer then scan for any key pressed with 'keypressed' then read the key that's pressed and set the corresponding boolean value to true or false, which then determines the horizontal or diagonal movements. if no key has been pressed i need to clear/flush the keyboard.

so the logic would be:

movement:array[1..4] of boolean;

clear/flush keyboard buffer {that's the part i need the code/commands for}
if keypressed=true then
if ord(k)=77 {right arrow key} then movement[1]:=true;
if movement[1]=true then x:=x+1;
until keypressed;

can anyone help me out with this? if you know of a better way to get the same result please let me know. thanks

sorry that this thread was posted twice but upon submitting the thread the screen kept loading and never showed me that the thread was posted. so i logged out and back in again and tried posting the same thread. that's why thread was posted twice.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!