From 66783797c33d457e9d4d7ca669a6ad1fa3cf554c Mon Sep 17 00:00:00 2001 From: Oxore Date: Wed, 29 Nov 2017 02:14:29 +0300 Subject: Change coding style --- src/main.c | 194 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 97 insertions(+), 97 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 1736a49..dc3bfc0 100644 --- a/src/main.c +++ b/src/main.c @@ -16,14 +16,14 @@ sfVector2f textScore_pos; char *scoreDisp; int scoreCurrent = 0; -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 +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 +int fldCOutThick = 1; // Field rectangles outline thickness +sfVector2f fldCSize; // Field rectangles size variable x/y sfVector2i fldSize; sfVector2f fldPos; @@ -34,118 +34,118 @@ int lvlLatency = 500000; sfClock *gameTick; sfClock *mTick; -sfClock *repPushDown; // Clock for repeat latency when Down arrow long push -sfClock *repKeyLeft; // Clock for repeat latency when Left arrow long push -sfClock *repKeyRight; // Clock for repeat latency when Left arrow long push +sfClock *repPushDown; // Clock for repeat latency when Down arrow long push +sfClock *repKeyLeft; // Clock for repeat latency when Left arrow long push +sfClock *repKeyRight; // Clock for repeat latency when Left arrow long push void prepare() { - srand( time(NULL) ); - gameTick = sfClock_create(); - mTick = sfClock_create(); - fontScore = sfFont_createFromFile("dat/arial.ttf"); - if (!fontScore) { - printf("dat/arial.ttf font load failed"); - exit(-1); - } - - - 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); - - /* - * 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 - - nsCSize = (sfVector2f){.x = 23, .y = 23}; - nxtShape = (struct shapeSt){.x = 250+10+20, .y = 200}; - - initFld(); - - /* - * 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); + srand( time(NULL) ); + gameTick = sfClock_create(); + mTick = sfClock_create(); + fontScore = sfFont_createFromFile("dat/arial.ttf"); + if (!fontScore) { + printf("dat/arial.ttf font load failed"); + exit(-1); + } + + + 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); + + /* + * 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 + + nsCSize = (sfVector2f){.x = 23, .y = 23}; + nxtShape = (struct shapeSt){.x = 250+10+20, .y = 200}; + + initFld(); + + /* + * 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); } void handleWindowEvents() { - while (sfRenderWindow_pollEvent(window, &event)) - if (event.type == sfEvtClosed) - sfRenderWindow_close(window); + while (sfRenderWindow_pollEvent(window, &event)) + if (event.type == sfEvtClosed) + sfRenderWindow_close(window); } void gameLoop() { - tTick(); - tKeyCtrl(); - scoreDisplay(scoreCurrent, textScore); - colorizeFld(); - colorizeActiSh(); - drawFld(window); - drawNextShape(window); - sfRenderWindow_drawText(window, textScore, NULL); + tTick(); + tKeyCtrl(); + scoreDisplay(scoreCurrent, textScore); + colorizeFld(); + colorizeActiSh(); + drawFld(window); + drawNextShape(window); + sfRenderWindow_drawText(window, textScore, NULL); } void menuLoop() { - menuTick(); - drawFld(window); - sfRenderWindow_drawText(window, textMenu1, NULL); - if (sfKeyboard_isKeyPressed(sfKeyS) == 1) { - gameIsStarted = 1; - cleanup(); - initFld(); - } + menuTick(); + drawFld(window); + sfRenderWindow_drawText(window, textMenu1, NULL); + if (sfKeyboard_isKeyPressed(sfKeyS) == 1) { + gameIsStarted = 1; + cleanup(); + initFld(); + } } void mainLoop() { - while (sfRenderWindow_isOpen(window)) { - handleWindowEvents(); - sfRenderWindow_clear(window, sfBlack); - if (gameIsStarted) { - gameLoop(); - } else { - menuLoop(); - } - sfRenderWindow_display(window); - } + while (sfRenderWindow_isOpen(window)) { + handleWindowEvents(); + sfRenderWindow_clear(window, sfBlack); + if (gameIsStarted) { + gameLoop(); + } else { + menuLoop(); + } + sfRenderWindow_display(window); + } } int main() { - prepare(); - window = sfRenderWindow_create(mode, - windowName_conf, - sfResize | sfClose, - NULL); - if (!window) - return EXIT_FAILURE; + prepare(); + window = sfRenderWindow_create(mode, + windowName_conf, + sfResize | sfClose, + NULL); + if (!window) + return EXIT_FAILURE; - /* colorize field once at start */ - colorizeRandom(); + /* colorize field once at start */ + colorizeRandom(); - mainLoop(); + mainLoop(); - /* Just senseless printf */ - printf("%d\n", scoreCurrent); + /* Just senseless printf */ + printf("%d\n", scoreCurrent); - cleanup(); - sfRenderWindow_destroy(window); - sfText_destroy(textScore); - sfText_destroy(textMenu1); + cleanup(); + sfRenderWindow_destroy(window); + sfText_destroy(textScore); + sfText_destroy(textMenu1); - return EXIT_SUCCESS; + return EXIT_SUCCESS; } -- cgit v1.2.3