hi there, i've been trying to find something on limiting the users movement on my game.. i use directinput in which it detects keypress and moves character, but i have no idea how todo this and its really aggrivating me now...
[pascal]
procedure TFury.Render;
begin
if F_DXDevice = nil then exit;
// clear the backbuffer to black
F_DXDevice.Clear(0, nil, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0, 0);
// Rendering of scene objects can happen here
F_DXDevice.BeginScene;
begin
//get user input.
ProcessKBInput;
F_MapBuilder.DrawBricks;
end;
F_DXDevice.EndScene;
// Present the backbuffer contents to the display
F_DXDevice.Present(nil, nil, 0, nil);
end;
[/pascal]
the processkbinput is as follows:
[pascal]
procedure TFury.ProcessKBInput;
var
buffer: array[0..255] of byte;
hr: HResult;
begin
hr := F_DIDevice.GetDeviceState(SizeOf(buffer), @buffer);
if FAILED(hr) then begin
WriteLN('FAIL');
exit; //**** knows.... probably try to reaquire, todo...
end;
if (buffer[DIK_LEFT] and $80) <> 0 then //... need to move character smoothly not 1000mph...
F_MapBuilder.Player.PosX := F_MapBuilder.Player.PosX - 1
else if (buffer[DIK_RIGHT] and $80) <> 0 then
F_MapBuilder.Player.PosX := F_MapBuilder.Player.PosX + 1; //way to fast :/
end;
[/pascal]
so basically when i press left key, the character moves farrrrrrr too quick and vice versa with right, i considering only checking input after x amount of seconds, but then it will miss keypress...
any help would be greatly appreciated
*EDIT*
i slowed down the movement by using single for posx and y, however problem is that if the framerate increases or drops it also changes the movement rate
[pascal]
if (buffer[DIK_LEFT] and $80) <> 0 then //... need to move character smoothly not 1000mph...
F_MapBuilder.Player.PosX := F_MapBuilder.Player.PosX - 0.05
else if (buffer[DIK_RIGHT] and $80) <> 0 then
F_MapBuilder.Player.PosX := F_MapBuilder.Player.PosX + 0.05;
[/pascal]
-MM
Bookmarks