almost done
This commit is contained in:
parent
2f975d8e74
commit
411b2e4bb3
10 changed files with 203 additions and 138 deletions
|
|
@ -2,35 +2,60 @@
|
|||
|
||||
void do_attaching(void) {
|
||||
GameState_t* state = get_game_state();
|
||||
place_figure();
|
||||
clear_lines();
|
||||
if (is_game_over()) {
|
||||
state->state = GameOver;
|
||||
} else {
|
||||
state->state = Spawn;
|
||||
long long current_time = get_current_time_ms();
|
||||
|
||||
// Если только что вошли в Attaching - размещаем фигуру и запускаем таймер
|
||||
if (!state->attach_completed) {
|
||||
// Первый вход в Attaching
|
||||
if (state->attach_start_time == 0) {
|
||||
place_figure();
|
||||
clear_lines();
|
||||
state->attach_start_time = current_time;
|
||||
state->attach_completed = 0;
|
||||
}
|
||||
|
||||
// Проверяем, прошло ли 350мс
|
||||
if (current_time - state->attach_start_time >= 350) {
|
||||
state->attach_completed = 1;
|
||||
state->attach_start_time = 0; // Сбрасываем таймер
|
||||
|
||||
// Проверяем game over и переходим
|
||||
int game_over = is_game_over();
|
||||
|
||||
if (game_over) {
|
||||
state->state = GameOver;
|
||||
} else {
|
||||
state->state = Spawn;
|
||||
}
|
||||
|
||||
state->attach_completed = 0; // Сбрасываем флаг для следующего attach
|
||||
}
|
||||
// Иначе остаёмся в Attaching и ждём
|
||||
}
|
||||
}
|
||||
|
||||
int check_collision() {
|
||||
GameState_t* state = get_game_state();
|
||||
Figure_t* fig = &state->curr;
|
||||
int collision_detected = 0;
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
for (int i = 0; i < 4 && !collision_detected; ++i) {
|
||||
for (int j = 0; j < 4 && !collision_detected; ++j) {
|
||||
if (fig->mtrx[i][j]) {
|
||||
int x = fig->x + j;
|
||||
int y = fig->y + i;
|
||||
|
||||
if (x < 0 || x >= FIELD_WIDTH || y >= FIELD_HEIGHT) {
|
||||
return 1; // TODO
|
||||
}
|
||||
if (y >= 0 && state->field[y][x]) {
|
||||
return 1; // TODO
|
||||
int out_of_bounds = (x < 0 || x >= FIELD_WIDTH || y >= FIELD_HEIGHT);
|
||||
int hits_placed_block = (y >= 0 && state->field[y][x]);
|
||||
|
||||
if (out_of_bounds || hits_placed_block) {
|
||||
collision_detected = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
return collision_detected;
|
||||
}
|
||||
|
||||
void place_figure() {
|
||||
|
|
@ -43,7 +68,7 @@ void place_figure() {
|
|||
int x = fig->x + j;
|
||||
int y = fig->y + i;
|
||||
if (y >= 0 && y < FIELD_HEIGHT && x >= 0 && x < FIELD_WIDTH) {
|
||||
state->field[y][x] = 2; // закреплённая фигура
|
||||
state->field[y][x] = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -68,31 +93,36 @@ void clear_lines() {
|
|||
|
||||
for (int i = FIELD_HEIGHT - 1; i >= 0; --i) {
|
||||
int full = 1;
|
||||
|
||||
for (int j = 0; j < FIELD_WIDTH; ++j) {
|
||||
if (state->field[i][j] != 2) {
|
||||
full = 0;
|
||||
break; // TODO
|
||||
}
|
||||
}
|
||||
|
||||
if (full) {
|
||||
shift_lines_down(i);
|
||||
lines_cleared++;
|
||||
i++; // Check the same row again after shifting
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (lines_cleared > 0) {
|
||||
int points[] = {0, 100, 300, 700, 1500};
|
||||
state->info->score += points[lines_cleared];
|
||||
|
||||
if (state->info->score > state->info->high_score) {
|
||||
state->info->high_score = state->info->score;
|
||||
}
|
||||
|
||||
int new_level = (state->info->score / 600) + 1;
|
||||
if (new_level > 10) new_level = 10;
|
||||
if (new_level > 10) {
|
||||
new_level = 10;
|
||||
}
|
||||
|
||||
if (new_level > state->info->level) {
|
||||
state->info->level = new_level;
|
||||
state->info->speed = new_level * 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue