aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <dbphillipsnz@gmail.com>2016-03-07 13:09:57 +1300
committerDavid Phillips <dbphillipsnz@gmail.com>2016-03-07 13:09:57 +1300
commit2d03cd7de5e9347fb7b3ad16928947f639d954bc (patch)
treec34b500f6550e64577ae53fc5e10c20b7571364d
parent3d5e998059750a66107663d8b18cc06b77a3bd10 (diff)
downloadtetris-2d03cd7de5e9347fb7b3ad16928947f639d954bc.tar.xz
Quick and dirty wall kick
-rw-r--r--tetris.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/tetris.c b/tetris.c
index 3b6364a..b768d0d 100644
--- a/tetris.c
+++ b/tetris.c
@@ -154,12 +154,15 @@ void new_piece(struct piece *held)
update_bitmap(held);
}
-void rotate(struct piece *held)
+void rotate(struct piece *held, int direction)
{
- held->rotation++;
+ held->rotation += direction;
if (held->rotation >= 4)
held->rotation -= 4;
+ if (held->rotation < 0)
+ held->rotation += 4;
+
update_bitmap(held);
}
@@ -196,6 +199,7 @@ void main_loop()
struct colour *board[WIDTH_CELLS][HEIGHT_CELLS];
SDL_Event e = {0};
bool running = false;
+ int i = 0;
int x = 0;
int y = 0;
int last_x = 0;
@@ -215,14 +219,13 @@ void main_loop()
{
lockout = 0;
clear_rows(&board);
+
if (hit_side(x, y, &held, &board))
- {
x = last_x;
- }
+
if (hit_floor(x, y, &held, &board))
- {
lockout = 1;
- }
+
draw_board(&board);
draw_piece(x, y, held.colour, held.bitmap);
plot_update();
@@ -251,7 +254,13 @@ void main_loop()
{
case SDLK_a: last_x = x--; break;
case SDLK_d: last_x = x++; break;
- case SDLK_w: rotate(&held); break;
+ case SDLK_w:
+ i = 0;
+ do
+ {
+ rotate(&held, 1);
+ } while(hit_side(x, y, &held, &board) && i++ < 4);
+ break;
case SDLK_q:
running = false;
break;