diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/engine.c | 9 | ||||
-rw-r--r-- | src/field.c | 47 |
2 files changed, 50 insertions, 6 deletions
diff --git a/src/engine.c b/src/engine.c index 6abda95..fd00e34 100644 --- a/src/engine.c +++ b/src/engine.c @@ -220,8 +220,9 @@ static void game_tick() static void signal_up() { - field_rotate_shape(&fld, 1); + field_rotate_shape_clockwise(&fld, 1); project_ghost_shape(&fld, 1, 0); + sfClock_restart(game.putTick); } static void signal_harddrop() @@ -239,7 +240,6 @@ static void signal_down() sfClock_restart(game.gameTick); game.scoreCurrent++; } - sfClock_restart(game.repPushDown); } static void signal_left() @@ -248,7 +248,6 @@ static void signal_left() project_ghost_shape(&fld, 1, 0); sfClock_restart(game.putTick); } - sfClock_restart(game.repKeyLeft); } static void signal_right() @@ -257,7 +256,6 @@ static void signal_right() project_ghost_shape(&fld, 1, 0); sfClock_restart(game.putTick); } - sfClock_restart(game.repKeyRight); } static void game_keys() @@ -287,6 +285,7 @@ static void game_keys() if (!(arrKeys & DOWN)) { arrKeys = arrKeys | DOWN; signal_down(); + sfClock_restart(game.repPushDown); } else { if (sfClock_getElapsedTime(game.repPushDown).microseconds >= moveRepeatLatency2) arrKeys = arrKeys & ~DOWN; @@ -300,6 +299,7 @@ static void game_keys() if (!(arrKeys & LEFT)) { arrKeys = arrKeys | LEFT; signal_left(); + sfClock_restart(game.repKeyLeft); } else if (!(arrKeys & LEFTHOLD)) { if (sfClock_getElapsedTime(game.repKeyLeft).microseconds >= moveRepeatLatency1) { arrKeys = arrKeys | LEFTHOLD; @@ -319,6 +319,7 @@ static void game_keys() if (!(arrKeys & RIGHT)) { arrKeys = arrKeys | RIGHT; signal_right(); + sfClock_restart(game.repKeyRight); } else if (!(arrKeys & RIGHTHOLD)) { if (sfClock_getElapsedTime(game.repKeyRight).microseconds >= moveRepeatLatency1) { arrKeys = arrKeys | RIGHTHOLD; diff --git a/src/field.c b/src/field.c index 62b6455..ebe61d5 100644 --- a/src/field.c +++ b/src/field.c @@ -179,12 +179,55 @@ static void rotate_shape_right(struct shape *shape) shape->c[j][i] = arr[i+1][3-j]; } -void field_rotate_shape(struct field *fld, unsigned int index) +static int wall_kick(struct field *fld, struct shape *shape) +{ + // try kick the left wall + shape->x++; + if (field_shape_collision(fld, shape)) + shape->x--; + else + return 1; + + // try kick the right wall + shape->x--; + if (field_shape_collision(fld, shape)) { + if (shape->t == 6) { + shape->x--; + if (field_shape_collision(fld, shape)) + shape->x++; + else + return 1; + } + shape->x++; + } else { + return 1; + } + + // try kick the floor + shape->y++; + if (field_shape_collision(fld, shape)) { + if (shape->t == 6) { + shape->y++; + if (field_shape_collision(fld, shape)) + shape->y--; + else + return 1; + } + shape->y--; + } else { + return 1; + } + + return 0; +} + +void field_rotate_shape_clockwise(struct field *fld, unsigned int index) { struct shape *shape = &fld->shape[index]; rotate_shape_right(shape); if (field_shape_collision(fld, shape)) - rotate_shape_left(shape); + if (!wall_kick(fld, shape)) + rotate_shape_left(shape); } int field_move_shape_down(struct field *fld, unsigned int index) |