diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 83 |
1 files changed, 39 insertions, 44 deletions
diff --git a/src/main.c b/src/main.c index 2fee6bd..255d841 100644 --- a/src/main.c +++ b/src/main.c @@ -14,6 +14,7 @@ #define FALL_TICK 0.3 #define SOFT_DROP_MULT 4.0 #define LOCK_TICK 0.5 +#define DAS 0.3 enum InputResult { NONE = 0, @@ -49,6 +50,7 @@ struct { int held; double phase_time; double fall_tick; + double das_timer; } game_state; void draw_block(int x, int y, int width, int height, struct Color color) @@ -354,58 +356,51 @@ void hold_piece(void) } int handle_input(void) { - static int moved_l = 0; - static int moved_r = 0; - static int moved_cw = 0; - static int moved_ccw = 0; - static int hard_dropped = 0; - - if (IsKeyDown(KEY_A)) { - if (!moved_l) { - moved_l = move_piece(-1); - return MOVED; - } - } else { - moved_l = 0; + enum InputResult action = NONE; + + if (IsKeyPressed(KEY_A)) { + move_piece(-1); + game_state.das_timer = 0.0; + action = MOVED; } - if (IsKeyDown(KEY_D)) { - if (!moved_r) { - moved_r = move_piece(+1); - return MOVED; - } - } else { - moved_r = 0; + if (IsKeyPressed(KEY_D)) { + move_piece(+1); + game_state.das_timer = 0.0; + action = MOVED; } - if (IsKeyDown(KEY_L)) { - if (!moved_cw) { - moved_cw = rotate_piece(+1); - return MOVED; - } + if (IsKeyDown(KEY_A) || IsKeyDown(KEY_D)) { + game_state.das_timer += GetFrameTime(); } else { - moved_cw = 0; + game_state.das_timer = 0.0; } - if (IsKeyDown(KEY_J)) { - if (!moved_ccw) { - moved_ccw = rotate_piece(-1); - return MOVED; - } - } else { - moved_ccw = 0; + if (IsKeyDown(KEY_A) && game_state.das_timer > DAS) { + move_piece(-1); + action = MOVED; } - if (IsKeyDown(KEY_W)) { - if (!hard_dropped) { - hard_dropped = 1; - while (!is_overlap(0, -1)) { - game_state.current_piece.pos_y--; - } - return HARD_DROPPED; + if (IsKeyDown(KEY_D) && game_state.das_timer > DAS) { + move_piece(+1); + action = MOVED; + } + + if (IsKeyPressed(KEY_L)) { + rotate_piece(+1); + action = MOVED; + } + + if (IsKeyPressed(KEY_J)) { + rotate_piece(-1); + action = MOVED; + } + + if (IsKeyPressed(KEY_W)) { + while (!is_overlap(0, -1)) { + game_state.current_piece.pos_y--; } - } else { - hard_dropped = 0; + action = HARD_DROPPED; } if (IsKeyDown(KEY_S)) { @@ -414,11 +409,11 @@ int handle_input(void) { game_state.fall_tick = FALL_TICK; } - if (IsKeyDown(KEY_SPACE)) { + if (IsKeyPressed(KEY_SPACE)) { hold_piece(); } - return NONE; + return action; } void lock_phase(void) { |