Quantcast
Channel: Programmers Heaven Forums RSS Feed
Viewing all articles
Browse latest Browse all 2703

Key movements in turbo pascal

$
0
0
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:

var
movement:array[1..4] of boolean;
k:char;

repeat
clear/flush keyboard buffer {that's the part i need the code/commands for}
if keypressed=true then
begin
k:=readkey;
if ord(k)=77 {right arrow key} then movement[1]:=true;
end;
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

Viewing all articles
Browse latest Browse all 2703

Trending Articles