From d3fddd7d28f314a6738f2a0ba4d9f58024b01984 Mon Sep 17 00:00:00 2001 From: Oxore Date: Thu, 12 Jul 2018 11:51:00 +0300 Subject: Introduce testing with munit, refactor Split unicode routines from text. Testing: add munit submodule, move translation units with main functions to separate folder, make corresponding changes in Makefile. Make simple test for unicode handling routine. Remove _vimrc_local. test.c: optimize includes. Add test run to .travis.yml. --- src/target/tetris.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/target/tetris.c (limited to 'src/target/tetris.c') diff --git a/src/target/tetris.c b/src/target/tetris.c new file mode 100644 index 0000000..2419c8d --- /dev/null +++ b/src/target/tetris.c @@ -0,0 +1,115 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" +#include "idlist.h" +#include "vector.h" +#include "text.h" +#include "field.h" +#include "painter.h" +#include "engine.h" +#include "tet_conf.h" + +sfRenderWindow *window; +struct idlist *texts; + +struct field fld, nxt; +struct game game = { + .started = 0, + .paused = 0, + .scoreCurrent = 0, + .level = 1, + .moveLatency = L00LATENCY, + .lines = 0 +}; + +static void handleWindowEvents() { + sfEvent event; + while (sfRenderWindow_pollEvent(window, &event)) + if (event.type == sfEvtClosed) + sfRenderWindow_close(window); +} + +static void register_text(void *obj) +{ + struct text *text = obj; + text->id = painter_register_text(text); +} + +int main() +{ + srand(time(NULL)); + game.gameTick = sfClock_create(); + game.putTick = sfClock_create(); + game.mTick = sfClock_create(); + game.repPushDown = sfClock_create(); + game.repKeyLeft = sfClock_create(); + game.repKeyRight = sfClock_create(); + painter_load_font("dat/arial.ttf"); + + sfVideoMode mode = (sfVideoMode){450, 570, 32}; + window = sfRenderWindow_create(mode, windowName_conf, sfResize | sfClose, NULL); + if (!window) + exit(EXIT_FAILURE); + sfRenderWindow_setFramerateLimit(window, 60); + painter_set_window(window); + + fld.pos = FLD_POS; + fld.size = (struct vector2ui){.x = FLD_SIZE_X, .y = FLD_SIZE_Y}; + fld.bound = (struct vector2ui){.x = FLD_BOUND_X, .y = FLD_BOUND_Y}; + fld.shape_cnt = 2; + field_init(&fld); + fld.shape[0].attr |= SHP_ATTR_GHOST; + + nxt.pos = NXT_POS; + nxt.size = NXT_SIZE; + nxt.bound = NXT_SIZE; + nxt.shape_cnt = 3; + nxt.attr |= FLD_ATTR_HIDE_EMPTY_CELLS | FLD_ATTR_INVISIBLE; + field_init(&nxt); + nxt.shape[0].y = 4; + nxt.shape[1].y = 1; + nxt.shape[2].y = -2; + + fld.id = painter_register_field(&fld); + nxt.id = painter_register_field(&nxt); + field_fill_random(&fld); + painter_update_field(fld.id, &fld); + painter_update_field(nxt.id, &nxt); + + texts = load_texts("dat/texts.yaml"); + + list_foreach(texts, register_text); + + transition_init(); + while (sfRenderWindow_isOpen(window)) { + handleWindowEvents(); + main_loop(); + } + + list_foreach(texts, text_destroy); + list_destroy(texts); + + painter_destroy_drawables(); + field_deinit(&fld); + field_deinit(&nxt); + + if (window) { + sfRenderWindow_destroy(window); + window = 0; + } + painter_destroy_font(); + sfClock_destroy(game.gameTick); + sfClock_destroy(game.putTick); + sfClock_destroy(game.mTick); + sfClock_destroy(game.repPushDown); + sfClock_destroy(game.repKeyLeft); + sfClock_destroy(game.repKeyRight); + return EXIT_SUCCESS; +} -- cgit v1.2.3