diff options
author | Oxore <oxore@protonmail.com> | 2017-12-02 11:25:50 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2017-12-02 11:25:50 +0300 |
commit | 194112490cf58dc5fe9c0ca0488d4964faa9f2a3 (patch) | |
tree | 156737a02b21c374e0834521abee2bb28a1b4edc /src/main.c | |
parent | 8e04f42ee02852b72fcafb6af8598c12aacd39ec (diff) |
Make all text resources load from yaml file
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 39 |
1 files changed, 12 insertions, 27 deletions
@@ -6,8 +6,6 @@ Window w = {.mode = {450, 520, 32}}; Game game = {.isStarted = 0, .scoreCurrent = 0, .level = 1}; List *texts; -Text score; -Text level; sfFont *fontScore; Shape active, next; Field fld; @@ -44,18 +42,7 @@ void prepare() { .cSize = {.x = 23, .y = 23}}; initFld(); - texts = ListOfText_getFromListOfKeyMapOfString(ListOfKeyMapOfString_getFromYaml("dat/ya.yaml")); - score.sfText = sfText_create(); - sfText_setFont(score.sfText, fontScore); - sfText_setCharacterSize(score.sfText, 20); - sfText_setPosition(score.sfText, (sfVector2f){.x = 250+10+10, .y = 10}); - - level.sfText = sfText_create(); - sfText_setFont(level.sfText, fontScore); - sfText_setCharacterSize(level.sfText, 20); - sfText_setPosition(level.sfText, (sfVector2f){.x = 250+10+10, .y = 44}); - w.window = sfRenderWindow_create(w.mode, windowName_conf, sfResize | sfClose, @@ -70,17 +57,25 @@ void handleWindowEvents() { sfRenderWindow_close(w.window); } +void drawTextsAtScene(List *texts, char *scene, sfRenderWindow *window) { + List *t = texts; + while (t) { + if (!strcmp(((Text *)t->obj)->scene, scene)) + sfRenderWindow_drawText(window, ((Text *)t->obj)->sfText, NULL); + t = t->next; + } +} + void gameLoop() { tTick(); tKeyCtrl(); - scoreDisplay(game.scoreCurrent, &score); - levelDisplay(game.level, &level); + valueAfterTextDisplay(game.scoreCurrent, texts, "score"); + valueAfterTextDisplay(game.level, texts, "level"); colorizeFld(); colorizeActive(); drawFld(w.window); drawNextShape(w.window); - sfRenderWindow_drawText(w.window, score.sfText, NULL); - sfRenderWindow_drawText(w.window, level.sfText, NULL); + drawTextsAtScene(texts, "game", w.window); } void menuTick() @@ -91,15 +86,6 @@ void menuTick() } } -void drawTextsAtScene(List *texts, char *scene, sfRenderWindow *window) { - List *t = texts; - while (t) { - if (!strcmp(((Text *)t->obj)->scene, scene)) - sfRenderWindow_drawText(window, ((Text *)t->obj)->sfText, NULL); - t = t->next; - } -} - void menuLoop() { menuTick(); drawFld(w.window); @@ -133,7 +119,6 @@ int main() printf("%d\n", game.scoreCurrent); freeFld(); sfRenderWindow_destroy(w.window); - sfText_destroy(score.sfText); ListOfText_free(&texts); return EXIT_SUCCESS; |