Avoiding typematic delays

Hi Guys. I decided to post this question in the c++ section after having tried the pascal section of the forum with little success.

I am making a video game in turbo pascal and would like to know why I am still getting typematic delays despite using a boolean array in order to detect key presses.

Here is a sample of my code:

var
keydelay:integer;
keys:array[1..4] of boolean;
k:char;
o:array[1..40] of integer;

procedure playermovement;
begin
if keydelay>0 then keydelay:=keydelay-1;
if keydelay=0 then
begin
for o[1]:=1 to 4 do
keys[o[1]]:=false;
end;
if keypressed=true then
begin
k:=readkey;
keydelay:=10;
if ord(k)=80 then keys[1]:=true;
if ord(k)=72 then keys[2]:=true;
if ord(k)=77 then keys[3]:=true;
if ord(k)=75 then keys[4]:=true;
end;
o[2]:=0;
for o[1]:=1 to 4 do
if keys[o[1]]=true then o[2]:=1;
if o[2]=1 then
begin
x:=a[1]*11; y:=a[2]*11;
setactivepage(1);
putimage(x,y,p[1]^,normalput);
setactivepage(0);
putimage(x,y,p[1]^,normalput);
freemem(p[1],size[1]);
if keys[1]=true then
begin
a[3]:=1;
if objm[a[1],a[2]+1]=0 then a[2]:=a[2]+1;
end;
if keys[2]=true then
begin
a[3]:=2;
if objm[a[1],a[2]-1]=0 then a[2]:=a[2]-1;
end;
if keys[3]=true then
begin
a[3]:=3;
if objm[a[1]+1,a[2]]=0 then a[1]:=a[1]+1;
end;
if keys[4]=true then
begin
a[3]:=4;
if objm[a[1]-1,a[2]]=0 then a[1]:=a[1]-1;
end;
setactivepage(1);
x:=a[1]*11; y:=a[2]*11;
size[1]:=imagesize(x,y,x+10,y+10);
getmem(p[1],size[1]);
getimage(x,y,x+10,y+10,p[1]^);
cplayer;
player;
size[2]:=imagesize(x,y,x+10,y+10);
getmem(p[2],size[2]);
getimage(x,y,x+10,y+10,p[2]^);
setactivepage(0);
putimage(x,y,p[2]^,normalput);
freemem(p[2],size[2]);
end;
end;

Could you please explain to me the logic involved in eliminating typematic delays when controlling player movement with keyboard keys.

I have been trying to solve this issue since 2004 but never had a programmer able to help me with this. I would really appreciate it. Thanks.
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!

Categories