jag

tetoris_c

public

Small block game in C

Star0
Watch0

Commit a5d2e11a0a02

tarball

Jaglekon <58274093+Jaglekon@users.noreply.github.com>2026-07-17 14:55 UTC

1 file changed+27-4
crude rotation
Modified file: main.c+27 additions−4 deletions
@@ -156,8 +156,7 @@ int main () {
156156 current_piece.x + move + current_piece.size <= FULL_WIDTH
157157 ) {
158158
159- bool is_valid = true;
160-
159+ bool is_valid = true;
161160
162161 for (j = 0; j < current_piece.size; j++) {
163162 for (k = 0; k < current_piece.size; k++) {
@@ -185,7 +184,31 @@ int main () {
185184
186185 if (rotate) {
187186
188- direction new_direction = (current_piece.rotation + 1) % (LEFT + 1);
187+ piece rotated = current_piece;
188+
189+ rotated.rotation = (current_piece.rotation + 1) % (LEFT + 1);
190+
191+ bool is_valid = true;
192+
193+ for(j = 0; j < rotated.size; j++) {
194+ for (k = 0; k < rotated.size; k++) {
195+
196+ coord points = find_direction(rotated, k, j);
197+
198+ if (
199+ rotated.piece[j][k] &&
200+ playfield[rotated.y + points.y][rotated.x + points.x] != EMPTY
201+ ) {
202+ is_valid = false;
203+ }
204+ }
205+ }
206+
207+ if (is_valid) {
208+ current_piece = rotated;
209+ draw = true;
210+ }
211+
189212 }
190213
191214
@@ -270,9 +293,9 @@ int main () {
270293
271294 for (j = 0; j < FIELD_WIDTH; j++) {
272295 if (playfield[TOP_GAP][j + BORDER_WIDTH] > 0) {
273- printf("\033[2J\033[H");
274296 draw_board(current_piece, -1, is_piece);
275297 sleep(2);
298+ printf("\033[2J\033[H");
276299 printf("HAHA LOSER\n");
277300 sleep(1);
278301 goto end;