delphi - Delphi7, make a shape jump when pressing Up key -


i'd make shape jump when player presses key, best think of this, method used terrible , problematic:

(shape coordinates: shape1.top:=432;)

procedure tform1.formkeydown(sender: tobject; var key: word;   shift: tshiftstate); begin case key of vk_up: shape1.top:=shape1.top-40   //so jumps 392 end;  end; 

and timer:

procedure tform1.timer1timer(sender: tobject); begin timer1.interval:=300 if shape1.top<400      //if shape1.top=392 < 400 begin shape1.top:=432;            //move 432 end;  end; 

the problem players can press key up, don't want. know method terrible, hope have better , grateful if share me.

if player can hold down key , keydown fires repeatedly, can lock it.

first, declare field on form called fkeylock: set of byte. (note: technique fail if key values higher 255, ones you're deal won't high.)

procedure tform1.formkeydown(sender: tobject; var key: word;   shift: tshiftstate); begin   if key in fkeylock     exit;   case key of     vk_up:     begin       shape1.top:=shape1.top-40;   //so jumps 392       include(fkeylock, vk_up);     end;   end; end;  procedure tform1.formkeyup(sender: tobject; var key: word;   shift: tshiftstate); begin    exclude(fkeylock, key); end; 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -