Added unit tests
This commit is contained in:
@@ -30,6 +30,16 @@ static bool is_animating;
|
||||
static Vector2 new_tile = {-1, 1};
|
||||
static float new_tile_animation_progress;
|
||||
|
||||
typedef struct {
|
||||
Vector2 from;
|
||||
Vector2 to;
|
||||
// We need to store this to know when to (show the) merge, if merging
|
||||
Vector2 position;
|
||||
int value;
|
||||
} animated_tile_t;
|
||||
|
||||
static animated_tile_t animated_tiles[BOARD_WIDTH * BOARD_HEIGHT];
|
||||
|
||||
// Common logic shared between both input handlers
|
||||
static void after_input(GameState_t *game_state) {
|
||||
spawn_tile(game_state, &new_tile);
|
||||
@@ -132,21 +142,20 @@ void handle_keyboard_input(GameState_t *game_state) {
|
||||
}
|
||||
}
|
||||
|
||||
void animate_new_tile() {
|
||||
static void animate_new_tile() {
|
||||
if (new_tile.x == -1 && new_tile.y == -1)
|
||||
return;
|
||||
|
||||
// Simple pop-in animation that scales the tile from 0 to full size
|
||||
new_tile_animation_progress += GetFrameTime() * 5; // Adjust speed as needed
|
||||
new_tile_animation_progress += GetFrameTime() * 5;
|
||||
if (new_tile_animation_progress >= 1.0f) {
|
||||
new_tile_animation_progress = 0.3f;
|
||||
new_tile_animation_progress = 0.0f;
|
||||
new_tile = (Vector2){-1, -1}; // Reset after animation completes
|
||||
is_animating = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Main render loop, responsible ONLY for redering
|
||||
void render(GameState_t *game_state) {
|
||||
bool render(GameState_t *game_state) {
|
||||
if (is_animating) {
|
||||
animate_new_tile();
|
||||
}
|
||||
@@ -163,7 +172,7 @@ void render(GameState_t *game_state) {
|
||||
}
|
||||
|
||||
if (is_animating && new_tile.x == x && new_tile.y == y) {
|
||||
float scale = new_tile_animation_progress; // Scale from 0 to 1
|
||||
float scale = 1.0 - 0.2 * sin(new_tile_animation_progress * PI);
|
||||
int scaled_size = (int)(TILE_SIZE * scale);
|
||||
int offset = (TILE_SIZE - scaled_size) / 2;
|
||||
DrawRectangle(pos_x + offset, pos_y + offset, scaled_size, scaled_size, tile_colors[color_index]);
|
||||
@@ -207,4 +216,5 @@ void render(GameState_t *game_state) {
|
||||
DrawRectangle(400 - 100, 450, 200, 40, RED);
|
||||
DrawText("Try again", 400 - MeasureText("Try again", 20) / 2, 455 + 4, 20, WHITE);
|
||||
}
|
||||
return is_animating;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user