- player->position.x += (player->velocity.x + player->movement.x) * d;
- player->position.y += (player->velocity.y + player->movement.y) * d;
-
- if (!hit_floor_ceiling) {
- player->velocity.y += PLAYER_GRAVITY * d;
+ for (int i = 0; i < 1000
+ && (vec_length(opposing_force) > 1e-6
+ || squishing_vertical_force(sides)
+ || squishing_horizontal_force(sides)); ++i) {
+ player->position = vec_sum(
+ player->position,
+ vec_scala_mult(
+ opposing_force,
+ 1e-2f));
+
+ if (fabs(opposing_force.x) > 1e-6 && (opposing_force.x < 0.0f) != ((player->velocity.x + player->movement.x) < 0.0f)) {
+ player->velocity.x = 0.0f;
+ player->movement.x = 0.0f;
+ }
+
+ if (fabs(opposing_force.y) > 1e-6 && (opposing_force.y < 0.0f) != ((player->velocity.y + player->movement.y) < 0.0f)) {
+ player->velocity.y = 0.0f;
+ player->movement.y = 0.0f;
+ }
+
+ if (squishing_vertical_force(sides)) {
+ player->height -= 1e-2f;
+ /* player->width = (PLAYER_WIDTH * PLAYER_HEIGHT) / player->height; */
+ }
+
+ if (squishing_horizontal_force(sides)) {
+ player->width -= 1e-2f;
+ /* player->height = (PLAYER_WIDTH * PLAYER_HEIGHT) / player->width; */
+ }
+
+ platforms_rect_object_collide(
+ platforms,
+ player_hitbox(player),
+ sides);
+ opposing_force = opposing_force_by_sides(sides);