чување 41ca502c174e8892c40c352d4c739765428f208e
родитељ 3e11322bf6e287e164d99b4050c14f850f9ef34e
Аутор: Страхиња Радић <sr@strahinja.org>
Датум: Tue, 25 Aug 2026 16:32:41 +0000
linije.c(get_sprite_xy): Use data structure for sprite positions
Diffstat:
| M | linije.c | | | 44 | ++++++++++++-------------------------------- |
измењених датотека: 1, додавања: 12(+), брисања: 32(-)
diff --git a/linije.c b/linije.c
@@ -120,6 +120,16 @@ const int check_five_deltas[][4] = {
{ -1, 0, 1, 0 },
};
+const SDL_Point sprite_positions[] = {
+ [CELL_EMPTY] = { .x = 0, .y = 0 },
+ [CELL_RED] = { .x = 1 * CELL_SIZE, .y = 0 },
+ [CELL_BLUE] = { .x = 2 * CELL_SIZE, .y = 0 },
+ [CELL_GREEN] = { .x = 3 * CELL_SIZE, .y = 0 },
+ [CELL_PURPLE] = { .x = 4 * CELL_SIZE, .y = 0 },
+ [CELL_ORANGE] = { .x = 5 * CELL_SIZE, .y = 0 },
+ [CELL_SELECTED] = { .x = 0, .y = 1 * CELL_SIZE },
+};
+
const char* state_descriptions[] = {
"Idle",
"Selecting",
@@ -746,38 +756,8 @@ void
get_sprite_xy(const char cell, float* x, float* y)
{
assert((x != NULL) && (y != NULL));
- switch (cell)
- {
- case CELL_RED:
- *x = 1 * CELL_SIZE;
- *y = 0;
- break;
- case CELL_BLUE:
- *x = 2 * CELL_SIZE;
- *y = 0;
- break;
- case CELL_GREEN:
- *x = 3 * CELL_SIZE;
- *y = 0;
- break;
- case CELL_PURPLE:
- *x = 4 * CELL_SIZE;
- *y = 0;
- break;
- case CELL_ORANGE:
- *x = 5 * CELL_SIZE;
- *y = 0;
- break;
- case CELL_SELECTED:
- *x = 0;
- *y = 1 * CELL_SIZE;
- break;
- default:
- *x = 0;
- *y = 0;
- }
- /*SDL_LogDebug("get_sprite_xy: %d @ (%0.0f, %0.0f)",
- cell, *x, *y);*/
+ *x = sprite_positions[(int)cell].x;
+ *y = sprite_positions[(int)cell].y;
}
void