(20111228) 01:00
This commit is contained in:
44
Input.c
44
Input.c
@@ -25,7 +25,7 @@ int Input_Init(){
|
||||
for(i=0;i<InputKey_Max;i++){
|
||||
_keys[i]=InputKey_Released;
|
||||
}
|
||||
|
||||
/*
|
||||
// Check for joystick
|
||||
if(SDL_NumJoysticks()>0){
|
||||
// Open joystick
|
||||
@@ -44,7 +44,7 @@ int Input_Init(){
|
||||
if(SDL_JoystickOpened(0))
|
||||
SDL_JoystickClose(_joy);
|
||||
}
|
||||
|
||||
*/
|
||||
return(1);
|
||||
}
|
||||
|
||||
@@ -55,15 +55,45 @@ int Input_Init(){
|
||||
// Notify a frame update to the input subsystem.
|
||||
void Input_Frame(){
|
||||
Uint8* keys;
|
||||
Uint8 buttons;
|
||||
int mx,my;
|
||||
vec2 mdir;
|
||||
float temp;
|
||||
int mup,mdown,mleft,mright;
|
||||
extern int _width,_height;
|
||||
|
||||
|
||||
// Get mouse state
|
||||
buttons=SDL_GetMouseState(&mx,&my);
|
||||
vec2_set(mdir,mx-(_width/2),my-(_height/2.0f));
|
||||
temp=1.0f/sqrtf(vec2_dot(mdir,mdir));
|
||||
vec2_scale(mdir,mdir,temp);
|
||||
mup=mdown=mleft=mright=0;
|
||||
|
||||
// Virtual Dpad on screen using mouse position
|
||||
if(buttons){
|
||||
if(mdir[0]>0.5f){
|
||||
mright=1;
|
||||
}
|
||||
if(mdir[0]<-0.5f){
|
||||
mleft=1;
|
||||
}
|
||||
if(mdir[1]>0.5f){
|
||||
mdown=1;
|
||||
}
|
||||
if(mdir[1]<-0.5f){
|
||||
mup=1;
|
||||
}
|
||||
}
|
||||
|
||||
// Process Keys
|
||||
keys=SDL_GetKeyState(NULL);
|
||||
Input_SetKey(InputKey_Action1,keys[SDLK_z]);
|
||||
Input_SetKey(InputKey_Action1,keys[SDLK_z]|buttons);
|
||||
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_Up,keys[SDLK_UP]|mup);
|
||||
Input_SetKey(InputKey_Down,keys[SDLK_DOWN]|mdown);
|
||||
Input_SetKey(InputKey_Left,keys[SDLK_LEFT]|mleft);
|
||||
Input_SetKey(InputKey_Right,keys[SDLK_RIGHT]|mright);
|
||||
Input_SetKey(InputKey_Jump,keys[SDLK_SPACE]);
|
||||
Input_SetKey(InputKey_Continue,keys[SDLK_RETURN]|keys[SDLK_KP_ENTER]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user