diff options
author | Oxore <oxore@protonmail.com> | 2017-06-23 02:29:02 +0700 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2017-06-23 02:29:02 +0700 |
commit | 07b648f53d3d0dfd92d124df0f9967ffafc641a9 (patch) | |
tree | 380d4717400a651cfc6d3e5a5f8fed0461b9d905 /src | |
parent | 5da375c829d2bc5afdfd98c898339fb90175032f (diff) |
Code style refactoring
Diffstat (limited to 'src')
-rw-r--r-- | src/functions.c | 72 | ||||
-rw-r--r-- | src/include/tet_conf.h | 6 |
2 files changed, 42 insertions, 36 deletions
diff --git a/src/functions.c b/src/functions.c index ed2e3d5..c50abde 100644 --- a/src/functions.c +++ b/src/functions.c @@ -3,20 +3,20 @@ /* Externs from main.c */ -extern sfRectangleShape *fld[25][10]; // Array of field rectangles -extern sfVector2f fldCPos[25][10]; // Array of absolute coordinates of field rectangles +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 sfVector2i fldPos; -extern sfVector2f fldCSize; // Field rectangles size variable x/y -extern int fldCOutThick; // Field rectangles outline thickness +extern sfVector2f fldCSize; // Field rectangles size variable x/y +extern int fldCOutThick; // Field rectangles outline thickness extern sfVector2f textScore_pos; extern sfText *textScore; extern sfFont *fontScore; extern int gameIsStarted; -extern uint8_t arrKeys; // arrow keys states byte container -/* arrKeys = ...n|7|6|5|4|3|2|1|0| (just a little bit of such called "bit fucking") +extern uint8_t arrKeys; // Arrow keys states byte container +/* arrKeys = ...n|7|6|5|4|3|2|1|0| (just a bit of "bit fucking") * 0 - Right arrow pushed and held * 1 - Down arrow pushed and held * 2 - N/A @@ -405,23 +405,23 @@ int wallCollisionCheck(int dir) void tKeyCtrl() { /* Up arrow key 'hold' handler */ - if (sfKeyboard_isKeyPressed(sfKeyUp) == 1) { - if ((arrKeys & 0b0100) == 0) { + if (sfKeyboard_isKeyPressed(sfKeyUp)) { + if (!(arrKeys & 0b0100)) { arrKeys = arrKeys | 0b0100; rotateShape(); } } else { - if ((arrKeys & 0b0100) != 0) { + if ((arrKeys & 0b0100)) { arrKeys = arrKeys & ~0b0100; } } /* Down Arrow Key 'hold' handler */ - if (sfKeyboard_isKeyPressed(sfKeyDown) == 1) { - if ((arrKeys & 0b0010) == 0) { + if (sfKeyboard_isKeyPressed(sfKeyDown)) { + if (!(arrKeys & 0b0010)) { arrKeys = arrKeys | 0b0010; - if ((wallCollisionCheck(0b0010) == 0) - && (cellCollisionCheck(0b0010) == 0)) { + if (!wallCollisionCheck(0b0010) + && !cellCollisionCheck(0b0010)) { actiSh.y--; // Avoid excess move down by gameTick sfClock_restart(gameTick); @@ -434,65 +434,69 @@ void tKeyCtrl() arrKeys = arrKeys & ~0b0010; } } else { - if ((arrKeys & 0b0010) != 0) { + if ((arrKeys & 0b0010)) { arrKeys = arrKeys & ~0b0010; arrKeys = arrKeys & ~0b100000; } } /* Left Arrow Key 'hold' handler */ - if ((sfKeyboard_isKeyPressed(sfKeyLeft) == 1) - && (sfKeyboard_isKeyPressed(sfKeyRight) == 0)) { - if ((arrKeys & 0b1000) == 0){ + if (sfKeyboard_isKeyPressed(sfKeyLeft) + && !sfKeyboard_isKeyPressed(sfKeyRight)) { + if (!(arrKeys & 0b1000)) { arrKeys = arrKeys | 0b1000; - if ((wallCollisionCheck(0b1000) == 0) - && (cellCollisionCheck(0b1000) == 0)) + if (!wallCollisionCheck(0b1000) + && !cellCollisionCheck(0b1000)) actiSh.x--; repKeyLeft = sfClock_create(); } else { - if ((arrKeys & 0b10000000) == 0) { - if (sfClock_getElapsedTime(repKeyLeft).microseconds + if (!(arrKeys & 0b10000000)) { + if (sfClock_getElapsedTime(repKeyLeft) + .microseconds >= moveRepeatLatency1) { arrKeys = arrKeys | 0b10000000; arrKeys = arrKeys & ~0b1000; } } else { - if (sfClock_getElapsedTime(repKeyLeft).microseconds + if (sfClock_getElapsedTime(repKeyLeft) + .microseconds >= moveRepeatLatency2) arrKeys = arrKeys & ~0b1000; } } - } else if (sfKeyboard_isKeyPressed(sfKeyLeft) == 0) { - if ((arrKeys & 0b1000) != 0){ + } else if (!sfKeyboard_isKeyPressed(sfKeyLeft)) { + if ((arrKeys & 0b1000)){ arrKeys = arrKeys & ~0b1000; arrKeys = arrKeys & ~0b10000000; } } /* Right Arrow Key 'hold' handler */ - if ((sfKeyboard_isKeyPressed(sfKeyRight) == 1) - && (sfKeyboard_isKeyPressed(sfKeyLeft) == 0)) { - if ((arrKeys & 0b0001) == 0){ + if (sfKeyboard_isKeyPressed(sfKeyRight) + && !sfKeyboard_isKeyPressed(sfKeyLeft)) { + if (!(arrKeys & 0b0001)){ arrKeys = arrKeys | 0b0001; - if ((wallCollisionCheck(0b0001) == 0) - && (cellCollisionCheck(0b0001) == 0)) + if (!wallCollisionCheck(0b0001) + && !cellCollisionCheck(0b0001)) actiSh.x++; repKeyRight = sfClock_create(); } else { - if ((arrKeys & 0b10000) == 0) { - if (sfClock_getElapsedTime(repKeyRight).microseconds + if (!(arrKeys & 0b10000)) { + if (sfClock_getElapsedTime(repKeyRight) + .microseconds >= moveRepeatLatency1) { arrKeys = arrKeys | 0b10000; arrKeys = arrKeys & ~0b0001; } - } else if (sfKeyboard_isKeyPressed(sfKeyLeft) == 0) { - if (sfClock_getElapsedTime(repKeyRight).microseconds + } else if (!sfKeyboard_isKeyPressed(sfKeyLeft)) { + if (sfClock_getElapsedTime(repKeyRight) + .microseconds >= moveRepeatLatency2) // Wait short time arrKeys = arrKeys & ~0b0001; } } } else { - if ((arrKeys & 0b0001) != 0) { + if ((arrKeys & 0b0001)) { arrKeys = arrKeys & ~0b0001; arrKeys = arrKeys & ~0b10000; } diff --git a/src/include/tet_conf.h b/src/include/tet_conf.h index 6e113b8..eba92e5 100644 --- a/src/include/tet_conf.h +++ b/src/include/tet_conf.h @@ -9,8 +9,10 @@ #define tYellow sfColor_fromRGB(255, 255, 0) #define tCyan sfColor_fromRGB(0, 255, 255) #define tMagneta sfColor_fromRGB(192, 0, 255) -#define moveRepeatLatency1 150000 //microseconds, only for left-right arrows, first repeat move when long push -#define moveRepeatLatency2 30000 //microseconds, for Left, Right and Down arrows, the rest repeat move when long push +#define moveRepeatLatency1 150000 // microseconds, only for left-right arrows, + // first repeat move when long push +#define moveRepeatLatency2 30000 // microseconds, for Left, Right and Down + // arrows, the rest repeat move when long push /* |