(20111213)
This commit is contained in:
68
Input.c
Normal file
68
Input.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
#include "Input.h"
|
||||
|
||||
|
||||
// Globals
|
||||
InputKeyStatus _keys[InputKey_Max];
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_Init
|
||||
//
|
||||
// Initializes the game input.
|
||||
int Input_Init(){
|
||||
int i;
|
||||
|
||||
// Mark released all the keys
|
||||
for(i=0;i<InputKey_Max;i++){
|
||||
_keys[i]=InputKey_Released;
|
||||
}
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_Frame
|
||||
//
|
||||
// Notify a frame update to the input subsystem.
|
||||
void Input_Frame(){
|
||||
Uint8* keys;
|
||||
|
||||
// Process Keys
|
||||
keys=SDL_GetKeyState(NULL);
|
||||
Input_SetKey(InputKey_Action1,keys[SDLK_z]);
|
||||
Input_SetKey(InputKey_Action2,keys[SDLK_x]);
|
||||
Input_SetKey(InputKey_Up,keys[SDLK_UP]);
|
||||
Input_SetKey(InputKey_Down,keys[SDLK_DOWN]);
|
||||
Input_SetKey(InputKey_Left,keys[SDLK_LEFT]);
|
||||
Input_SetKey(InputKey_Right,keys[SDLK_RIGHT]);
|
||||
Input_SetKey(InputKey_Jump,keys[SDLK_SPACE]);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_SetKey
|
||||
//
|
||||
// Notify a key press to the input subsystem.
|
||||
void Input_SetKey(InputKey key,int status){
|
||||
if(!status){
|
||||
_keys[key]=InputKey_Released;
|
||||
}else{
|
||||
if(_keys[key]>=InputKey_Pressed){
|
||||
_keys[key]=InputKey_Holded;
|
||||
}else{
|
||||
_keys[key]=InputKey_Pressed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_GetKey
|
||||
//
|
||||
// Reports a the status of a key.
|
||||
InputKeyStatus Input_GetKey(InputKey key){
|
||||
return(_keys[key]);
|
||||
}
|
||||
Reference in New Issue
Block a user