Files

156 lines
4.9 KiB
ObjectPascal

unit input;
interface
uses jinput;
const
T_UP = KeyQ;
T_DOWN = KeyA;
T_LEFT = KeyO;
T_RIGHT = KeyP;
T_OK = KeySPACE;
T_NOK = KeyM;
retard_tecla = 10; { per a controlar les pulsacions de tecles }
var
tecla : word; { per a controlar les pulsacions de tecles }
J_OK : boolean; { indica la disponibilitat del Gamepad }
procedure Check_Joystick;
{ Funcio: Coloca en la variable global J_OK si esta el gamepad conectat }
function i_amunt:boolean;
{ Funcio: mira si hem pulsat la tecla o el Gamepad }
function i_avall:boolean;
{ Funcio: mira si hem pulsat la tecla o el Gamepad }
function i_esquerra:boolean;
{ Funcio: mira si hem pulsat la tecla o el Gamepad }
function i_dreta:boolean;
{ Funcio: mira si hem pulsat la tecla o el Gamepad }
function i_ok:boolean;
{ Funcio: mira si hem pulsat la tecla o el Gamepad }
function i_nok:boolean;
{ Funcio: mira si hem pulsat la tecla o el Gamepad }
function i_esc:boolean;
{ Funcio: mira si hem pulsat ESC }
implementation
{############################################################################
##### C H E C K J O Y S T I C K #####
############################################################################}
procedure Check_Joystick;
{ Funcio: Coloca en la variable global J_OK si esta el gamepad conectat }
begin
if (joyavaliable(joystick1)) then J_OK := TRUE else J_OK := FALSE;
end;
{############################################################################
##### A M U N T #####
############################################################################}
function i_amunt:boolean;
{ Funcio: mira si hem pulsat la tecla o el Gamepad }
begin
i_amunt := FALSE;
if tecla=0 then
if ((J_OK) and (joystick(joystick1_Y)=joy1_MIN_Y))
or (TeclaPuls(T_UP)) then
begin
i_amunt := TRUE;
tecla := retard_tecla;
end;
end;
{############################################################################
##### A V A L L #####
############################################################################}
function i_avall:boolean;
{ Funcio: mira si hem pulsat la tecla o el Gamepad }
begin
i_avall := FALSE;
if tecla=0 then
if ((J_OK) and (joystick(joystick1_Y)=joy1_MAX_Y))
or (TeclaPuls(T_DOWN)) then
begin
i_avall := TRUE;
tecla := retard_tecla;
end;
end;
{############################################################################
##### D R E T A #####
############################################################################}
function i_dreta:boolean;
{ Funcio: mira si hem pulsat la tecla o el Gamepad }
begin
i_dreta := FALSE;
if tecla=0 then
if ((J_OK) and (joystick(joystick1_X)=joy1_MAX_X))
or (TeclaPuls(T_RIGHT)) then
begin
i_dreta := TRUE;
tecla := retard_tecla;
end;
end;
{############################################################################
##### E S Q U E R R A #####
############################################################################}
function i_esquerra:boolean;
{ Funcio: mira si hem pulsat la tecla o el Gamepad }
begin
i_esquerra := FALSE;
if tecla=0 then
if ((J_OK) and (joystick(joystick1_X)=joy1_MIN_X))
or (TeclaPuls(T_LEFT)) then
begin
i_esquerra := TRUE;
tecla := retard_tecla;
end;
end;
{############################################################################
##### B O T O O K #####
############################################################################}
function i_ok:boolean;
{ Funcio: mira si hem pulsat la tecla o el Gamepad }
begin
i_ok := FALSE;
if tecla=0 then
if ((J_OK) and (jbotons(button1_2)<>0))
or (TeclaPuls(T_OK)) then
begin
i_ok := TRUE;
tecla := retard_tecla+5;
end;
end;
{############################################################################
##### B O T O N O K #####
############################################################################}
function i_nok:boolean;
{ Funcio: mira si hem pulsat la tecla o el Gamepad }
begin
i_nok := FALSE;
if tecla=0 then
if ((J_OK) and (jbotons(button1_1)<>0))
or (TeclaPuls(T_NOK)) then
begin
i_nok := TRUE;
tecla := retard_tecla+5;
end;
end;
{############################################################################
##### B O T O E S C #####
############################################################################}
function i_esc:boolean;
{ Funcio: mira si hem pulsat el ESC }
begin
i_esc := FALSE;
if TeclaPuls(KeyESC) then
i_esc := TRUE;
end;
{############################################################################}
begin
Joy1_MAX_X := 144;
Joy1_MIN_X := 17;
Joy1_MAX_Y := 144;
Joy1_MIN_Y := 17;
end.