Please, test this on a joystick.
TODO: add Up and Down level viewing.
SVN-Revision: 1988
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();
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;
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)
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;
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)
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);
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;
}
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
}
// 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);
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())
{
}
// Flapping
- if (input.up == DOWN && can_flap)
+ if (input.jump == DOWN && can_flap)
{
if (!flapping_timer.started())
{
// 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);
}
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;
}
physic.set_acceleration_y(0); //for flapping
}
- input.old_up = input.up;
+ input.old_jump = input.jump;
}
void
/* Jump/jumping? */
- if (on_ground() && input.up == UP)
+ if (on_ground() && input.jump == UP)
can_jump = true;
handle_vertical_input();
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);
{
public:
int jump;
- int activate;
- int duck;
+ int up;
+ int down;
int left;
int right;
- int fire;
+ int power;
PlayerKeymap();
};
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);