guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
- inkscape:window-width="1916"
- inkscape:window-height="1041"
+ inkscape:window-width="956"
+ inkscape:window-height="1023"
id="namedview13"
showgrid="false"
inkscape:snap-bbox="true"
inkscape:snap-bbox-midpoints="true"
inkscape:snap-bbox-edge-midpoints="true"
inkscape:zoom="2"
- inkscape:cx="282.86631"
- inkscape:cy="332.49893"
- inkscape:window-x="0"
- inkscape:window-y="18"
+ inkscape:cx="439.36631"
+ inkscape:cy="336.49893"
+ inkscape:window-x="960"
+ inkscape:window-y="36"
inkscape:window-maximized="0"
inkscape:current-layer="svg16" />
<metadata
width="50"
y="200"
x="350" />
- <rect
- id="rect4-7"
- style="fill:#0000ff;stroke-width:1"
- height="25"
- width="50"
- y="200"
- x="400" />
</svg>
size_t rects_size;
};
-static const vec_t opposing_rect_side_forces[RECT_SIDE_N] = {
- { .x = 1.0f, .y = 0.0f }, /* RECT_SIDE_LEFT = 0, */
- { .x = -1.0f, .y = 0.0f }, /* RECT_SIDE_RIGHT, */
- { .x = 0.0f, .y = 1.0f, }, /* RECT_SIDE_TOP, */
- { .x = 0.0f, .y = -1.0f, } /* RECT_SIDE_BOTTOM, */
-};
-
platforms_t *create_platforms(const rect_t *rects, size_t rects_size)
{
assert(rects);
return 0;
}
-vec_t platforms_rect_object_collide(const platforms_t *platforms,
- rect_t object)
+void platforms_rect_object_collide(const platforms_t *platforms,
+ rect_t object,
+ int sides[RECT_SIDE_N])
{
assert(platforms);
- int sides[4];
- memset(sides, 0, sizeof(sides));
+ memset(sides, 0, sizeof(int) * RECT_SIDE_N);
for (size_t i = 0; i < platforms->rects_size; ++i) {
rect_object_impact(&object, &platforms->rects[i], sides);
}
-
- vec_t opposing_force = {
- .x = 0.0f,
- .y = 0.0f
- };
-
- for (rect_side_t side = 0; side < RECT_SIDE_N; ++side) {
- if (sides[side]) {
- vec_add(
- &opposing_force,
- opposing_rect_side_forces[side]);
- }
- }
-
- return opposing_force;
}
float width;
};
+static const vec_t opposing_rect_side_forces[RECT_SIDE_N] = {
+ { .x = 1.0f, .y = 0.0f }, /* RECT_SIDE_LEFT = 0, */
+ { .x = -1.0f, .y = 0.0f }, /* RECT_SIDE_RIGHT, */
+ { .x = 0.0f, .y = 1.0f, }, /* RECT_SIDE_TOP, */
+ { .x = 0.0f, .y = -1.0f, } /* RECT_SIDE_BOTTOM, */
+};
+
+static vec_t opposing_force_by_sides(int sides[RECT_SIDE_N])
+{
+ vec_t opposing_force = {
+ .x = 0.0f,
+ .y = 0.0f
+ };
+
+ for (rect_side_t side = 0; side < RECT_SIDE_N; ++side) {
+ if (sides[side]) {
+ vec_add(
+ &opposing_force,
+ opposing_rect_side_forces[side]);
+ }
+ }
+
+ return opposing_force;
+}
+
+static int squishing_horizontal_force(int sides[RECT_SIDE_N])
+{
+ return sides[RECT_SIDE_LEFT] && sides[RECT_SIDE_RIGHT];
+}
+
+static int squishing_vertical_force(int sides[RECT_SIDE_N])
+{
+ return sides[RECT_SIDE_TOP] && sides[RECT_SIDE_BOTTOM];
+}
+
player_t *create_player(float x, float y)
{
player_t *player = malloc(sizeof(player_t));
player->height = fminf(player->height + PLAYER_INFLATION * d, PLAYER_HEIGHT);
player->width = (PLAYER_WIDTH * PLAYER_HEIGHT) / player->height;
- vec_t opposing_force = platforms_rect_object_collide(
- platforms,
- player_hitbox(player));
+
+ int sides[RECT_SIDE_N] = { 0, 0, 0, 0 };
+
+ platforms_rect_object_collide(platforms, player_hitbox(player), sides);
+ vec_t opposing_force = opposing_force_by_sides(sides);
if (opposing_force.y < 0.0f && (player->velocity.y + player->movement.y) > 800.0f) {
player->height = PLAYER_HEIGHT / 2;
}
- for (int i = 0; i < 1000 && vec_length(opposing_force) > 1e-6; ++i) {
+ 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(
player->movement.y = 0.0f;
}
- opposing_force = platforms_rect_object_collide(
+ 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));
+ player_hitbox(player),
+ sides);
+ opposing_force = opposing_force_by_sides(sides);
}
}