Skip to content

Commit 5d62659

Browse files
committed
minor bug fix with no IsKeyPressed not working on web
1 parent 6744a8b commit 5d62659

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

pufferlib/ocean/g2048/g2048.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ int main() {
2626
c_render(&env);
2727
frame++;
2828

29-
int action = 0;
29+
int action = -1;
3030
if (IsKeyDown(KEY_LEFT_SHIFT)) {
31-
if (IsKeyPressed(KEY_W) || IsKeyPressed(KEY_UP)) action = UP;
32-
else if (IsKeyPressed(KEY_S) || IsKeyPressed(KEY_DOWN)) action = DOWN;
33-
else if (IsKeyPressed(KEY_A) || IsKeyPressed(KEY_LEFT)) action = LEFT;
34-
else if (IsKeyPressed(KEY_D) || IsKeyPressed(KEY_RIGHT)) action = RIGHT;
31+
if (IsKeyDown(KEY_W) || IsKeyDown(KEY_UP)) action = UP;
32+
else if (IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN)) action = DOWN;
33+
else if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT)) action = LEFT;
34+
else if (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT)) action = RIGHT;
3535
env.actions[0] = action - 1;
3636
} else if (frame % 10 != 0) {
3737
continue;
@@ -43,9 +43,14 @@ int main() {
4343
forward_linearlstm(net, net->obs, env.actions);
4444
}
4545

46-
if (action != 0) {
46+
if (action >= 0) {
4747
c_step(&env);
4848
}
49+
50+
if (IsKeyDown(KEY_LEFT_SHIFT) && action >= 0) {
51+
WaitTime(0.01);
52+
}
53+
4954
}
5055

5156
free_linearlstm(net);

0 commit comments

Comments
 (0)