summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2017-12-01 07:25:32 +0300
committerOxore <oxore@protonmail.com>2017-12-01 07:25:32 +0300
commitcd92a5171dd67b795a6fed4c2e635aed8262a876 (patch)
treebee6d7275ab7a1d927e4e08052b0f59d7af5e9fc /src/main.c
parentcd02c513c69bd25d1dc214b60048ef85c9bd6917 (diff)
More structure wrapping, more refactoring
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/main.c b/src/main.c
index 43b5a40..6464e8e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2,9 +2,8 @@
#include "functions.h"
/* --- Variables --- */
-int gameIsStarted = 0;
Window w = {.mode = {450, 520, 32}};
-
+Game game = {.isStarted = 0, .scoreCurrent = 0, .level = 1};
Text menu1;
Text menu2;
Text score;
@@ -12,11 +11,7 @@ sfFont *fontScore;
Shape active, next;
Field fld;
-int scoreCurrent = 0;
-
uint8_t arrKeys = 0b00000000; // Arrow keys states byte container
-
-int lvlLatency = 500000;
/* --- Variables End --- */
sfClock *gameTick;
@@ -92,22 +87,30 @@ void handleWindowEvents() {
void gameLoop() {
tTick();
tKeyCtrl();
- scoreDisplay(scoreCurrent, &score);
+ scoreDisplay(game.scoreCurrent, &score);
colorizeFld();
- colorizeActiSh();
+ colorizeActive();
drawFld(w.window);
drawNextShape(w.window);
sfRenderWindow_drawText(w.window, score.text, NULL);
}
+void menuTick()
+{
+ if(sfClock_getElapsedTime(mTick).microseconds >= basicLatency/game.level) {
+ sfClock_restart(mTick);
+ colorizeRandom(&fld);
+ }
+}
+
void menuLoop() {
menuTick();
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();
+ game.isStarted = 1;
+ freeFld();
initFld();
}
}
@@ -116,7 +119,7 @@ void mainLoop() {
while (sfRenderWindow_isOpen(w.window)) {
handleWindowEvents();
sfRenderWindow_clear(w.window, sfBlack);
- if (gameIsStarted) {
+ if (game.isStarted) {
gameLoop();
} else {
menuLoop();
@@ -128,14 +131,15 @@ void mainLoop() {
int main()
{
prepare();
- colorizeRandom();
+ colorizeRandom(&fld);
mainLoop();
/* Just senseless printf */
- printf("%d\n", scoreCurrent);
- cleanupFld();
+ printf("%d\n", game.scoreCurrent);
+ freeFld();
sfRenderWindow_destroy(w.window);
sfText_destroy(score.text);
sfText_destroy(menu1.text);
+ sfText_destroy(menu2.text);
return EXIT_SUCCESS;
}