merged player's keydown and keyup code
authorRicardo Cruz <rick2@aeiou.pt>
Sat, 21 Feb 2004 15:08:59 +0000 (15:08 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Sat, 21 Feb 2004 15:08:59 +0000 (15:08 +0000)
SVN-Revision: 140

src/gameloop.c
src/player.c
src/player.h

index 581386f..4f83369 100644 (file)
@@ -134,7 +134,7 @@ void game_event(void)
           if(show_menu)
             menu_event(&event.key.keysym);
 
-          if(player_keydown_event(&tux,key))
+          if(player_key_event(&tux,key,DOWN))
             break;
 
           switch(key)
@@ -163,7 +163,7 @@ void game_event(void)
         case SDL_KEYUP:      /* A keyrelease! */
           key = event.key.keysym.sym;
 
-          if(player_keyup_event(&tux,key))
+          if(player_key_event(&tux,key,UP))
             break;
 
           switch(key)
index 6d42f49..759bb82 100644 (file)
@@ -71,62 +71,31 @@ void player_init(player_type* pplayer)
   timer_init(&pplayer->safe_timer);
 }
 
-int player_keydown_event(player_type* pplayer, SDLKey key)
+int player_key_event(player_type* pplayer, SDLKey key, int state)
 {
   if(key == pplayer->keymap.right)
     {
-      pplayer->input.right = DOWN;
+      pplayer->input.right = state;
       return YES;
     }
   else if( key == pplayer->keymap.left)
     {
-      pplayer->input.left = DOWN;
+      pplayer->input.left = state;
       return YES;
     }
   else if(key == pplayer->keymap.jump)
     {
-      pplayer->input.up = DOWN;
+      pplayer->input.up = state;
       return YES;
     }
   else if(key == pplayer->keymap.duck)
     {
-      pplayer->input.down = DOWN;
+      pplayer->input.down = state;
       return YES;
     }
   else if(key == pplayer->keymap.fire)
     {
-      pplayer->input.fire = DOWN;
-      return YES;
-    }
-  else
-    return NO;
-}
-
-int player_keyup_event(player_type* pplayer, SDLKey key)
-{
-  if(key == pplayer->keymap.right)
-    {
-      pplayer->input.right = UP;
-      return YES;
-    }
-  else if( key == pplayer->keymap.left)
-    {
-      pplayer->input.left = UP;
-      return YES;
-    }
-  else if(key == pplayer->keymap.jump)
-    {
-      pplayer->input.up = UP;
-      return YES;
-    }
-  else if(key == pplayer->keymap.duck)
-    {
-      pplayer->input.down = UP;
-      return YES;
-    }
-  else if(key == pplayer->keymap.fire)
-    {
-      pplayer->input.fire = UP;
+      pplayer->input.fire = state;
       return YES;
     }
   else
@@ -146,7 +115,7 @@ void player_level_begin(player_type* pplayer)
   pplayer->input.old_fire = UP;
   pplayer->input.right = UP;
   pplayer->input.up = UP;
-  
+
   timer_init(&pplayer->invincible_timer);
   timer_init(&pplayer->skidding_timer);
   timer_init(&pplayer->safe_timer);
index 27a9136..0f4528a 100644 (file)
@@ -84,8 +84,7 @@ extern texture_type tux_life,
  bigcape_right[2],  bigcape_left[2];
 
 void player_init(player_type* pplayer);
-int player_keydown_event(player_type* pplayer, SDLKey key);
-int player_keyup_event(player_type* pplayer, SDLKey key);
+int player_key_event(player_type* pplayer, SDLKey key, int state);
 void player_level_begin(player_type* pplayer);
 void player_action(player_type* pplayer);
 void player_input(player_type* pplayer);