mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-18 19:01:47 +03:00
Merge pull request #343 from p3ngu19z/dev
Improve Tetris fall speed algorithm
This commit is contained in:
commit
883f67d6d1
@ -16,6 +16,9 @@
|
|||||||
#define FIELD_WIDTH 11
|
#define FIELD_WIDTH 11
|
||||||
#define FIELD_HEIGHT 24
|
#define FIELD_HEIGHT 24
|
||||||
|
|
||||||
|
#define MAX_FALL_SPEED 500
|
||||||
|
#define MIN_FALL_SPEED 100
|
||||||
|
|
||||||
typedef struct Point {
|
typedef struct Point {
|
||||||
// Also used for offset data, which is sometimes negative
|
// Also used for offset data, which is sometimes negative
|
||||||
int8_t x, y;
|
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) {
|
static void tetris_game_init_state(TetrisState* tetris_state) {
|
||||||
tetris_state->gameState = GameStatePlaying;
|
tetris_state->gameState = GameStatePlaying;
|
||||||
tetris_state->numLines = 0;
|
tetris_state->numLines = 0;
|
||||||
tetris_state->fallSpeed = 500;
|
tetris_state->fallSpeed = MAX_FALL_SPEED;
|
||||||
memset(tetris_state->playField, 0, sizeof(tetris_state->playField));
|
memset(tetris_state->playField, 0, sizeof(tetris_state->playField));
|
||||||
|
|
||||||
memcpy(&tetris_state->currPiece, &shapes[rand() % 7], sizeof(tetris_state->currPiece));
|
memcpy(&tetris_state->currPiece, &shapes[rand() % 7], sizeof(tetris_state->currPiece));
|
||||||
@ -303,6 +306,7 @@ static void
|
|||||||
tetris_game_render_curr_piece(tetris_state);
|
tetris_game_render_curr_piece(tetris_state);
|
||||||
uint8_t numLines = 0;
|
uint8_t numLines = 0;
|
||||||
uint8_t lines[] = {0, 0, 0, 0};
|
uint8_t lines[] = {0, 0, 0, 0};
|
||||||
|
uint16_t nextFallSpeed;
|
||||||
|
|
||||||
tetris_game_check_for_lines(tetris_state, lines, &numLines);
|
tetris_game_check_for_lines(tetris_state, lines, &numLines);
|
||||||
if(numLines > 0) {
|
if(numLines > 0) {
|
||||||
@ -323,7 +327,10 @@ static void
|
|||||||
uint16_t oldNumLines = tetris_state->numLines;
|
uint16_t oldNumLines = tetris_state->numLines;
|
||||||
tetris_state->numLines += numLines;
|
tetris_state->numLines += numLines;
|
||||||
if((oldNumLines / 10) % 10 != (tetris_state->numLines / 10) % 10) {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user