IT WORKS NOW

This commit is contained in:
Rorikstr | Rust Dev 2025-09-29 19:23:14 +03:00
parent f5b65a390b
commit 0f2d03526e
14 changed files with 19477 additions and 31 deletions

View file

@ -1,6 +1,9 @@
#include "01_automato.h"
#include "../../logging.h"
void do_attaching(void) {
LOG_FUNCTION_START("do_attaching", "");
GameState_t* state = get_game_state();
// Закрепляем фигуру на поле
place_figure();
@ -15,9 +18,13 @@ void do_attaching(void) {
} else {
state->state = Spawn;
}
LOG_FUNCTION_END("do_attaching", "state=%d", state->state);
}
int check_collision() {
LOG_FUNCTION_START("check_collision", "");
GameState_t* state = get_game_state();
Figure_t* fig = &state->curr;
@ -28,19 +35,25 @@ int check_collision() {
int y = fig->y + i;
if (x < 0 || x >= FIELD_WIDTH || y >= FIELD_HEIGHT) {
LOG_FUNCTION_END("check_collision", "collision with boundary, x=%d, y=%d", x, y);
return 1; // коллизия
}
if (y >= 0 && state->field[y][x]) {
LOG_FUNCTION_END("check_collision", "collision with field, x=%d, y=%d", x, y);
return 1; // коллизия с другой фигурой
}
}
}
}
LOG_FUNCTION_END("check_collision", "no collision");
return 0; // нет коллизии
}
void place_figure() {
GameState_t* state = get_game_state();
LOG_FUNCTION_START("place_figure", "curr=(%d,%d)", state->curr.x, state->curr.y);
Figure_t* fig = &state->curr;
for (int i = 0; i < 4; ++i) {
@ -54,10 +67,14 @@ void place_figure() {
}
}
}
LOG_FUNCTION_END("place_figure", "");
}
void clear_lines() {
GameState_t* state = get_game_state();
LOG_FUNCTION_START("clear_lines", "score=%d", state->info->score);
int lines_cleared = 0;
for (int i = FIELD_HEIGHT - 1; i >= 0; --i) {
@ -93,4 +110,7 @@ void clear_lines() {
state->info->speed = state->info->level;
}
}
LOG_FUNCTION_END("clear_lines", "lines_cleared=%d, score=%d, level=%d",
lines_cleared, state->info->score, state->info->level);
}