summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2017-12-02 12:23:01 +0300
committerOxore <oxore@protonmail.com>2017-12-02 12:23:01 +0300
commite600f2e2703108152bac81fcebca1dfc92488295 (patch)
tree570c09537e3abec6a8a5198c5035d62cd55cc127
parent194112490cf58dc5fe9c0ca0488d4964faa9f2a3 (diff)
Add PUT_LATENCY threshold and some fixes
-rw-r--r--include/tet_conf.h3
-rw-r--r--src/functions.c29
-rw-r--r--src/main.c2
3 files changed, 25 insertions, 9 deletions
diff --git a/include/tet_conf.h b/include/tet_conf.h
index a5f4957..7b0574c 100644
--- a/include/tet_conf.h
+++ b/include/tet_conf.h
@@ -14,6 +14,9 @@
#define moveRepeatLatency2 30000 // microseconds, for Left, Right and Down
// arrows, the rest repeat move when long push
#define basicLatency 500000
+#define PUT_LATENCY 300000
+#define RM_LINE_SCORE 100
+#define LEVELUP_SCORE 100
/*
diff --git a/src/functions.c b/src/functions.c
index 482a459..7637289 100644
--- a/src/functions.c
+++ b/src/functions.c
@@ -21,6 +21,7 @@ extern uint8_t arrKeys; // Arrow keys states byte container
*/
extern sfClock *gameTick;
+extern sfClock *putTick;
extern sfClock *mTick;
extern sfClock *repPushDown; // Clock for repeat latency when Down arrow long push
extern sfClock *repKeyLeft; // Clock for repeat latency when Left arrow long push
@@ -143,7 +144,7 @@ void putShape()
if ((j+active.y >= 0) && (i+active.x >= 0))
fld.c[j+active.y][i+active.x].fColor = active.fColor;
}
- game.scoreCurrent += linesRmScore()*100; // Remove filled lines and get score;
+ game.scoreCurrent += linesRmScore()*RM_LINE_SCORE; // Remove filled lines and get score;
for (int i = 0; i < 10; i++)
if (fld.c[20][i].a) {
gameover(&game);
@@ -155,8 +156,8 @@ void putShape()
void checkLevelUp(Game *game)
{
- if (game->level <= 15)
- if (game->scoreCurrent >= game->level * 100)
+ if (game->level < 15)
+ if (game->scoreCurrent >= game->level * LEVELUP_SCORE)
game->level++;
}
@@ -186,13 +187,18 @@ void tTick()
if (sfClock_getElapsedTime(gameTick).microseconds
>= moveRepeatLatency2*(16-game.level)
&& game.level <= 15) {
- sfClock_restart(gameTick); // Restart gameTick
+ sfClock_restart(gameTick);
/* if bottom not reached */
if ((wallCollisionCheck(0b0010) == 0)
- && (cellCollisionCheck(0b0010) == 0))
+ && (cellCollisionCheck(0b0010) == 0)) {
active.y--; // Move
- else
- putShape(); // Just put the shape
+ sfClock_restart(putTick);
+ } else {
+ if (sfClock_getElapsedTime(putTick).microseconds >= PUT_LATENCY) {
+ putShape(); // Just put the shape
+ sfClock_restart(putTick);
+ }
+ }
}
}
@@ -356,6 +362,7 @@ void tKeyCtrl()
&& !cellCollisionCheck(0b0010)) {
active.y--;
// Avoid excess move down by gameTick
+ sfClock_restart(putTick);
sfClock_restart(gameTick);
game.scoreCurrent++;
}
@@ -378,8 +385,10 @@ void tKeyCtrl()
if (!(arrKeys & 0b1000)) {
arrKeys = arrKeys | 0b1000;
if (!wallCollisionCheck(0b1000)
- && !cellCollisionCheck(0b1000))
+ && !cellCollisionCheck(0b1000)) {
active.x--;
+ sfClock_restart(putTick);
+ }
repKeyLeft = sfClock_create();
} else {
if (!(arrKeys & 0b10000000)) {
@@ -409,8 +418,10 @@ void tKeyCtrl()
if (!(arrKeys & 0b0001)){
arrKeys = arrKeys | 0b0001;
if (!wallCollisionCheck(0b0001)
- && !cellCollisionCheck(0b0001))
+ && !cellCollisionCheck(0b0001)) {
active.x++;
+ sfClock_restart(putTick);
+ }
repKeyRight = sfClock_create();
} else {
if (!(arrKeys & 0b10000)) {
diff --git a/src/main.c b/src/main.c
index 731aa86..a4a8863 100644
--- a/src/main.c
+++ b/src/main.c
@@ -14,6 +14,7 @@ uint8_t arrKeys = 0b00000000; // Arrow keys states byte container
/* --- Variables End --- */
sfClock *gameTick;
+sfClock *putTick;
sfClock *mTick;
sfClock *repPushDown; // Clock for repeat latency when Down arrow long push
sfClock *repKeyLeft; // Clock for repeat latency when Left arrow long push
@@ -22,6 +23,7 @@ sfClock *repKeyRight; // Clock for repeat latency when Left arrow long push
void prepare() {
srand( time(NULL) );
gameTick = sfClock_create();
+ putTick = sfClock_create();
mTick = sfClock_create();
fontScore = sfFont_createFromFile("dat/arial.ttf");
if (!fontScore) {