Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
fix keyboard input only working for one frame with controller plugged in
Browse files Browse the repository at this point in the history
  • Loading branch information
lemon32767 committed Sep 20, 2020
1 parent ef60837 commit 30a679c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
8 changes: 4 additions & 4 deletions emscripten-shell.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
<div class="emscripten">
<p>Experimental <a href="https://emscripten.org/">emscripten</a> build of <a href="https://github.com/lemon-sherbet/ccleste">ccleste</a>. <br>
<ul>
<li>Jump with Z/C</li>
<li>Dash with X/V</li>
<li>Move with arrow keys</li>
<li>Escape to pause</li>
<li>Jump with Z/C/Gamepad A</li>
<li>Dash with X/V/Gamepad B</li>
<li>Move with arrow keys/Gamepad d-pad/Gamepad left stick</li>
<li>Escape/Gamepad start to pause</li>
<li>Shift+S to save state</li>
<li>Shift+D to load state</li>
<li>Hold F9 to reset</li>
Expand Down
32 changes: 10 additions & 22 deletions sdl12main.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ static void mainLoop(void) {
}
} else reset_input_timer = 0;

buttons_state = 0;

#if SDL_MAJOR_VERSION >= 2
SDL_GameControllerUpdate();
Expand Down Expand Up @@ -454,31 +455,18 @@ static void mainLoop(void) {
) {
enable_screenshake = !enable_screenshake;
OSDset("screenshake: %s", enable_screenshake ? "on" : "off");
}
//else: fallthrough
}
case SDL_KEYUP: {
int down = ev.type == SDL_KEYDOWN;
int b = -1;
switch (ev.key.keysym.sym) {
case SDLK_LEFT: b = 0; break;
case SDLK_RIGHT: b = 1; break;
case SDLK_UP: b = 2; break;
case SDLK_DOWN: b = 3; break;
case SDLK_z: case SDLK_c: case SDLK_n: case SDLK_a:
b = 4; break;
case SDLK_x: case SDLK_v: case SDLK_m: case SDLK_b:
b = 5; break;
default: break;
}
if (!TAS && b >= 0) {
if (down) buttons_state |= (1<<b);
else buttons_state &= ~(1<<b);
}
} break;
}
}

if (TAS && !paused) {
if (!TAS) {
if (kbstate[SDLK_LEFT]) buttons_state |= (1<<0);
if (kbstate[SDLK_RIGHT]) buttons_state |= (1<<1);
if (kbstate[SDLK_UP]) buttons_state |= (1<<2);
if (kbstate[SDLK_DOWN]) buttons_state |= (1<<3);
if (kbstate[SDLK_z] || kbstate[SDLK_c] || kbstate[SDLK_n] || kbstate[SDLK_a]) buttons_state |= (1<<4);
if (kbstate[SDLK_x] || kbstate[SDLK_v] || kbstate[SDLK_m] || kbstate[SDLK_b]) buttons_state |= (1<<5);
} else if (TAS && !paused) {
static int t = 0;
t++;
if (t==1) buttons_state = 1<<4;
Expand Down

0 comments on commit 30a679c

Please sign in to comment.