Update events.c

This commit is contained in:
Jason Bou-Samra
2024-08-30 19:20:13 +10:00
committed by GitHub
parent 3bc00fa22d
commit d0f8e52d9a
+39 -25
View File
@@ -14,70 +14,83 @@ bool gradient_d = false; // gradient direction flag
int handle_events () {
//////////////////////////////// GAME LOOP //////////////////////////
////////////////////////////// EVENT LOOP //////////////////////////
while (restart == false) {
SDL_PollEvent (&event);
switch (event.type) {
case SDL_KEYDOWN:
// gradient colour cycle
if(event.key.keysym.sym == SDLK_c
&& (event.key.keysym.mod & KMOD_CTRL) != 0 ) {
colour = colour + 10;
if (colour >= 69) {colour = 0;}
backdrop(colour);
break;
} // gradient colour cycle
}
if( event.key.keysym.sym == SDLK_x
&& (event.key.keysym.mod & KMOD_CTRL) != 0 ) {
// invert gradient
if( event.key.keysym.sym == SDLK_x
&& (event.key.keysym.mod & KMOD_CTRL) != 0 ) {
gradient_d = !gradient_d;
break;
} // invert gradient
}
if (event.key.keysym.sym == SDLK_LEFT) {
if (col == 0) {break;}
grid[0][row + 1][col] = 0;
grid[0][row + 0][col] = 0;
grid[0][row + 2][col] = 0;
grid[0][row - 1][col] = 0;
// left arrow
if (event.key.keysym.sym == SDLK_LEFT) {
if (col == 0 | grid[0][row + 2][col - 1] != 0) {break;}
for (int i = -1; i < 3; i++) {
grid[0][row + i][col] = 0; // zero out old column
}
col--;
disp_column (row, col);
break;
} // left arrow
}
// right arrow
if (event.key.keysym.sym == SDLK_RIGHT) {
if (col == 7) {break;}
grid[0][row + 1][col] = 0;
grid[0][row + 0][col] = 0;
grid[0][row + 2][col] = 0;
grid[0][row - 1][col] = 0;
if (col == 7 | grid[0][row + 2][col + 1] != 0) {break;}
for (int i = -1; i < 3; i++) {
grid[0][row + i][col] = 0; // zero out old column
}
col++;
disp_column (row, col);
break;
} // right arrow
}
// next piece (brick/block) preview
if (event.key.keysym.sym == SDLK_n) {
next_p = !next_p;
break;
} // next piece (brick/block) preview
}
// restart
if( event.key.keysym.sym == SDLK_r
&& (event.key.keysym.mod & KMOD_CTRL) != 0 ) {
restart = true;
break;
} // restart
}
// rotate tiles
if(event.key.keysym.sym == SDLK_r
&& (event.key.keysym.mod & KMOD_SHIFT) != 0 ) {
rotate_col();
disp_column (row, col);
break;
} // rotate tiles
}
// drop/fall block/piece/brick
if (event.key.keysym.sym == SDLK_SPACE) {
for (int i = -1; i < 3; i++) {
grid[0][row + i][col] = 0; // zero out old column
}
row = 18 - (18-colcnt[col]);
disp_column (row, col);
break;
} // drop/fall block/piece/brick
}
// change tile design/pattern
if( event.key.keysym.sym == SDLK_s
&& (event.key.keysym.mod & KMOD_CTRL) != 0 ) {
tile_shp++;
@@ -85,12 +98,13 @@ int handle_events () {
tile_shp = 0;
}
break;
} // change tile design/pattern
}
// pause
if (event.key.keysym.sym == SDLK_p) {
pause_f = !pause_f;
break;
} // pause
}
}
Ren_game ();
}