almost done
This commit is contained in:
parent
2f975d8e74
commit
411b2e4bb3
10 changed files with 203 additions and 138 deletions
|
|
@ -4,63 +4,87 @@ void userInput(UserAction_t action, bool hold) {
|
|||
(void)hold;
|
||||
GameState_t* state = get_game_state();
|
||||
|
||||
if (state->info->pause &&
|
||||
(action == Left || action == Right || action == Down || action == Up ||
|
||||
action == Action || action == Start)) {
|
||||
return;
|
||||
int should_process = 1;
|
||||
|
||||
// Проверка паузы
|
||||
if (state->info->pause) {
|
||||
if (action == Left || action == Right || action == Down ||
|
||||
action == Up || action == Action || action == Start) {
|
||||
should_process = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Блокируем движения во время Attaching (до завершения задержки)
|
||||
if (state->state == Attaching && !state->attach_completed) {
|
||||
if (action == Left || action == Right || action == Down ||
|
||||
action == Up || action == Action) {
|
||||
should_process = 0;
|
||||
}
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case Start:
|
||||
if (state->info->score >= state->info->high_score) {
|
||||
state->info->high_score = state->info->score;
|
||||
save_high_score(state->info->high_score);
|
||||
}
|
||||
state->info->high_score = load_high_score();
|
||||
state->state = Init;
|
||||
break;
|
||||
case Terminate:
|
||||
if (state->info->score > state->info->high_score) {
|
||||
state->info->high_score = state->info->score;
|
||||
save_high_score(state->info->high_score);
|
||||
}
|
||||
terminate_and_free(); // Освобождаем память здесь - единственное место
|
||||
state->state = GameOver;
|
||||
break;
|
||||
case Left:
|
||||
state->state = Moving;
|
||||
state->moving_type = LeftDown;
|
||||
break;
|
||||
case Right:
|
||||
state->state = Moving;
|
||||
state->moving_type = RightDown;
|
||||
break;
|
||||
case Action:
|
||||
state->state = Moving;
|
||||
state->moving_type = Rotate;
|
||||
break;
|
||||
case Down:
|
||||
state->state = Moving;
|
||||
state->moving_type = ToDown;
|
||||
break;
|
||||
case Pause:
|
||||
if (!state->info->pause) {
|
||||
state->pause_start_time = get_current_time_ms();
|
||||
} else {
|
||||
long long pause_duration = get_current_time_ms() - state->pause_start_time;
|
||||
state->last_move_time += pause_duration;
|
||||
}
|
||||
state->info->pause = !state->info->pause;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (should_process) {
|
||||
switch (action) {
|
||||
case Start:
|
||||
if (state->info->score >= state->info->high_score) {
|
||||
state->info->high_score = state->info->score;
|
||||
save_high_score(state->info->high_score);
|
||||
}
|
||||
state->info->high_score = load_high_score();
|
||||
state->state = Init;
|
||||
state->down_key_was_released = 1;
|
||||
break;
|
||||
case Terminate:
|
||||
if (state->info->score > state->info->high_score) {
|
||||
state->info->high_score = state->info->score;
|
||||
save_high_score(state->info->high_score);
|
||||
}
|
||||
terminate_and_free();
|
||||
state->state = GameOver;
|
||||
break;
|
||||
case Left:
|
||||
state->state = Moving;
|
||||
state->moving_type = LeftDown;
|
||||
break;
|
||||
case Right:
|
||||
state->state = Moving;
|
||||
state->moving_type = RightDown;
|
||||
break;
|
||||
case Action:
|
||||
state->state = Moving;
|
||||
state->moving_type = Rotate;
|
||||
break;
|
||||
case Down:
|
||||
if (state->down_key_was_released) {
|
||||
state->state = Moving;
|
||||
state->moving_type = ToDown;
|
||||
state->down_key_was_released = 0;
|
||||
}
|
||||
break;
|
||||
case Up:
|
||||
state->down_key_was_released = 1;
|
||||
break;
|
||||
case Pause:
|
||||
if (!state->info->pause) {
|
||||
state->pause_start_time = get_current_time_ms();
|
||||
} else {
|
||||
long long pause_duration = get_current_time_ms() - state->pause_start_time;
|
||||
state->last_move_time += pause_duration;
|
||||
// Корректируем attach_start_time если мы в Attaching
|
||||
state->attach_start_time += (state->state == Attaching) * pause_duration;
|
||||
}
|
||||
state->info->pause = !state->info->pause;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GameInfo_t updateCurrentState() {
|
||||
GameState_t* state = get_game_state();
|
||||
|
||||
if (!state->info->pause || state->state == GameOver) {
|
||||
int should_update = (!state->info->pause || state->state == GameOver);
|
||||
if (should_update) {
|
||||
switch (state->state) {
|
||||
case Init:
|
||||
do_init();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue