Merge pull request #343 from p3ngu19z/dev

Improve Tetris fall speed algorithm
This commit is contained in:
MX 2023-02-17 00:00:13 +03:00 committed by GitHub
commit 883f67d6d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,9 @@
#define FIELD_WIDTH 11
#define FIELD_HEIGHT 24
#define MAX_FALL_SPEED 500
#define MIN_FALL_SPEED 100
typedef struct Point {
// Also used for offset data, which is sometimes negative
int8_t x, y;
@ -169,7 +172,7 @@ static void tetris_game_input_callback(InputEvent* input_event, FuriMessageQueue
static void tetris_game_init_state(TetrisState* tetris_state) {
tetris_state->gameState = GameStatePlaying;
tetris_state->numLines = 0;
tetris_state->fallSpeed = 500;
tetris_state->fallSpeed = MAX_FALL_SPEED;
memset(tetris_state->playField, 0, sizeof(tetris_state->playField));
memcpy(&tetris_state->currPiece, &shapes[rand() % 7], sizeof(tetris_state->currPiece));
@ -303,6 +306,7 @@ static void
tetris_game_render_curr_piece(tetris_state);
uint8_t numLines = 0;
uint8_t lines[] = {0, 0, 0, 0};
uint16_t nextFallSpeed;
tetris_game_check_for_lines(tetris_state, lines, &numLines);
if(numLines > 0) {
@ -323,7 +327,10 @@ static void
uint16_t oldNumLines = tetris_state->numLines;
tetris_state->numLines += numLines;
if((oldNumLines / 10) % 10 != (tetris_state->numLines / 10) % 10) {
tetris_state->fallSpeed -= 50;
nextFallSpeed = tetris_state->fallSpeed - (100 / (tetris_state->numLines / 10));
if (nextFallSpeed >= MIN_FALL_SPEED){
tetris_state->fallSpeed = nextFallSpeed;
}
}
}