fixed bug after gameover
This commit is contained in:
parent
f071558a0f
commit
65d2c2e287
7 changed files with 18 additions and 20 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "00_tetris.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef enum {
|
||||
Init,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
#include "01_automato.h"
|
||||
|
||||
void userInput(UserAction_t action, bool hold) {
|
||||
(void)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)) {
|
||||
|
|
@ -13,6 +12,10 @@ void userInput(UserAction_t action, bool hold) {
|
|||
|
||||
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;
|
||||
|
|
@ -44,7 +47,7 @@ void userInput(UserAction_t action, bool hold) {
|
|||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GameInfo_t updateCurrentState() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "01_automato.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int load_high_score() {
|
||||
FILE* file = fopen("high_score.txt", "r");
|
||||
|
|
@ -43,14 +42,6 @@ GameState_t* get_game_state(void) {
|
|||
state.frame_count = 0;
|
||||
state.last_move_frame = 0;
|
||||
state.info->high_score = load_high_score();
|
||||
|
||||
// Инициализируем следующую фигуру
|
||||
state.next.sprite = rand() % FIGURE_COUNT;
|
||||
state.next.rotation = 0;
|
||||
const int (*shape)[4] = get_figure_shape(state.next.sprite, 0);
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (int j = 0; j < 4; ++j)
|
||||
state.next.mtrx[i][j] = shape[i][j];
|
||||
|
||||
state.state = GameOver;
|
||||
initialized = 1;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
void do_init(void) {
|
||||
GameState_t* state = get_game_state();
|
||||
|
||||
// Очищаем поле
|
||||
for (int i = 0; i < FIELD_HEIGHT; ++i)
|
||||
for (int j = 0; j < FIELD_WIDTH; ++j)
|
||||
state->field[i][j] = 0;
|
||||
|
|
@ -9,5 +11,13 @@ void do_init(void) {
|
|||
state->info->score = 0;
|
||||
state->info->level = 1;
|
||||
state->info->speed = 10;
|
||||
state->state = Spawn;
|
||||
|
||||
state->next.sprite = rand() % FIGURE_COUNT;
|
||||
state->next.rotation = 0;
|
||||
const int (*shape)[4] = get_figure_shape(state->next.sprite, 0);
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (int j = 0; j < 4; ++j)
|
||||
state->next.mtrx[i][j] = shape[i][j];
|
||||
|
||||
state->state = Spawn; // Переход в Spawn
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
#include "01_automato.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void do_spawn(void) {
|
||||
GameState_t* state = get_game_state();
|
||||
|
|
|
|||
|
|
@ -1,11 +1,6 @@
|
|||
// brick_game/tetris/06_move.c
|
||||
#include <time.h>
|
||||
#include "01_automato.h"
|
||||
|
||||
long long get_time_ms() {
|
||||
return (long long)time(NULL) * 1000;
|
||||
}
|
||||
|
||||
void do_move(void) {
|
||||
GameState_t* state = get_game_state();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "01_automato.h"
|
||||
#include <string.h>
|
||||
|
||||
const int (*get_figure_shape(Sprite_t sprite, int rotation))[4] {
|
||||
const int (*result)[4] = NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue