summaryrefslogtreecommitdiff
path: root/src/target
diff options
context:
space:
mode:
Diffstat (limited to 'src/target')
-rw-r--r--src/target/test.c57
-rw-r--r--src/target/tetris.c115
2 files changed, 172 insertions, 0 deletions
diff --git a/src/target/test.c b/src/target/test.c
new file mode 100644
index 0000000..60439a5
--- /dev/null
+++ b/src/target/test.c
@@ -0,0 +1,57 @@
+#include "munit.h"
+
+#include "unicode.h"
+
+struct u_pair {
+ char *utf8;
+ wchar_t *utf32;
+};
+
+struct u_pair *text_fixture;
+
+static void *test_text_setup(const MunitParameter params[], void *user_data) {
+ (void) params;
+ (void) user_data;
+
+ return text_fixture;
+}
+
+static MunitResult test_text(const MunitParameter params[], void *fixture) {
+ (void) params;
+ struct u_pair *f = fixture;
+
+ munit_assert_ulong(utf8_strlen(f[0].utf8), ==, strlen(f[0].utf8));
+
+ return MUNIT_OK;
+}
+
+static MunitTest test_suite_tests[] = {
+ {
+ "/example/parameters",
+ test_text,
+ test_text_setup,
+ NULL,
+ MUNIT_TEST_OPTION_NONE,
+ NULL
+ },
+ {NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}
+};
+
+static const MunitSuite test_suite = {
+ "unit",
+ test_suite_tests,
+ NULL,
+ 1,
+ MUNIT_SUITE_OPTION_NONE
+};
+
+int main(int argc, char **argv) {
+ text_fixture = (struct u_pair []){
+ {
+ .utf8 = "Single byte ascii symbols string",
+ .utf32 = L"Single byte ascii symbols string"
+ }
+ };
+
+ return munit_suite_main(&test_suite, NULL, argc, argv);
+}
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 <SFML/System/Clock.h>
+#include <SFML/Window/Keyboard.h>
+#include <SFML/Graphics/RenderWindow.h>
+#include <SFML/Graphics/Font.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#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;
+}