diff --git a/src/brick_game/tetris/01_automato.h b/src/brick_game/tetris/01_automato.h index 4fbfb72..3b9754d 100644 --- a/src/brick_game/tetris/01_automato.h +++ b/src/brick_game/tetris/01_automato.h @@ -46,7 +46,8 @@ typedef struct { Moving_t moving_type; int field[FIELD_HEIGHT][FIELD_WIDTH]; GameInfo_t* info; - long long last_time; + long long frame_count; // Общий счётчик кадров + long long last_move_frame; // Кадр, когда фигура последний раз двигалась } GameState_t; GameState_t* get_game_state(void); diff --git a/src/brick_game/tetris/02_tetris.c b/src/brick_game/tetris/02_tetris.c index 8235111..2572043 100644 --- a/src/brick_game/tetris/02_tetris.c +++ b/src/brick_game/tetris/02_tetris.c @@ -54,6 +54,8 @@ GameInfo_t updateCurrentState() { LOG_FUNCTION_START("updateCurrentState", ""); GameState_t* state = get_game_state(); + + state->frame_count++; // Обновляем логику игры только если игра не на паузе (кроме GameOver) if (!state->info->pause || state->state == GameOver) { diff --git a/src/brick_game/tetris/03_automato.c b/src/brick_game/tetris/03_automato.c index 916c70b..7ce6426 100644 --- a/src/brick_game/tetris/03_automato.c +++ b/src/brick_game/tetris/03_automato.c @@ -43,10 +43,12 @@ GameState_t* get_game_state(void) { } // Инициализируем начальные значения - state.info->speed = 100; + state.info->speed = 10; state.info->score = 0; state.info->level = 1; state.info->pause = 0; + state.frame_count = 0; + state.last_move_frame = 0; state.info->high_score = load_high_score(); // Загружаем рекорд // Инициализируем следующую фигуру diff --git a/src/brick_game/tetris/04_init.c b/src/brick_game/tetris/04_init.c index 28872c2..31e7dc7 100644 --- a/src/brick_game/tetris/04_init.c +++ b/src/brick_game/tetris/04_init.c @@ -12,7 +12,7 @@ void do_init(void) { state->info->score = 0; state->info->level = 1; - state->info->speed = 100; + state->info->speed = 10; state->state = Spawn; LOG_FUNCTION_END("do_init", "score=%d, level=%d, state=%d", diff --git a/src/brick_game/tetris/05_spawn.c b/src/brick_game/tetris/05_spawn.c index 4bc7ffb..555dca7 100644 --- a/src/brick_game/tetris/05_spawn.c +++ b/src/brick_game/tetris/05_spawn.c @@ -9,6 +9,7 @@ void do_spawn(void) { state->curr = state->next; state->curr.x = FIELD_WIDTH / 2 - 2; state->curr.y = 0; + state->moving_type = DoNothing; // Генерим новую следующую фигуру state->next.sprite = rand() % FIGURE_COUNT; diff --git a/src/brick_game/tetris/06_move.c b/src/brick_game/tetris/06_move.c index 4851ae2..51d98ab 100644 --- a/src/brick_game/tetris/06_move.c +++ b/src/brick_game/tetris/06_move.c @@ -12,19 +12,18 @@ void do_move(void) { LOG_FUNCTION_START("do_move", "speed=%d, moving_type=%d, current_pos=(%d,%d)", state->info->speed, state->moving_type, state->curr.x, state->curr.y); - // Добавляем проверку, чтобы избежать деления на ноль - if (state->info->speed <= 0) { - state->info->speed = 100; // Устанавливаем минимальное значение + // Рассчитываем, сколько кадров должно пройти между движениями + int frames_to_wait = (state->moving_type == ToDown) ? 1 : (1000 / state->info->speed); + + // Проверяем, прошло ли достаточно кадров + if (state->frame_count - state->last_move_frame < frames_to_wait) { + LOG_FUNCTION_END("do_move", "not enough frames passed, frame_count=%lld, last_move_frame=%lld, frames_to_wait=%d", + state->frame_count, state->last_move_frame, frames_to_wait); + return; } - long long current_time = get_time_ms(); - int delay = (state->moving_type == ToDown) ? 50 : (1000 / state->info->speed); - - if (current_time - state->last_time < delay) { - LOG_FUNCTION_END("do_move", "not enough time passed, delay=%ld ms, current_time=%ld, state->last_time=%ld, difference=%ld", delay, current_time, state->last_time, current_time - state->last_time); - return; // ещё не время - } - state->last_time = current_time; + // Обновляем время последнего движения + state->last_move_frame = state->frame_count; // Двигаем вниз state->curr.y++; @@ -33,6 +32,6 @@ void do_move(void) { state->state = Attaching; // переход в Attaching } - LOG_FUNCTION_END("do_move", "moved to (%d,%d), state=%d, delay=%d ms", - state->curr.x, state->curr.y, state->state, delay); + LOG_FUNCTION_END("do_move", "moved to (%d,%d), state=%d", + state->curr.x, state->curr.y, state->state); } \ No newline at end of file diff --git a/src/brick_game/tetris/07_moving.c b/src/brick_game/tetris/07_moving.c index 4ab850c..bc3c275 100644 --- a/src/brick_game/tetris/07_moving.c +++ b/src/brick_game/tetris/07_moving.c @@ -47,6 +47,7 @@ void do_moving(void) { state->state = Move; break; } + state->state = Move; LOG_FUNCTION_END("do_moving", "curr=(%d,%d), state=%d", state->curr.x, state->curr.y, state->state); diff --git a/src/brick_game/tetris/08_attaching.c b/src/brick_game/tetris/08_attaching.c index dc09724..74f9d66 100644 --- a/src/brick_game/tetris/08_attaching.c +++ b/src/brick_game/tetris/08_attaching.c @@ -111,8 +111,7 @@ void clear_lines() { if (new_level > state->info->level) { state->info->level = new_level; - // СУПЕР-УСКОРЕНИЕ! В 50 раз быстрее! - state->info->speed = new_level * 50; + state->info->speed += new_level * 5; LOG_FUNCTION_END("clear_lines", "lines_cleared=%d, score=%d->%d, level=%d->%d, speed=%d->%d", lines_cleared, old_score, state->info->score, old_level, state->info->level,