summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/engine.c60
-rw-r--r--src/painter.c24
-rw-r--r--src/target/test.c11
-rw-r--r--src/text.c13
-rw-r--r--src/unicode.c6
5 files changed, 72 insertions, 42 deletions
diff --git a/src/engine.c b/src/engine.c
index 41bdc4a..2a5755b 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -267,7 +267,8 @@ static void transition_game_over()
list_foreach(texts, update_game_over_text);
}
-static void project_ghost_shape(struct field *fld, size_t idreal, size_t idghost)
+static void project_ghost_shape(struct field *fld, size_t idreal,
+ size_t idghost)
{
fld->shape[idghost].t = fld->shape[idreal].t;
fld->shape[idghost].x = fld->shape[idreal].x;
@@ -398,11 +399,11 @@ static void game_keys()
/* PAUSE */
if (sfKeyboard_isKeyPressed(sfKeyP)) {
if (!(keys & PAUSE)) {
- keys = keys | PAUSE;
+ keys |= PAUSE;
signal_pause();
}
} else {
- keys = keys & ~PAUSE;
+ keys &= ~PAUSE;
}
/* UP */
@@ -418,11 +419,11 @@ static void game_keys()
/* HARDDROP */
if (sfKeyboard_isKeyPressed(sfKeySpace)) {
if (!(keys & HARDDROP)) {
- keys = keys | HARDDROP;
+ keys |= HARDDROP;
signal_harddrop();
}
} else {
- keys = keys & ~HARDDROP;
+ keys &= ~HARDDROP;
}
/* DOWN */
@@ -432,51 +433,58 @@ static void game_keys()
signal_down();
sfClock_restart(game.repPushDown);
} else {
- if (sfClock_getElapsedTime(game.repPushDown).microseconds >= moveRepeatLatency2)
- keys = keys & ~DOWN;
+ if (sfClock_getElapsedTime(game.repPushDown).microseconds
+ >= moveRepeatLatency2)
+ keys &= ~DOWN;
}
} else {
- keys = keys & ~DOWN;
+ keys &= ~DOWN;
}
/* LEFT */
- if (sfKeyboard_isKeyPressed(sfKeyLeft) && !sfKeyboard_isKeyPressed(sfKeyRight)) {
+ if (sfKeyboard_isKeyPressed(sfKeyLeft)
+ && !sfKeyboard_isKeyPressed(sfKeyRight)) {
if (!(keys & LEFT)) {
keys = keys | LEFT;
signal_left();
sfClock_restart(game.repKeyLeft);
} else if (!(keys & LEFTHOLD)) {
- if (sfClock_getElapsedTime(game.repKeyLeft).microseconds >= moveRepeatLatency1) {
- keys = keys | LEFTHOLD;
- keys = keys & ~LEFT;
+ if (sfClock_getElapsedTime(game.repKeyLeft).microseconds
+ >= moveRepeatLatency1) {
+ keys |= LEFTHOLD;
+ keys &= ~LEFT;
}
} else {
- if (sfClock_getElapsedTime(game.repKeyLeft).microseconds >= moveRepeatLatency2)
- keys = keys & ~LEFT;
+ if (sfClock_getElapsedTime(game.repKeyLeft).microseconds
+ >= moveRepeatLatency2)
+ keys &= ~LEFT;
}
} else {
- keys = keys & ~LEFT;
- keys = keys & ~LEFTHOLD;
+ keys &= ~LEFT;
+ keys &= ~LEFTHOLD;
}
/* RIGHT */
- if (sfKeyboard_isKeyPressed(sfKeyRight) && !sfKeyboard_isKeyPressed(sfKeyLeft)) {
+ if (sfKeyboard_isKeyPressed(sfKeyRight)
+ && !sfKeyboard_isKeyPressed(sfKeyLeft)) {
if (!(keys & RIGHT)) {
keys = keys | RIGHT;
signal_right();
sfClock_restart(game.repKeyRight);
} else if (!(keys & RIGHTHOLD)) {
- if (sfClock_getElapsedTime(game.repKeyRight).microseconds >= moveRepeatLatency1) {
- keys = keys | RIGHTHOLD;
- keys = keys & ~RIGHT;
+ if (sfClock_getElapsedTime(game.repKeyRight).microseconds
+ >= moveRepeatLatency1) {
+ keys |= RIGHTHOLD;
+ keys &= ~RIGHT;
}
} else {
- if (sfClock_getElapsedTime(game.repKeyRight).microseconds >= moveRepeatLatency2)
- keys = keys & ~RIGHT;
+ if (sfClock_getElapsedTime(game.repKeyRight).microseconds
+ >= moveRepeatLatency2)
+ keys &= ~RIGHT;
}
} else {
- keys = keys & ~RIGHT;
- keys = keys & ~RIGHTHOLD;
+ keys &= ~RIGHT;
+ keys &= ~RIGHTHOLD;
}
}
@@ -485,11 +493,11 @@ static void pause_keys()
/* PAUSE */
if (sfKeyboard_isKeyPressed(sfKeyP)) {
if (!(keys & PAUSE)) {
- keys = keys | PAUSE;
+ keys |= PAUSE;
signal_pause();
}
} else {
- keys = keys & ~PAUSE;
+ keys &= ~PAUSE;
}
}
diff --git a/src/painter.c b/src/painter.c
index dea9b69..a9029b1 100644
--- a/src/painter.c
+++ b/src/painter.c
@@ -95,7 +95,8 @@ size_t painter_register_field(struct field *fld)
sfRectangleShape_setPosition(f->p[j][i], cell_pos);
sfRectangleShape_setFillColor(f->p[j][i], (sfColor)UIBGCOLOR);
sfRectangleShape_setSize(f->p[j][i], CELL_SIZE);
- sfRectangleShape_setOutlineColor(f->p[j][i], (sfColor)UIFGACTIVECOLOR);
+ sfRectangleShape_setOutlineColor(f->p[j][i],
+ (sfColor)UIFGACTIVECOLOR);
sfRectangleShape_setOutlineThickness(f->p[j][i], OUT_THICK);
}
}
@@ -118,27 +119,36 @@ void painter_update_field(size_t id, struct field *fld)
cell_pos.y = fld->pos.y - (j * (CELL_SIZE.y + 2 * OUT_THICK));
sfRectangleShape_setPosition(f->p[j][i], cell_pos);
if (fld->c[j][i].a) {
- sfRectangleShape_setFillColor(f->p[j][i], shape_color_map[fld->c[j][i].color]);
- sfRectangleShape_setOutlineColor(f->p[j][i], (sfColor)UIFGACTIVECOLOR);
+ sfRectangleShape_setFillColor(f->p[j][i],
+ shape_color_map[fld->c[j][i].color]);
+ sfRectangleShape_setOutlineColor(f->p[j][i],
+ (sfColor)UIFGACTIVECOLOR);
} else if (f->attr & FLD_ATTR_HIDE_EMPTY_CELLS) {
- sfRectangleShape_setFillColor(f->p[j][i], (sfColor)UITRANSPARENT);
- sfRectangleShape_setOutlineColor(f->p[j][i], (sfColor)UITRANSPARENT);
+ sfRectangleShape_setFillColor(f->p[j][i],
+ (sfColor)UITRANSPARENT);
+ sfRectangleShape_setOutlineColor(f->p[j][i],
+ (sfColor)UITRANSPARENT);
} else {
sfRectangleShape_setFillColor(f->p[j][i], (sfColor)UIBGCOLOR);
- sfRectangleShape_setOutlineColor(f->p[j][i], (sfColor)UIFGINACTIVECOLOR);
+ sfRectangleShape_setOutlineColor(f->p[j][i],
+ (sfColor)UIFGINACTIVECOLOR);
}
}
}
+
for (size_t s = 0; s < fld->shape_cnt; ++s) {
sfColor fill_color = shape_color_map[fld->shape[s].t];
sfColor outline_color = (sfColor)UIFGACTIVECOLOR;
+
if (fld->shape[s].attr && SHP_ATTR_GHOST) {
fill_color.a = 100;
outline_color.a = 100;
}
+
for (int j = 0; j < 4; j++)
for (int i = 0; i < 4; i++)
- if (fld->shape[s].c[j][i] && j + fld->shape[s].y < (int)fld->size.y) {
+ if (fld->shape[s].c[j][i] && j + fld->shape[s].y
+ < (int)fld->size.y) {
sfRectangleShape_setFillColor(
f->p[j + fld->shape[s].y][i + fld->shape[s].x],
fill_color);
diff --git a/src/target/test.c b/src/target/test.c
index 0959eaa..e250954 100644
--- a/src/target/test.c
+++ b/src/target/test.c
@@ -27,14 +27,18 @@ struct u_pair text_fixture[] = {
};
-static void *test_utf8_strlen_setup(const MunitParameter params[], void *user_data) {
+static void *test_utf8_strlen_setup(const MunitParameter params[],
+ void *user_data)
+{
(void) params;
(void) user_data;
return text_fixture;
}
-static MunitResult test_utf8_strlen(const MunitParameter params[], void *fixture) {
+static MunitResult test_utf8_strlen(const MunitParameter params[],
+ void *fixture)
+{
(void) params;
struct u_pair *f = fixture;
@@ -64,6 +68,7 @@ static const MunitSuite test_suite = {
MUNIT_SUITE_OPTION_NONE
};
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
return munit_suite_main(&test_suite, NULL, argc, argv);
}
diff --git a/src/text.c b/src/text.c
index a879d51..3b361dd 100644
--- a/src/text.c
+++ b/src/text.c
@@ -56,16 +56,21 @@ struct idlist *load_texts(char *filename)
}
struct text *text = texts_node->obj;
if (!strcmp((char *)event.data.scalar.value, "type")) {
- text->type = malloc(sizeof(char) * (strlen((char *)ev.data.scalar.value) + 1));
+ text->type = malloc(sizeof(char)
+ * (strlen((char *)ev.data.scalar.value) + 1));
strcpy(text->type, (char *)ev.data.scalar.value);
} else if (!strcmp((char *)event.data.scalar.value, "scene")) {
- text->scene = malloc(sizeof(char) * (strlen((char *)ev.data.scalar.value) + 1));
+ text->scene = malloc(sizeof(char)
+ * (strlen((char *)ev.data.scalar.value) + 1));
strcpy(text->scene, (char *)ev.data.scalar.value);
} else if (!strcmp((char *)event.data.scalar.value, "text")) {
- text->text = calloc((utf8_strlen((char *)ev.data.scalar.value)) + 1, sizeof(size_t));
+ text->text
+ = calloc((utf8_strlen((char *)ev.data.scalar.value)) + 1,
+ sizeof(size_t));
utf8to32_strcpy(text->text, (char *)ev.data.scalar.value);
} else if (!strcmp((char *)event.data.scalar.value, "font")) {
- text->font = malloc(sizeof(char) * (strlen((char *)ev.data.scalar.value) + 1));
+ text->font = malloc(sizeof(char)
+ * (strlen((char *)ev.data.scalar.value) + 1));
strcpy(text->font, (char *)ev.data.scalar.value);
} else if (!strcmp((char *)event.data.scalar.value, "size")) {
text->size = atoi((char *)ev.data.scalar.value);
diff --git a/src/unicode.c b/src/unicode.c
index 8e4309d..de25ffb 100644
--- a/src/unicode.c
+++ b/src/unicode.c
@@ -38,9 +38,11 @@ void utf8to32_strcpy(wchar_t *dest, char *src)
} else if (clen == 2) {
dc[len] = ((c[0] & 0x1f) << 6) | ((c[1] & 0x3f) << 0);
} else if (clen == 3) {
- dc[len] = ((c[0] & 0x0f) << 12) | ((c[1] & 0x3f) << 6) | ((c[2] & 0x3f) << 0);
+ dc[len] = ((c[0] & 0x0f) << 12) | ((c[1] & 0x3f) << 6)
+ | ((c[2] & 0x3f) << 0);
} else if (clen == 4) {
- dc[len] = ((c[0] & 0x07) << 18) | ((c[1] & 0x3f) << 12) | ((c[2] & 0x3f) << 6) | ((c[3] & 0x3f) << 0);
+ dc[len] = ((c[0] & 0x07) << 18) | ((c[1] & 0x3f) << 12)
+ | ((c[2] & 0x3f) << 6) | ((c[3] & 0x3f) << 0);
} else {
dc[len] = 0;
return;