summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/game.c b/src/game.c
index b85d3ca..c75200e 100644
--- a/src/game.c
+++ b/src/game.c
@@ -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,