From 716a056398189ee131bf1179056c2a1ea71d432c Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Thu, 7 Oct 2004 17:50:21 +0000 Subject: [PATCH] Sometime ago I asked what keys ppl would prefer, made the changes now to reflect that. Please, test this on a joystick. TODO: add Up and Down level viewing. SVN-Revision: 1988 --- src/gameloop.cpp | 26 +++++++++++++------- src/misc.cpp | 24 +++++++++---------- src/player.cpp | 72 +++++++++++++++++++++++++++++++------------------------- src/player.h | 9 +++---- 4 files changed, 74 insertions(+), 57 deletions(-) diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 4d3c79259..6fa78367c 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -248,11 +248,12 @@ GameSession::on_escape_press() it could have nasty bugs, like going allways to the right or whatever that key does */ Player& tux = *(currentsector->player); - tux.key_event((SDLKey)keymap.jump, UP); - tux.key_event((SDLKey)keymap.duck, UP); + tux.key_event((SDLKey)keymap.up, UP); + tux.key_event((SDLKey)keymap.down, UP); tux.key_event((SDLKey)keymap.left, UP); tux.key_event((SDLKey)keymap.right, UP); - tux.key_event((SDLKey)keymap.fire, UP); + tux.key_event((SDLKey)keymap.jump, UP); + tux.key_event((SDLKey)keymap.power, UP); Menu::set_current(game_menu); Ticks::pause_start(); @@ -500,11 +501,20 @@ GameSession::process_events() else if (event.jaxis.axis == joystick_keymap.y_axis) { if (event.jaxis.value > joystick_keymap.dead_zone) - tux.input.down = DOWN; - else if (event.jaxis.value < -joystick_keymap.dead_zone) + { + tux.input.up = DOWN; tux.input.down = UP; + } + else if (event.jaxis.value < -joystick_keymap.dead_zone) + { + tux.input.up = UP; + tux.input.down = DOWN; + } else - tux.input.down = UP; + { + tux.input.up = DOWN; + tux.input.down = DOWN; + } } break; @@ -531,7 +541,7 @@ GameSession::process_events() case SDL_JOYBUTTONDOWN: if (event.jbutton.button == joystick_keymap.a_button) - tux.input.up = DOWN; + tux.input.jump = DOWN; else if (event.jbutton.button == joystick_keymap.b_button) tux.input.fire = DOWN; else if (event.jbutton.button == joystick_keymap.start_button) @@ -539,7 +549,7 @@ GameSession::process_events() break; case SDL_JOYBUTTONUP: if (event.jbutton.button == joystick_keymap.a_button) - tux.input.up = UP; + tux.input.jump = UP; else if (event.jbutton.button == joystick_keymap.b_button) tux.input.fire = UP; break; diff --git a/src/misc.cpp b/src/misc.cpp index 7873929f2..ce553ede9 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -19,22 +19,21 @@ void MyConfig::customload(LispReader& reader) { - reader.read_int ("keyboard-jump", keymap.jump); - reader.read_int ("keyboard-activate", keymap.activate); - reader.read_int ("keyboard-duck", keymap.duck); + reader.read_int ("keyboard-up", keymap.up); + reader.read_int ("keyboard-down", keymap.down); reader.read_int ("keyboard-left", keymap.left); reader.read_int ("keyboard-right", keymap.right); - reader.read_int ("keyboard-fire", keymap.fire); + reader.read_int ("keyboard-jump", keymap.jump); + reader.read_int ("keyboard-power", keymap.power); } void MyConfig::customsave(FILE * config) { - fprintf(config, "\t(keyboard-jump %d)\n", keymap.jump); - fprintf(config, "\t(keyboard-duck %d)\n", keymap.duck); + fprintf(config, "\t(keyboard-up %d)\n", keymap.up); + fprintf(config, "\t(keyboard-down %d)\n", keymap.down); fprintf(config, "\t(keyboard-left %d)\n", keymap.left); fprintf(config, "\t(keyboard-right %d)\n", keymap.right); - fprintf(config, "\t(keyboard-fire %d)\n", keymap.fire); - fprintf(config, "\t(keyboard-activate %d)\n", keymap.activate); - + fprintf(config, "\t(keyboard-jump %d)\n", keymap.jump); + fprintf(config, "\t(keyboard-power %d)\n", keymap.power); } void process_options_menu(void) @@ -129,11 +128,10 @@ void st_menu(void) options_keys_menu->additem(MN_HL,"",0,0); options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Left move"), 0,0, 0,&keymap.left); options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Right move"), 0,0, 0,&keymap.right); + options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Up/Activate"), 0,0, 0,&keymap.up); + options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Down/Duck"), 0,0, 0,&keymap.down); options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Jump"), 0,0, 0,&keymap.jump); - options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Duck"), 0,0, 0,&keymap.duck); - options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Activate"), 0, 0, 0, - &keymap.activate); - options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Power/Run"), 0,0, 0,&keymap.fire); + options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Power/Run"), 0,0, 0,&keymap.power); options_keys_menu->additem(MN_HL,"",0,0); options_keys_menu->additem(MN_BACK,_("Back"),0,0); diff --git a/src/player.cpp b/src/player.cpp index 666616b2a..ecea4f999 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -67,23 +67,25 @@ PlayerKeymap keymap; PlayerKeymap::PlayerKeymap() { - keymap.jump = SDLK_SPACE; - keymap.activate = SDLK_UP; - keymap.duck = SDLK_DOWN; + keymap.up = SDLK_UP; + keymap.down = SDLK_DOWN; keymap.left = SDLK_LEFT; keymap.right = SDLK_RIGHT; - keymap.fire = SDLK_LCTRL; + + keymap.power = SDLK_LCTRL; + keymap.jump = SDLK_LALT; } void player_input_init(player_input_type* pplayer_input) { + pplayer_input->up = UP; pplayer_input->down = UP; pplayer_input->fire = UP; pplayer_input->left = UP; pplayer_input->old_fire = UP; pplayer_input->right = UP; - pplayer_input->up = UP; - pplayer_input->old_up = UP; + pplayer_input->jump = UP; + pplayer_input->old_jump = UP; pplayer_input->activate = UP; } @@ -199,38 +201,44 @@ Player::key_event(SDLKey key, int state) input.left = state; return true; } - else if(key == keymap.jump) + else if(key == keymap.up) { input.up = state; + + /* Up key also opens activates stuff */ + input.activate = state; + + if(state == DOWN) { + /** check for interactive objects */ + for(Sector::InteractiveObjects::iterator i + = Sector::current()->interactive_objects.begin(); + i != Sector::current()->interactive_objects.end(); ++i) { + if(rectcollision(base, (*i)->get_area())) { + (*i)->interaction(INTERACTION_ACTIVATE); + } + } + } + return true; } - else if(key == keymap.duck) + else if(key == keymap.down) { input.down = state; return true; } - else if(key == keymap.fire) + else if(key == keymap.power) { if (state == UP) input.old_fire = UP; input.fire = state; + return true; } - else if(key == keymap.activate) + else if(key == keymap.jump) { - input.activate = state; - - if(state == DOWN) { - /** check for interactive objects */ - for(Sector::InteractiveObjects::iterator i - = Sector::current()->interactive_objects.begin(); - i != Sector::current()->interactive_objects.end(); ++i) { - if(rectcollision(base, (*i)->get_area())) { - (*i)->interaction(INTERACTION_ACTIVATE); - } - } - } - + if (state == UP) + input.old_jump = UP; + input.jump = state; return true; } else @@ -533,7 +541,7 @@ Player::handle_vertical_input() } // Press jump key - if(input.up == DOWN && can_jump && on_ground()) + if(input.jump == DOWN && can_jump && on_ground()) { if(duck) { // only jump a little bit when in duck mode { physic.set_velocity_y(3); @@ -556,7 +564,7 @@ Player::handle_vertical_input() SoundManager::get()->play_sound(IDToSound(SND_BIGJUMP)); } // Let go of jump key - else if(input.up == UP) + else if(input.jump == UP) { if (!flapping && !duck && !falling_from_flap && !on_ground()) { @@ -570,7 +578,7 @@ Player::handle_vertical_input() } // Flapping - if (input.up == DOWN && can_flap) + if (input.jump == DOWN && can_flap) { if (!flapping_timer.started()) { @@ -606,7 +614,7 @@ Player::handle_vertical_input() // Hover //(disabled by default, use cheat code "hover" to toggle on/off) //TODO: needs some tweaking, especially when used together with double jump and jumping off badguys - if (enable_hover && input.up == DOWN && !jumping && !butt_jump && physic.get_velocity_y() <= 0) + if (enable_hover && input.jump == DOWN && !jumping && !butt_jump && physic.get_velocity_y() <= 0) { physic.set_velocity_y(-1); } @@ -670,8 +678,8 @@ Player::handle_vertical_input() issolid(base.x + base.width - 1, base.y + base.height + 64)) && jumping == false && can_jump == false - && input.up == DOWN - && input.old_up == UP) + && input.jump == DOWN + && input.old_jump == UP) { can_jump = true; } @@ -686,7 +694,7 @@ Player::handle_vertical_input() physic.set_acceleration_y(0); //for flapping } - input.old_up = input.up; + input.old_jump = input.jump; } void @@ -697,7 +705,7 @@ Player::handle_input() /* Jump/jumping? */ - if (on_ground() && input.up == UP) + if (on_ground() && input.jump == UP) can_jump = true; handle_vertical_input(); @@ -1205,7 +1213,7 @@ Player::bounce(BadGuy* badguy) Sector::current()->add_floating_text(base, str); } - if (input.up) + if (input.jump) physic.set_velocity_y(5.2); else physic.set_velocity_y(2); diff --git a/src/player.h b/src/player.h index d2b7e0712..b76022b9c 100644 --- a/src/player.h +++ b/src/player.h @@ -63,11 +63,11 @@ struct PlayerKeymap { public: int jump; - int activate; - int duck; + int up; + int down; int left; int right; - int fire; + int power; PlayerKeymap(); }; @@ -79,11 +79,12 @@ struct player_input_type int right; int left; int up; - int old_up; int down; int fire; int old_fire; int activate; + int jump; + int old_jump; }; void player_input_init(player_input_type* pplayer_input); -- 2.11.0