diff options
| author | Menase Teshale <osome3717@gmail.com> | 2026-08-22 10:33:02 +0300 |
|---|---|---|
| committer | Menase Teshale <osome3717@gmail.com> | 2026-08-22 10:33:02 +0300 |
| commit | 05d3e3628f8d4ffe0e9dde7ecfdcb0a15d03cf23 (patch) | |
| tree | f5a98733fe3060b99663ce2862680f1b868d1c77 /src/game.c | |
| parent | a8b9de1767613f2e0e763e267979a6d51b4222a4 (diff) | |
Improved piece fall animation
Diffstat (limited to 'src/game.c')
| -rw-r--r-- | src/game.c | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -20,8 +20,9 @@ #define PIECE_ROTATION_SPEED 200 #define GRAVITY 2000.0 #define PIECE_MAX_FALL_XSPEED 200 -#define PIECE_FALL_YSPEED_INITIAL -15 +#define PIECE_FALL_YSPEED_INITIAL -150 #define DELETE_PIECE_OFFSET 50 +#define PIECE_FALL_ROTATION_SPEED 200 #define BOARD_WIDTH 8 #define BOARD_HEIGHT 6 @@ -53,6 +54,7 @@ typedef struct { //Data for falling animation float xvel, yvel; + float angular_velocity; int piece_color; int piece_face; @@ -256,6 +258,8 @@ void piece_start_falling(piece* piece) { piece->xvel = xvel_multiplier * PIECE_MAX_FALL_XSPEED; piece->yvel = PIECE_FALL_YSPEED_INITIAL; + + piece->angular_velocity = (rand() % 2 ? 1 : -1) * PIECE_FALL_ROTATION_SPEED; piece->state = fall_state; } @@ -281,6 +285,8 @@ void update_piece(piece* piece, float dt) { piece->position.y += piece->yvel * dt; piece->yvel += GRAVITY * dt / 2; + piece->orientation += piece->angular_velocity * dt; + piece->orientation = SDL_max(-PIECE_MAX_ROTATION, SDL_min(PIECE_MAX_ROTATION, piece->orientation)); break; default: @@ -457,6 +463,9 @@ void handle_piece_rotation(float dt) { for (int i = 0; i < game.num_pieces; i++) { piece* piece = &game.pieces[i]; + if (piece->state == fall_state) + continue; + if (piece->piece_id == selected_piece_id) { piece->orientation = SDL_min(piece->orientation + PIECE_ROTATION_SPEED * dt, |
