Add new inputs
This commit is contained in:
parent
e982cd73a8
commit
a20766e335
@ -12,6 +12,9 @@ namespace game
|
||||
PI_CROUCH = 1 << 5,
|
||||
PI_USE = 1 << 6,
|
||||
PI_ATTACK = 1 << 7,
|
||||
PI_DEBUG1 = 1 << 8,
|
||||
PI_DEBUG2 = 1 << 9,
|
||||
PI_DEBUG3 = 1 << 10,
|
||||
};
|
||||
|
||||
using PlayerInputFlags = unsigned int;
|
||||
|
||||
33
src/main.cpp
33
src/main.cpp
@ -94,7 +94,7 @@ static bool InitGL()
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
glDebugMessageCallback(GLDebugCallback, 0);
|
||||
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
SDL_GL_SetSwapInterval(0);
|
||||
#endif
|
||||
|
||||
|
||||
@ -156,29 +156,44 @@ static void Frame()
|
||||
s_app->SetViewportSize(width, height);
|
||||
|
||||
game::PlayerInputFlags input = 0;
|
||||
const uint8_t* state = SDL_GetKeyboardState(nullptr);
|
||||
const uint8_t* kbd_state = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
if (state[SDL_GetScancodeFromKey(SDLK_w)])
|
||||
if (kbd_state[SDL_GetScancodeFromKey(SDLK_w)])
|
||||
input |= game::PI_FORWARD;
|
||||
|
||||
if (state[SDL_GetScancodeFromKey(SDLK_s)])
|
||||
if (kbd_state[SDL_GetScancodeFromKey(SDLK_s)])
|
||||
input |= game::PI_BACKWARD;
|
||||
|
||||
if (state[SDL_GetScancodeFromKey(SDLK_a)])
|
||||
if (kbd_state[SDL_GetScancodeFromKey(SDLK_a)])
|
||||
input |= game::PI_LEFT;
|
||||
|
||||
if (state[SDL_GetScancodeFromKey(SDLK_d)])
|
||||
if (kbd_state[SDL_GetScancodeFromKey(SDLK_d)])
|
||||
input |= game::PI_RIGHT;
|
||||
|
||||
if (state[SDL_GetScancodeFromKey(SDLK_SPACE)])
|
||||
if (kbd_state[SDL_GetScancodeFromKey(SDLK_SPACE)])
|
||||
input |= game::PI_JUMP;
|
||||
|
||||
if (state[SDL_GetScancodeFromKey(SDLK_LCTRL)])
|
||||
if (kbd_state[SDL_GetScancodeFromKey(SDLK_LCTRL)])
|
||||
input |= game::PI_CROUCH;
|
||||
|
||||
if (state[SDL_GetScancodeFromKey(SDLK_e)])
|
||||
if (kbd_state[SDL_GetScancodeFromKey(SDLK_e)])
|
||||
input |= game::PI_USE;
|
||||
|
||||
if (kbd_state[SDL_GetScancodeFromKey(SDLK_F3)])
|
||||
input |= game::PI_DEBUG1;
|
||||
|
||||
if (kbd_state[SDL_GetScancodeFromKey(SDLK_F4)])
|
||||
input |= game::PI_DEBUG2;
|
||||
|
||||
if (kbd_state[SDL_GetScancodeFromKey(SDLK_F5)])
|
||||
input |= game::PI_DEBUG3;
|
||||
|
||||
int mouse_state = SDL_GetMouseState(nullptr, nullptr);
|
||||
|
||||
if (mouse_state & SDL_BUTTON(SDL_BUTTON_LEFT))
|
||||
input |= game::PI_ATTACK;
|
||||
|
||||
|
||||
s_app->SetInput(input);
|
||||
|
||||
s_app->Frame();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user