diff options
author | Oxore <oxore@protonmail.com> | 2018-07-09 03:53:22 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2018-07-09 03:53:22 +0300 |
commit | a3eaa5d7cd4bdb5cf1977c4cd4e8b4dd28e737ea (patch) | |
tree | 16b61f03e1dab98aa9aebcf8a0a37f43c673654d /src/field.c | |
parent | a673d86621054f18b25add5878efab6fa035e352 (diff) |
Introduce wall kick, refactor
Refactor controls a little: move key repeat clocks reset to the keys
handler.
Refactor field: rename rotation function (add "clockwise" postfix).
Diffstat (limited to 'src/field.c')
-rw-r--r-- | src/field.c | 47 |
1 files changed, 45 insertions, 2 deletions
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) |