break;
case SDL_JOYAXISMOTION:
- if (event.jaxis.axis == JOY_X)
+ if (event.jaxis.axis == joystick_keymap.x_axis)
{
- if (event.jaxis.value < -JOYSTICK_DEAD_ZONE)
+ if (event.jaxis.value < -joystick_keymap.dead_zone)
{
tux.input.left = DOWN;
tux.input.right = UP;
}
- else if (event.jaxis.value > JOYSTICK_DEAD_ZONE)
+ else if (event.jaxis.value > joystick_keymap.dead_zone)
{
tux.input.left = UP;
tux.input.right = DOWN;
tux.input.right = DOWN;
}
}
- else if (event.jaxis.axis == JOY_Y)
+ else if (event.jaxis.axis == joystick_keymap.y_axis)
{
- if (event.jaxis.value > JOYSTICK_DEAD_ZONE)
+ if (event.jaxis.value > joystick_keymap.dead_zone)
tux.input.down = DOWN;
- else if (event.jaxis.value < -JOYSTICK_DEAD_ZONE)
+ else if (event.jaxis.value < -joystick_keymap.dead_zone)
tux.input.down = UP;
else
tux.input.down = UP;
break;
case SDL_JOYBUTTONDOWN:
- if (event.jbutton.button == JOY_A)
+ if (event.jbutton.button == joystick_keymap.a_button)
tux.input.up = DOWN;
- else if (event.jbutton.button == JOY_B)
+ else if (event.jbutton.button == joystick_keymap.b_button)
tux.input.fire = DOWN;
- else if (event.jbutton.button == JOY_START)
+ else if (event.jbutton.button == joystick_keymap.start_button)
on_escape_press();
break;
case SDL_JOYBUTTONUP:
- if (event.jbutton.button == JOY_A)
+ if (event.jbutton.button == joystick_keymap.a_button)
tux.input.up = UP;
- else if (event.jbutton.button == JOY_B)
+ else if (event.jbutton.button == joystick_keymap.b_button)
tux.input.fire = UP;
break;
/** The datadir prefix prepended when loading game data file */
std::string datadir;
-int JOY_A = 0;
-int JOY_B = 1;
-int JOY_START = 9;
+JoystickKeymap::JoystickKeymap()
+{
+ a_button = 0;
+ b_button = 1;
+ start_button = 9;
+
+ x_axis = 0;
+ y_axis = 1;
+
+ dead_zone = 4096;
+}
-int JOY_X = 0;
-int JOY_Y = 1;
+JoystickKeymap joystick_keymap;
SDL_Surface * screen;
Text* black_text;
bool use_fullscreen;
bool debug_mode;
bool show_fps;
-float game_speed = 1.0f;
+float game_speed = 1.2f;
int joystick_num = 0;
char* level_startup_file = 0;
extern std::string datadir;
-/* Joystick buttons and axes: */
-extern int JOY_A;
-extern int JOY_B;
-extern int JOY_START;
+struct JoystickKeymap
+{
+ int a_button;
+ int b_button;
+ int start_button;
-extern int JOY_X;
-extern int JOY_Y;
+ int x_axis;
+ int y_axis;
+
+ int dead_zone;
+
+ JoystickKeymap();
+};
+
+extern JoystickKeymap joystick_keymap;
extern SDL_Surface * screen;
extern Text* black_text;
int wait_for_event(SDL_Event& event,unsigned int min_delay = 0, unsigned int max_delay = 0, bool empty_events = false);
-#define JOYSTICK_DEAD_ZONE 4096
-
#endif /* SUPERTUX_GLOBALS_H */
}
break;
case SDL_JOYAXISMOTION:
- if(event.jaxis.axis == JOY_Y)
+ if(event.jaxis.axis == joystick_keymap.y_axis)
{
if (event.jaxis.value > 1024)
menuaction = MENU_ACTION_DOWN;
Surface* bigcape_right[2];
Surface* bigcape_left[2];
+PlayerKeymap keymap;
+
+PlayerKeymap::PlayerKeymap()
+{
+ keymap.jump = SDLK_UP;
+ keymap.duck = SDLK_DOWN;
+ keymap.left = SDLK_LEFT;
+ keymap.right = SDLK_RIGHT;
+ keymap.fire = SDLK_LCTRL;
+}
+
void player_input_init(player_input_type* pplayer_input)
{
pplayer_input->down = UP;
player_input_init(&input);
- keymap.jump = SDLK_UP;
- keymap.duck = SDLK_DOWN;
- keymap.left = SDLK_LEFT;
- keymap.right = SDLK_RIGHT;
- keymap.fire = SDLK_LCTRL;
-
invincible_timer.init(true);
skidding_timer.init(true);
safe_timer.init(true);
#include <vector>
-struct player_keymap_type
+struct PlayerKeymap
{
+public:
int jump;
int duck;
int left;
int right;
int fire;
+
+ PlayerKeymap();
};
struct player_input_type
class Player
{
- public:
- player_keymap_type keymap;
-
+public:
player_input_type input;
bool got_coffee;
int size;
Timer frame_timer;
Physic physic;
- public:
+public:
void init();
int key_event(SDLKey key, int state);
void level_begin();
bool on_ground();
bool under_solid();
- private:
+private:
void handle_horizontal_input();
void handle_vertical_input();
void remove_powerups();
};
#endif /*SUPERTUX_PLAYER_H*/
+
+/* Local Variables: */
+/* mode:c++ */
+/* End: */
break;
case SDL_JOYAXISMOTION:
- if (event.jaxis.axis == JOY_X)
+ if (event.jaxis.axis == joystick_keymap.x_axis)
{
- if (event.jaxis.value < -JOYSTICK_DEAD_ZONE)
+ if (event.jaxis.value < -joystick_keymap.dead_zone)
input_direction = WEST;
- else if (event.jaxis.value > JOYSTICK_DEAD_ZONE)
+ else if (event.jaxis.value > joystick_keymap.dead_zone)
input_direction = EAST;
}
- else if (event.jaxis.axis == JOY_Y)
+ else if (event.jaxis.axis == joystick_keymap.y_axis)
{
- if (event.jaxis.value > JOYSTICK_DEAD_ZONE)
+ if (event.jaxis.value > joystick_keymap.dead_zone)
input_direction = SOUTH;
- else if (event.jaxis.value < -JOYSTICK_DEAD_ZONE)
+ else if (event.jaxis.value < -joystick_keymap.dead_zone)
input_direction = NORTH;
}
break;
case SDL_JOYBUTTONDOWN:
- if (event.jbutton.button == JOY_B)
+ if (event.jbutton.button == joystick_keymap.b_button)
enter_level = true;
- else if (event.jbutton.button == JOY_START)
+ else if (event.jbutton.button == joystick_keymap.start_button)
on_escape_press();
break;