From e74a7240155e6e2e8948092daefb89383be02ede Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Sat, 21 Feb 2004 15:08:59 +0000 Subject: [PATCH] merged player's keydown and keyup code SVN-Revision: 140 --- src/gameloop.c | 4 ++-- src/player.c | 45 +++++++-------------------------------------- src/player.h | 3 +-- 3 files changed, 10 insertions(+), 42 deletions(-) diff --git a/src/gameloop.c b/src/gameloop.c index 581386fbd..4f83369e7 100644 --- a/src/gameloop.c +++ b/src/gameloop.c @@ -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) diff --git a/src/player.c b/src/player.c index 6d42f499c..759bb82d3 100644 --- a/src/player.c +++ b/src/player.c @@ -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); diff --git a/src/player.h b/src/player.h index 27a91366c..0f4528a67 100644 --- a/src/player.h +++ b/src/player.h @@ -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); -- 2.11.0