diff options
author | Oxore <oxore@protonmail.com> | 2017-12-01 05:28:10 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2017-12-01 05:28:10 +0300 |
commit | e949a49287b38574c7372c9a6c1c759eafa3266c (patch) | |
tree | 206266cae6a0cf9703d3b09110f0165ff29200b3 /src | |
parent | 027a94b74a2ff36eddbffc1cce4dcdc14126c813 (diff) |
Wrap global variables into structures
Diffstat (limited to 'src')
-rw-r--r-- | src/functions.c | 274 | ||||
-rw-r--r-- | src/main.c | 112 |
2 files changed, 178 insertions, 208 deletions
diff --git a/src/functions.c b/src/functions.c index e376f6b..bce83f1 100644 --- a/src/functions.c +++ b/src/functions.c @@ -3,17 +3,10 @@ /* Externs from main.c */ -extern sfRectangleShape* ns[4][4]; // Array of next shape image rectangles -extern sfVector2f nsCSize; // Next shape rectangles size variable x/y -extern sfRectangleShape *fld[25][10]; // Array of field rectangles -extern sfVector2f fldCPos[25][10]; // Array of abs coords of field rectangles -extern sfVector2i fldSize; -extern sfVector2f fldPos; -extern sfVector2f fldCSize; // Field rectangles size variable x/y -extern int fldCOutThick; // Field rectangles outline thickness +extern Shape active, next; +extern Field fld; extern sfVector2f textScore_pos; -extern sfText *textScore; extern sfFont *fontScore; extern int gameIsStarted; @@ -37,7 +30,7 @@ extern sfClock *repKeyRight; // Clock for repeat latency when Left arrow long pu extern int lvlLatency; extern int scoreCurrent; -extern char *scoreDisp; + /* Shapes maps */ extern uint8_t arrShapeL[4][4]; extern uint8_t arrShapeRL[4][4]; @@ -51,34 +44,33 @@ extern uint8_t arrShapeT[4][4]; /* Field init routine */ void initFld() { + sfVector2f fldCPos[25][10]; /* Create field */ - for (int j = 0; j < fldSize.y; j++) { - for(int i = 0; i < fldSize.x; i++) { - fldCAtt[j][i].a = 0; // Inactive = empty - fldCPos[j][i].x = fldPos.x - + (i * (fldCSize.x + 2 * fldCOutThick)); - fldCPos[j][i].y = fldPos.y - - (j * (fldCSize.y + 2 * fldCOutThick)); - fld[j][i] = sfRectangleShape_create(); - sfRectangleShape_setFillColor(fld[j][i], uiColor1); - sfRectangleShape_setSize(fld[j][i], fldCSize); - sfRectangleShape_setPosition(fld[j][i], fldCPos[j][i]); - sfRectangleShape_setOutlineColor(fld[j][i], uiColor3); - sfRectangleShape_setOutlineThickness(fld[j][i], - fldCOutThick); + for (int j = 0; j < fld.size.y; j++) { + for(int i = 0; i < fld.size.x; i++) { + fld.c[j][i].a = 0; // Inactive = empty + fldCPos[j][i].x = fld.pos.x + (i * (fld.cSize.x + 2 * fld.cOutThick)); + fldCPos[j][i].y = fld.pos.y - (j * (fld.cSize.y + 2 * fld.cOutThick)); + fld.p[j][i] = sfRectangleShape_create(); + sfRectangleShape_setFillColor(fld.p[j][i], uiColor1); + sfRectangleShape_setSize(fld.p[j][i], fld.cSize); + sfRectangleShape_setPosition(fld.p[j][i], fldCPos[j][i]); + sfRectangleShape_setOutlineColor(fld.p[j][i], uiColor3); + sfRectangleShape_setOutlineThickness(fld.p[j][i], + fld.cOutThick); } } /* Create next shape field */ sfVector2f nsPos; for (int j = 0; j < 4; j++) { for(int i = 0; i < 4; i++) { - nsPos.x = nxtShape.x+i*(nsCSize.x+2*fldCOutThick); - nsPos.y = nxtShape.y-j*(nsCSize.y+2*fldCOutThick); - ns[j][i] = sfRectangleShape_create(); - sfRectangleShape_setSize(ns[j][i], nsCSize); - sfRectangleShape_setPosition(ns[j][i], nsPos); - sfRectangleShape_setOutlineThickness(ns[j][i], - fldCOutThick); + nsPos.x = next.x+i*(next.cSize.x+2*fld.cOutThick); + nsPos.y = next.y-j*(next.cSize.y+2*fld.cOutThick); + next.p[j][i] = sfRectangleShape_create(); + sfRectangleShape_setSize(next.p[j][i], next.cSize); + sfRectangleShape_setPosition(next.p[j][i], nsPos); + sfRectangleShape_setOutlineThickness(next.p[j][i], + fld.cOutThick); } } genNextShape(); @@ -89,17 +81,17 @@ void initFld() * Refreshes score * */ -void scoreDisplay(int score, sfText *textScore) +void scoreDisplay(int s, Text *textScore) { char a[64]; char b[8]; sprintf(b, "Score: "); - sprintf(a, "%d", score); + sprintf(a, "%d", s); for (int i = 63; i >= 7; i--) a[i] = a[i-7]; for (int i = 0; i < 7; i++) a[i] = b[i]; - sfText_setString(textScore, (char *)&a); + sfText_setString(textScore->text, (char *)&a); } /* @@ -112,7 +104,7 @@ int linesRmScore() int s = 0; for (int j = 0; j < 20; j++) { for (int i = 0; i < 10; i++) { - if (fldCAtt[j][i].a != 0) + if (fld.c[j][i].a != 0) k++; } if (k >= 10) { // If line is full @@ -120,15 +112,15 @@ int linesRmScore() for (int n = j; n < 20; n++) { // Drop all lines down if (n == 19) { for (int m = 0; m < 10; m++) { - fldCAtt[n][m].a = 0; - fldCAtt[n][m].fColor = uiColor1; + fld.c[n][m].a = 0; + fld.c[n][m].fColor = uiColor1; } break; } for (int m = 0; m < 10; m++) { - fldCAtt[n][m].a = fldCAtt[n+1][m].a; - fldCAtt[n][m].fColor - = fldCAtt[n+1][m].fColor; + fld.c[n][m].a = fld.c[n+1][m].a; + fld.c[n][m].fColor + = fld.c[n+1][m].fColor; } } j--; // Do not let loop to go to next line because @@ -146,23 +138,16 @@ int linesRmScore() */ void putShape() { - for (int j = 0; j < 4; j++) { - for (int i = 0; i < 4; i++) { - if (actiSh.c[j][i]) { - fldCAtt[j+actiSh.y][i+actiSh.x].a - = actiSh.c[j][i]; - if ((j+actiSh.y >= 0) - && (i+actiSh.x >= 0)) { - fldCAtt[j+actiSh.y][i+actiSh.x].fColor - = actiSh.fColor; - } + for (int j = 0; j < 4; j++) + for (int i = 0; i < 4; i++) + if (active.c[j][i]) { + fld.c[j+active.y][i+active.x].a = active.c[j][i]; + if ((j+active.y >= 0) && (i+active.x >= 0)) + fld.c[j+active.y][i+active.x].fColor = active.fColor; } - } - } - scoreCurrent += linesRmScore()*100; // Remove filled lines and - // get score; + scoreCurrent += linesRmScore()*100; // Remove filled lines and get score; for (int i = 0; i < 10; i++) - if (fldCAtt[20][i].a) { + if (fld.c[20][i].a) { gameover(); return; } @@ -172,15 +157,15 @@ void putShape() void resetActiveShape() { genNextShape(); - copyShape(&actiSh); - actiSh.x = 3; - if (actiSh.t == 6) - actiSh.y = 17; + copyShape(&active); + active.x = 3; + if (active.t == 6) + active.y = 17; else - actiSh.y = 16; + active.y = 16; for (;;) { if (cellCollisionCheck(0b0010)) - actiSh.y++; + active.y++; else break; } @@ -197,7 +182,7 @@ void tTick() /* if bottom not reached */ if ((wallCollisionCheck(0b0010) == 0) && (cellCollisionCheck(0b0010) == 0)) - actiSh.y--; // Move + active.y--; // Move else putShape(); // Just put the shape } @@ -211,18 +196,18 @@ void tTick() void rotateLeft() { uint8_t arr[4][4]; - memcpy(&arr[0][0], &actiSh.c[0][0], sizeof(uint8_t)*4*4); - if (actiSh.t == 5) + memcpy(&arr[0][0], &active.c[0][0], sizeof(uint8_t)*4*4); + if (active.t == 5) return; - if (actiSh.t == 6) { + if (active.t == 6) { for (int j = 3; j >= 0; j--) for (int i = 0; i < 4; i++) - actiSh.c[j][i] = arr[3-i][3-j]; + active.c[j][i] = arr[3-i][3-j]; return; } for (int j = 3; j > 0; j--) for (int i = 0; i < 3; i++) - actiSh.c[j][i] = arr[3-i][j-1]; + active.c[j][i] = arr[3-i][j-1]; } @@ -233,18 +218,18 @@ void rotateLeft() void rotateRight() { uint8_t arr[4][4]; - memcpy(&arr[0][0], &actiSh.c[0][0], sizeof(uint8_t)*4*4); - if (actiSh.t == 5) + memcpy(&arr[0][0], &active.c[0][0], sizeof(uint8_t)*4*4); + if (active.t == 5) return; - if (actiSh.t == 6) { + if (active.t == 6) { for (int j = 3; j >= 0; j--) for (int i = 0; i < 4; i++) - actiSh.c[j][i] = arr[3-i][3-j]; + active.c[j][i] = arr[3-i][3-j]; return; } for (int j = 3; j > 0; j--) for (int i = 0; i < 3; i++) - actiSh.c[j][i] = arr[i+1][3-j]; + active.c[j][i] = arr[i+1][3-j]; } @@ -264,8 +249,8 @@ int cellRotCollisionCheck() { for (int j = 0; j < 4; j++) for (int i = 0; i < 4; i++) - if (actiSh.c[j][i] - && fldCAtt[j+actiSh.y][i+actiSh.x].a) + if (active.c[j][i] + && fld.c[j+active.y][i+active.x].a) return 1; // Collision happens return 0; // Else it do not } @@ -273,17 +258,17 @@ int cellRotCollisionCheck() int wallRotCollisionCheck() { - if(actiSh.y < 0) //If shape has crossed Bottom border + if(active.y < 0) //If shape has crossed Bottom border for(int i = 0; i < 4; i++) - if (actiSh.c[-1-actiSh.y][i]) + if (active.c[-1-active.y][i]) return 1; // Collision happens - if(actiSh.x < 0) //If shape has crossed Left border + if(active.x < 0) //If shape has crossed Left border for(int i = 0; i < 4; i++) - if (actiSh.c[i][-1-actiSh.x]) + if (active.c[i][-1-active.x]) return 1; // Collision happens - if(actiSh.x > 6) //If shape has crossed Right border + if(active.x > 6) //If shape has crossed Right border for(int i = 0; i < 4; i++) - if (actiSh.c[i][3-(actiSh.x-7)]) + if (active.c[i][3-(active.x-7)]) return 1; // Collision happens return 0; // If no conditions are met collision is absent } @@ -294,22 +279,22 @@ int cellCollisionCheck(int dir) for (int j = 0; j < 4; j++) { for (int i = 0; i < 4; i++) { if ((dir & 0b0001) // Check Right - && (j+actiSh.y >= 0) // Avoiding nonexisting fld cells - && (i+actiSh.x+1 >= 0) // --- - && actiSh.c[j][i] // Check activity - && fldCAtt[j+actiSh.y][i+actiSh.x+1].a) + && (j+active.y >= 0) // Avoiding nonexisting fld cells + && (i+active.x+1 >= 0) // --- + && active.c[j][i] // Check activity + && fld.c[j+active.y][i+active.x+1].a) return 1; // Collision happens if ((dir & 0b1000) // Check Left - && (j+actiSh.y >= 0) // Avoiding nonexisting fld cells - && (i+actiSh.x-1 >= 0) // --- - && actiSh.c[j][i] // Check activity - && fldCAtt[j+actiSh.y][i+actiSh.x-1].a) + && (j+active.y >= 0) // Avoiding nonexisting fld cells + && (i+active.x-1 >= 0) // --- + && active.c[j][i] // Check activity + && fld.c[j+active.y][i+active.x-1].a) return 1; // Collision happens if ((dir & 0b0010) // Check Bottom - && (j+actiSh.y-1 >= 0) // Avoiding nonexisting fld cells - && (i+actiSh.x >= 0) // --- - && actiSh.c[j][i] // Check activity - && fldCAtt[j+actiSh.y-1][i+actiSh.x].a) + && (j+active.y-1 >= 0) // Avoiding nonexisting fld cells + && (i+active.x >= 0) // --- + && active.c[j][i] // Check activity + && fld.c[j+active.y-1][i+active.x].a) return 1; // Collision happens } } @@ -319,19 +304,19 @@ int cellCollisionCheck(int dir) int wallCollisionCheck(int dir) { if (dir & 0b0001) { // Right collision request - if (actiSh.x >= 6) // If shape has reached Right boreder + if (active.x >= 6) // If shape has reached Right boreder for (int i = 0 ; i < 4; i++) - if (actiSh.c[i][3-(actiSh.x-6)]) + if (active.c[i][3-(active.x-6)]) return 1; // Collision happens } else if (dir & 0b0010) { // Bottom collision request - if (actiSh.y <= 0) //If shape has reached Bottom border + if (active.y <= 0) //If shape has reached Bottom border for (int i = 0; i < 4; i++) - if (actiSh.c[-actiSh.y][i]) + if (active.c[-active.y][i]) return 1; // Collision happens } else if (dir & 0b1000) // Left collision request - if (actiSh.x <= 0) // If shape has reached Left border + if (active.x <= 0) // If shape has reached Left border for (int i = 0; i < 4; i++) - if (actiSh.c[i][-actiSh.x]) + if (active.c[i][-active.x]) return 1; // Collision happens return 0; } @@ -361,7 +346,7 @@ void tKeyCtrl() arrKeys = arrKeys | 0b0010; if (!wallCollisionCheck(0b0010) && !cellCollisionCheck(0b0010)) { - actiSh.y--; + active.y--; // Avoid excess move down by gameTick sfClock_restart(gameTick); scoreCurrent++; @@ -386,7 +371,7 @@ void tKeyCtrl() arrKeys = arrKeys | 0b1000; if (!wallCollisionCheck(0b1000) && !cellCollisionCheck(0b1000)) - actiSh.x--; + active.x--; repKeyLeft = sfClock_create(); } else { if (!(arrKeys & 0b10000000)) { @@ -417,7 +402,7 @@ void tKeyCtrl() arrKeys = arrKeys | 0b0001; if (!wallCollisionCheck(0b0001) && !cellCollisionCheck(0b0001)) - actiSh.x++; + active.x++; repKeyRight = sfClock_create(); } else { if (!(arrKeys & 0b10000)) { @@ -449,28 +434,27 @@ void tKeyCtrl() */ void colorizeFld() { - for(int j = 0; j < fldSize.y-5; j++) { - for(int i = 0; i < fldSize.x; i++) { - if (fldCAtt[j][i].a) { + for(int j = 0; j < fld.size.y-5; j++) { + for(int i = 0; i < fld.size.x; i++) { + if (fld.c[j][i].a) { sfRectangleShape_setFillColor( - fld[j][i], - fldCAtt[j][i].fColor); + fld.p[j][i], + fld.c[j][i].fColor); sfRectangleShape_setOutlineColor( - fld[j][i], + fld.p[j][i], uiColor3); } else { sfRectangleShape_setFillColor( - fld[j][i], + fld.p[j][i], uiColor1); sfRectangleShape_setOutlineColor( - fld[j][i], + fld.p[j][i], uiColor2); } } } } - /* * Colorize active cells of active shape (overlay only * active cells above background of fld) @@ -480,12 +464,12 @@ void colorizeActiSh() { for(int j = 0; j < 4; j++) { for(int i = 0; i < 4; i++) { - if (actiSh.c[j][i] && j+actiSh.y < 20) { + if (active.c[j][i] && j+active.y < 20) { sfRectangleShape_setFillColor( - fld[j+actiSh.y][i+actiSh.x], - actiSh.fColor); + fld.p[j+active.y][i+active.x], + active.fColor); sfRectangleShape_setOutlineColor( - fld[j+actiSh.y][i+actiSh.x], + fld.p[j+active.y][i+active.x], uiColor3); } } @@ -499,10 +483,10 @@ void colorizeActiSh() */ void drawFld(sfRenderWindow *window) { - for (int j = 0; j < fldSize.y; j++){ - for(int i = 0; i < fldSize.x; i++){ + for (int j = 0; j < fld.size.y; j++){ + for(int i = 0; i < fld.size.x; i++){ sfRenderWindow_drawRectangleShape(window, - fld[j][i], + fld.p[j][i], NULL); } } @@ -521,40 +505,40 @@ void menuTick() void colorizeRandom() { int a; - for (int j = 0; j < fldSize.y-5; j++) { - for (int i = 0; i < fldSize.x; i++) { + for (int j = 0; j < fld.size.y-5; j++) { + for (int i = 0; i < fld.size.x; i++) { a = rand()%7+1; switch (a) { case 1 : - sfRectangleShape_setFillColor(fld[j][i], + sfRectangleShape_setFillColor(fld.p[j][i], tOrange); break; case 2 : - sfRectangleShape_setFillColor(fld[j][i], + sfRectangleShape_setFillColor(fld.p[j][i], tBlue); break; case 3 : - sfRectangleShape_setFillColor(fld[j][i], + sfRectangleShape_setFillColor(fld.p[j][i], tRed); break; case 4 : - sfRectangleShape_setFillColor(fld[j][i], + sfRectangleShape_setFillColor(fld.p[j][i], tGreen); break; case 5 : - sfRectangleShape_setFillColor(fld[j][i], + sfRectangleShape_setFillColor(fld.p[j][i], tYellow); break; case 6 : - sfRectangleShape_setFillColor(fld[j][i], + sfRectangleShape_setFillColor(fld.p[j][i], tCyan); break; case 7 : - sfRectangleShape_setFillColor(fld[j][i], + sfRectangleShape_setFillColor(fld.p[j][i], tMagneta); break; } - sfRectangleShape_setOutlineColor(fld[j][i], uiColor3); + sfRectangleShape_setOutlineColor(fld.p[j][i], uiColor3); } } } @@ -569,17 +553,17 @@ void gameover() void genNextShape() { - actiSh.t = nxtShape.t; - nxtShape.t = (rand()%7)+1; // Insert new random shape of 7 variants - copyShape(&nxtShape); - if (nxtShape.t == 5) + active.t = next.t; + next.t = (rand()%7)+1; // Insert new random shape of 7 variants + copyShape(&next); + if (next.t == 5) for (int j = 0; j < 3; j++) for (int i = 0; i < 4; i++) - nxtShape.c[i][j] = nxtShape.c[i][j+1]; + next.c[i][j] = next.c[i][j+1]; } -void copyShape(struct shapeSt *localSh) +void copyShape(Shape *localSh) { switch (localSh->t) { // Copy cell active/inactive state case 1 : @@ -639,28 +623,22 @@ void drawNextShape(sfRenderWindow *window) sfText_setFont(textNextShape, fontScore); sfText_setCharacterSize(textNextShape, 20); sfText_setPosition(textNextShape, textNextShapePos); - char a[13]; - sprintf(a, "Next Shape: "); - sfText_setString(textNextShape, (char *)&a); + sfText_setString(textNextShape, "Next Shape: "); sfRenderWindow_drawText(window, textNextShape, NULL); for(int j = 0; j < 4; j++) for(int i = 0; i < 4; i++) - if (nxtShape.c[j][i]) { - sfRectangleShape_setFillColor(ns[j][i], - nxtShape.fColor); - sfRectangleShape_setOutlineColor(ns[j][i], - uiColor3); - sfRenderWindow_drawRectangleShape(window, - ns[j][i], - NULL); + if (next.c[j][i]) { + sfRectangleShape_setFillColor(next.p[j][i], next.fColor); + sfRectangleShape_setOutlineColor(next.p[j][i], uiColor3); + sfRenderWindow_drawRectangleShape(window, next.p[j][i], NULL); } } void cleanupFld() { - for (int j = 0; j < fldSize.y; j++) - for(int i = 0; i < fldSize.x; i++) - sfRectangleShape_destroy(fld[j][i]); + for (int j = 0; j < fld.size.y; j++) + for(int i = 0; i < fld.size.x; i++) + sfRectangleShape_destroy(fld.p[j][i]); for (int j = 0; j < 4; j++) for(int i = 0; i < 4; i++) - sfRectangleShape_destroy(ns[j][i]); + sfRectangleShape_destroy(next.p[j][i]); } @@ -3,29 +3,16 @@ /* --- Variables --- */ int gameIsStarted = 0; -sfVideoMode mode = {450, 520, 32}; -sfRenderWindow* window; -sfEvent event; - -sfText *textMenu1; -sfVector2f textMenu1_pos; +Window w = {.mode = {450, 520, 32}}; +Text menu1; +Text menu2; +Text score; sfFont *fontScore; -sfText *textScore; -sfVector2f textScore_pos; -char *scoreDisp; -int scoreCurrent = 0; +Shape active, next; +Field fld; -sfRectangleShape* ns[4][4]; // Array of next shape image rectangles -sfRectangleShape* fld[25][10]; // Array of fld rectangles -sfVector2f fldCPos[25][10]; // Array of absolute coordinates of fld - // rectangles -sfRectangleShape* ns[4][4]; // Array of next shape image rectangles -sfVector2f nsCSize; // Next shape rectangles size variable x/y -int fldCOutThick = 1; // Field rectangles outline thickness -sfVector2f fldCSize; // Field rectangles size variable x/y -sfVector2i fldSize; -sfVector2f fldPos; +int scoreCurrent = 0; uint8_t arrKeys = 0b00000000; // Arrow keys states byte container @@ -52,64 +39,72 @@ void prepare() { * Dimensions of every fld's cell * 23px - fill color 1px - for outline, 25 - at all */ - fldCSize = (sfVector2f){.x = 23, .y = 23}; //Fld's cell size in pixels - fldPos = (sfVector2f){.x = 10, .y = 10+500-20}; // Fld bot left corner - fldSize = (sfVector2i){.x = 10, .y = 25}; // Field's size in blocks + fld.cSize = (sfVector2f){.x = 23, .y = 23}; //Fld's cell size in pixels + fld.cOutThick = 1; + fld.pos = (sfVector2i){.x = 10, .y = 10+500-24}; // Fld bot left corner + fld.size = (sfVector2i){.x = 10, .y = 25}; // Field's size in blocks - nsCSize = (sfVector2f){.x = 23, .y = 23}; - nxtShape = (struct shapeSt){.x = 250+10+20, .y = 200}; + next = (Shape){.x = 250+10+20, .y = 200, + .cSize = {.x = 23, .y = 23}}; initFld(); - textScore_pos = (sfVector2f){.x = 250+10+10, .y = 10}; - textScore = sfText_create(); - sfText_setFont(textScore, fontScore); - sfText_setCharacterSize(textScore, 20); - sfText_setPosition(textScore, textScore_pos); + score.pos = (sfVector2f){.x = 250+10+10, .y = 10}; + score.text = sfText_create(); + sfText_setFont(score.text, fontScore); + sfText_setCharacterSize(score.text, 20); + sfText_setPosition(score.text, score.pos); /* * Menu texts * */ - textMenu1_pos.x = 10+250+30; - textMenu1_pos.y = 100; - textMenu1 = sfText_create(); - sfText_setFont(textMenu1, fontScore); - sfText_setCharacterSize(textMenu1, 36); - sfText_setPosition(textMenu1, textMenu1_pos); - char b[7]; - sprintf(b, "TETRIS"); - sfText_setString(textMenu1, (char *)&b); - - window = sfRenderWindow_create(mode, + menu1.pos.x = 10+250+30; + menu1.pos.y = 100; + menu1.text = sfText_create(); + sfText_setFont(menu1.text, fontScore); + sfText_setCharacterSize(menu1.text, 36); + sfText_setPosition(menu1.text, menu1.pos); + sfText_setString(menu1.text, "TETRIS"); + + menu2.pos.x = 10+250+16; + menu2.pos.y = 200; + menu2.text = sfText_create(); + sfText_setFont(menu2.text, fontScore); + sfText_setCharacterSize(menu2.text, 20); + sfText_setPosition(menu2.text, menu2.pos); + sfText_setString(menu2.text, "Press \"S\" to start"); + + w.window = sfRenderWindow_create(w.mode, windowName_conf, sfResize | sfClose, NULL); - if (!window) + if (!w.window) exit(EXIT_FAILURE); } void handleWindowEvents() { - while (sfRenderWindow_pollEvent(window, &event)) - if (event.type == sfEvtClosed) - sfRenderWindow_close(window); + while (sfRenderWindow_pollEvent(w.window, &w.event)) + if (w.event.type == sfEvtClosed) + sfRenderWindow_close(w.window); } void gameLoop() { tTick(); tKeyCtrl(); - scoreDisplay(scoreCurrent, textScore); + scoreDisplay(scoreCurrent, &score); colorizeFld(); colorizeActiSh(); - drawFld(window); - drawNextShape(window); - sfRenderWindow_drawText(window, textScore, NULL); + drawFld(w.window); + drawNextShape(w.window); + sfRenderWindow_drawText(w.window, score.text, NULL); } void menuLoop() { menuTick(); - drawFld(window); - sfRenderWindow_drawText(window, textMenu1, NULL); + drawFld(w.window); + sfRenderWindow_drawText(w.window, menu1.text, NULL); + sfRenderWindow_drawText(w.window, menu2.text, NULL); if (sfKeyboard_isKeyPressed(sfKeyS) == 1) { gameIsStarted = 1; cleanupFld(); @@ -118,32 +113,29 @@ void menuLoop() { } void mainLoop() { - while (sfRenderWindow_isOpen(window)) { + while (sfRenderWindow_isOpen(w.window)) { handleWindowEvents(); - sfRenderWindow_clear(window, sfBlack); + sfRenderWindow_clear(w.window, sfBlack); if (gameIsStarted) { gameLoop(); } else { menuLoop(); } - sfRenderWindow_display(window); + sfRenderWindow_display(w.window); } } int main() { prepare(); - colorizeRandom(); mainLoop(); - /* Just senseless printf */ printf("%d\n", scoreCurrent); - cleanupFld(); - sfRenderWindow_destroy(window); - sfText_destroy(textScore); - sfText_destroy(textMenu1); + sfRenderWindow_destroy(w.window); + sfText_destroy(score.text); + sfText_destroy(menu1.text); return EXIT_SUCCESS; } |