start is working
This commit is contained in:
parent
3c7e55dd6f
commit
485ac0ca40
2 changed files with 8 additions and 9 deletions
|
|
@ -46,11 +46,12 @@ void init_game() {
|
||||||
state->next_figure.rotation = 0;
|
state->next_figure.rotation = 0;
|
||||||
|
|
||||||
state->score = 0;
|
state->score = 0;
|
||||||
|
state->high_score = 0;
|
||||||
state->level = 1;
|
state->level = 1;
|
||||||
state->drop_time = time(NULL) * 1000;
|
state->drop_time = time(NULL) * 1000;
|
||||||
state->game_over = false;
|
state->game_over = false;
|
||||||
state->paused = false;
|
state->paused = false;
|
||||||
state->state = FSM_Start; // Начинаем в состоянии Start
|
state->state = FSM_Start; // Начинаем в состоянии FSM_Start
|
||||||
}
|
}
|
||||||
|
|
||||||
void place_figure() {
|
void place_figure() {
|
||||||
|
|
@ -92,7 +93,7 @@ void place_figure() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_completed_lines() {
|
void clear_completed_lines() {
|
||||||
GameStateData* state = get_game_state();
|
GameStateData* state = get_instance();
|
||||||
int lines_cleared = 0;
|
int lines_cleared = 0;
|
||||||
int write_row = FIELD_HEIGHT - 1;
|
int write_row = FIELD_HEIGHT - 1;
|
||||||
|
|
||||||
|
|
@ -177,7 +178,7 @@ bool check_collision() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void fsm_transition() {
|
void fsm_transition() {
|
||||||
GameStateData* state = get_game_state();
|
GameStateData* state = get_instance();
|
||||||
|
|
||||||
switch (state->state) {
|
switch (state->state) {
|
||||||
case FSM_Start:
|
case FSM_Start:
|
||||||
|
|
@ -215,8 +216,6 @@ void fsm_transition() {
|
||||||
|
|
||||||
case FSM_Attaching:
|
case FSM_Attaching:
|
||||||
place_figure();
|
place_figure();
|
||||||
// После place_figure проверяем, не произошел ли Game Over
|
|
||||||
// В place_figure уже устанавливается FSM_Spawn, но нужно проверить столкновение
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FSM_GameOver:
|
case FSM_GameOver:
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ void userInput(UserAction_t action, bool hold) {
|
||||||
int saved_high_score = state->high_score;
|
int saved_high_score = state->high_score;
|
||||||
init_game();
|
init_game();
|
||||||
state->high_score = saved_high_score;
|
state->high_score = saved_high_score;
|
||||||
// Не меняем состояние, пусть остается в Start до следующего нажатия
|
// Не меняем состояние, пусть остается в FSM_Start до следующего нажатия
|
||||||
} else if (state->state == FSM_Start) {
|
} else if (state->state == FSM_Start) {
|
||||||
// Начинаем игру из состояния Start
|
// Начинаем игру из состояния Start
|
||||||
state->state = FSM_Spawn;
|
state->state = FSM_Spawn;
|
||||||
|
|
@ -84,7 +84,7 @@ void userInput(UserAction_t action, bool hold) {
|
||||||
state->paused = !state->paused;
|
state->paused = !state->paused;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Pause:
|
case Pause:
|
||||||
state->paused = !state->paused;
|
state->paused = !state->paused;
|
||||||
break;
|
break;
|
||||||
|
|
@ -194,8 +194,8 @@ GameInfo_t updateCurrentState() {
|
||||||
|
|
||||||
// Обновляем next
|
// Обновляем next
|
||||||
const int (*next_shape)[4];
|
const int (*next_shape)[4];
|
||||||
if (state->state == FSM_GameOver || state->state == FSM_Start) {
|
if (state->state == FSM_GameOver) {
|
||||||
// При game_over или в начальном состоянии показываем пустую фигуру
|
// При game_over показываем пустую фигуру
|
||||||
next_shape = empty_fig();
|
next_shape = empty_fig();
|
||||||
} else {
|
} else {
|
||||||
next_shape = get_figure_shape(state->next_figure.type, state->next_figure.rotation);
|
next_shape = get_figure_shape(state->next_figure.type, state->next_figure.rotation);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue