summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2025-05-07 22:19:05 +0200
committerRichard Braun <rbraun@sceen.net>2025-05-07 22:19:05 +0200
commitf3aa771a8d1416b57e1580833bbfb2914b790582 (patch)
treee4b08d671baa48e7107f88e9aa0112a7ec8011fa
parent6a6d994cc469328fd03516ac897f850eb277f7db (diff)
Fix spawning position
-rw-r--r--src/et/et.c31
-rw-r--r--src/macros.h6
2 files changed, 21 insertions, 16 deletions
diff --git a/src/et/et.c b/src/et/et.c
index 8797635..3a7200d 100644
--- a/src/et/et.c
+++ b/src/et/et.c
@@ -69,7 +69,7 @@
" :T-'-.:\"\":|\"\"\"\"\"\"\"|/ \\/ \\|=====|======| \n" \
" .A.\"\"\"||_|| ,. .. || || |/\\/\\/\\/ | | || \n" \
" :;:////\\:::.'.| || || ||-||-|/\\/\\/\\+|+| | | \n" \
-" ;:;;\\////::::,='======='============/\\/\\=====. \n"
+" ;:;;\\////::::,='======='=====umrain=/\\/\\=====. \n"
#define ET_HELP_SPRITE \
" s = left \n" \
@@ -596,9 +596,6 @@ et_bag_push(struct et_bag *bag, struct et_piece *piece)
assert(bag->size < (int)ARRAY_SIZE(bag->pieces));
id = eetg_rand() % (ARRAY_SIZE(bag->pieces) - bag->size);
-#if 0
-id = 6 % (ARRAY_SIZE(bag->pieces) - bag->size);
-#endif
for (;;) {
bool exists;
@@ -679,6 +676,20 @@ et_game_get_next_piece(struct et_game *game)
}
static void
+et_game_switch_to_next_piece(struct et_game *game)
+{
+ struct eetg_object *object;
+
+ assert(game);
+
+ game->current_piece = et_game_get_next_piece(game);
+ object = et_piece_get_object(game->current_piece);
+
+ eetg_world_add_layer(&game->world, object,
+ 40 - (DIV_CEIL(eetg_object_get_width(object), 4) * 2), 0, 1);
+}
+
+static void
et_game_start(struct et_game *game)
{
assert(game);
@@ -701,12 +712,7 @@ et_game_start(struct et_game *game)
eetg_world_add(&game->world, &game->right_wall, 50, 0);
eetg_world_add(&game->world, &game->bottom_wall, 28, 20);
- assert(!game->current_piece);
-
- game->current_piece = et_game_get_next_piece(game);
-
- eetg_world_add_layer(&game->world,
- et_piece_get_object(game->current_piece), 38, 0, 1);
+ et_game_switch_to_next_piece(game);
game->current_piece_counter_reload = ET_FPS / ET_CURRENT_PIECE_SPEED;
game->current_piece_counter = game->current_piece_counter_reload;
@@ -880,10 +886,7 @@ et_game_process_lockdown(struct et_game *game)
game->nr_lockdown_moves = -1;
- game->current_piece = et_game_get_next_piece(game);
-
- eetg_world_add_layer(&game->world,
- et_piece_get_object(game->current_piece), 38, 0, 1);
+ et_game_switch_to_next_piece(game);
}
static void
diff --git a/src/macros.h b/src/macros.h
index 58cdca2..422bb8b 100644
--- a/src/macros.h
+++ b/src/macros.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024 Richard Braun.
+ * Copyright (c) 2024-2025 Richard Braun.
*
* Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted.
@@ -19,7 +19,9 @@
#ifndef MACROS_H
#define MACROS_H
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+#define DIV_CEIL(n, d) (((n) + (d) - 1) / (d))
#define structof(ptr, type, member) \
((type *)((char *)(ptr) - offsetof(type, member)))