Joypad controls (hardcoded, for now).
This commit is contained in:
parent
c287a1333e
commit
3afbfabeb5
15
src/defs.h
15
src/defs.h
|
@ -38,8 +38,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#define SAVE_FILENAME "game.save"
|
#define SAVE_FILENAME "game.save"
|
||||||
#define CONFIG_FILENAME "config.json"
|
#define CONFIG_FILENAME "config.json"
|
||||||
|
|
||||||
#define SCREEN_WIDTH 1280
|
#define SCREEN_WIDTH 1280
|
||||||
#define SCREEN_HEIGHT 720
|
#define SCREEN_HEIGHT 720
|
||||||
|
|
||||||
#define MAX_KEYBOARD_KEYS 350
|
#define MAX_KEYBOARD_KEYS 350
|
||||||
#define MAX_MOUSE_BUTTONS 6
|
#define MAX_MOUSE_BUTTONS 6
|
||||||
|
@ -53,7 +53,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#define MAX_NAME_LENGTH 32
|
#define MAX_NAME_LENGTH 32
|
||||||
#define MAX_DESCRIPTION_LENGTH 512
|
#define MAX_DESCRIPTION_LENGTH 512
|
||||||
#define MAX_LINE_LENGTH 1024
|
#define MAX_LINE_LENGTH 1024
|
||||||
#define MAX_FILENAME_LENGTH 1024
|
#define MAX_FILENAME_LENGTH 1024
|
||||||
|
|
||||||
#define NUM_TEXTURE_BUCKETS 32
|
#define NUM_TEXTURE_BUCKETS 32
|
||||||
|
@ -113,7 +113,7 @@ enum
|
||||||
};
|
};
|
||||||
|
|
||||||
#define EF_NONE 0
|
#define EF_NONE 0
|
||||||
#define EF_WEIGHTLESS (2 << 0)
|
#define EF_WEIGHTLESS (2 << 0)
|
||||||
#define EF_BOUNCES (2 << 1)
|
#define EF_BOUNCES (2 << 1)
|
||||||
#define EF_TELEPORTING (2 << 2)
|
#define EF_TELEPORTING (2 << 2)
|
||||||
#define EF_NO_ENVIRONMENT (2 << 3)
|
#define EF_NO_ENVIRONMENT (2 << 3)
|
||||||
|
@ -135,6 +135,13 @@ enum
|
||||||
#define GRAVITY_POWER 0.5f
|
#define GRAVITY_POWER 0.5f
|
||||||
#define FRICTION 0.75f
|
#define FRICTION 0.75f
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
JOYPAD_AXIS_X,
|
||||||
|
JOYPAD_AXIS_Y,
|
||||||
|
JOYPAD_AXIS_MAX
|
||||||
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
FACING_RIGHT,
|
FACING_RIGHT,
|
||||||
|
|
|
@ -320,6 +320,7 @@ typedef struct {
|
||||||
SDL_Joystick *joypad;
|
SDL_Joystick *joypad;
|
||||||
int keyboard[MAX_KEYBOARD_KEYS];
|
int keyboard[MAX_KEYBOARD_KEYS];
|
||||||
int joypadButton[SDL_CONTROLLER_BUTTON_MAX];
|
int joypadButton[SDL_CONTROLLER_BUTTON_MAX];
|
||||||
|
int joypadAxis[JOYPAD_AXIS_MAX];
|
||||||
SDL_Texture *backBuffer;
|
SDL_Texture *backBuffer;
|
||||||
SDL_Renderer *renderer;
|
SDL_Renderer *renderer;
|
||||||
SDL_Window *window;
|
SDL_Window *window;
|
||||||
|
|
|
@ -37,12 +37,38 @@ void initControls(void)
|
||||||
{
|
{
|
||||||
game.config.joypadControls[i] = -1;
|
game.config.joypadControls[i] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
game.config.joypadControls[CONTROL_JUMP] = 1;
|
||||||
|
game.config.joypadControls[CONTROL_FIRE] = 3;
|
||||||
|
game.config.joypadControls[CONTROL_JETPACK] = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int isControl(int type)
|
int isControl(int type)
|
||||||
{
|
{
|
||||||
int key = game.config.keyControls[type];
|
int key, btn;
|
||||||
int btn = game.config.joypadControls[type];
|
|
||||||
|
key = game.config.keyControls[type];
|
||||||
|
btn = game.config.joypadControls[type];
|
||||||
|
|
||||||
|
if (type == CONTROL_LEFT && app.joypadAxis[JOYPAD_AXIS_X] <= -16384)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == CONTROL_RIGHT && app.joypadAxis[JOYPAD_AXIS_X] >= 16384)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == CONTROL_UP && app.joypadAxis[JOYPAD_AXIS_Y] <= -16384)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == CONTROL_DOWN && app.joypadAxis[JOYPAD_AXIS_Y] >= 16384)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return ((key != 0 && app.keyboard[key]) || (btn != -1 && app.joypadButton[btn]));
|
return ((key != 0 && app.keyboard[key]) || (btn != -1 && app.joypadButton[btn]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,4 +163,9 @@ void handleInput(void)
|
||||||
{
|
{
|
||||||
app.joypadButton[i] = SDL_JoystickGetButton(app.joypad, i);
|
app.joypadButton[i] = SDL_JoystickGetButton(app.joypad, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0 ; i < JOYPAD_AXIS_MAX ; i++)
|
||||||
|
{
|
||||||
|
app.joypadAxis[i] = SDL_JoystickGetAxis(app.joypad, i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue