This commit is contained in:
Rorikstr | Rust Dev 2025-09-29 23:06:30 +03:00
parent a298b6396d
commit a0cec98aa7
8 changed files with 23 additions and 18 deletions

View file

@ -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);

View file

@ -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) {

View file

@ -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(); // Загружаем рекорд
// Инициализируем следующую фигуру

View file

@ -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",

View file

@ -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;

View file

@ -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);
}

View file

@ -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);

View file

@ -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,