unit l_input;
(*************************************)
(* Input module by XProger           *)
(*************************************)
(* site : http://XProger.mirgames.ru *)
(* mail : XProger@list.ru            *)
(*************************************)
interface

uses
 Windows, l_math;

var
 Key : array [0..255] of boolean;

 function KeyDown(Btn: Byte): boolean;
 procedure ResetKeys;
 procedure KeyOnDown(ID: Byte);
 procedure KeyOnUp(ID: Byte);
 procedure Input_Update;

var
 MDelta : TPoint;

implementation

uses
 l_game, l_map, l_menu, l_gl, l_sound, l_camera;
 
function KeyDown(Btn: Byte): boolean;
begin
Result := Key[Btn];
end;

procedure ResetKeys;
begin
ZeroMemory(@Key, 256);
MDelta.X := 0;
MDelta.Y := 0;
end;

procedure KeyOnDown(ID: Byte);
begin
Key[ID] := true;
end;

procedure KeyOnUp(ID: Byte);
begin
Key[ID] := false;
 case ID of
  VK_ESCAPE : if not inMenu then
               begin
               snd_StopAll(0);
               Player.ResetKeys;
               if Player.Health = 0 then
                Menu_Load;
               inMenu := true;
               end;
  // не девелопер ты, и не видеть тебе дебага!
{ VK_F1 : debug   := not debug;
  VK_F2 : detail  := not detail;
  VK_F3 : vsync   := not vsync;
  VK_F4 : culling := not culling; }
 end;
end;

procedure Input_Update;
var
 p : TPoint;
begin
GetCursorPos(p);
MDelta.X := p.X - glWidth div 2;
MDelta.Y := p.Y - glHeight div 2;
SetCursorPos(glWidth div 2, glHeight div 2);
end;


end.
