From b9b958a8db51902c5cef9548d77ec4e1b3752bc1 Mon Sep 17 00:00:00 2001 From: En Yi Date: Sat, 21 Mar 2020 15:17:58 +0800 Subject: [PATCH] Account for shear when colliding target --- include/header.h | 3 ++- obj/kinematics.c | 3 ++- obj/player.c | 2 +- obj/squishy.c | 2 +- obj/target.c | 18 ++++++++++++++---- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/header.h b/include/header.h index 08714e0..9202478 100644 --- a/include/header.h +++ b/include/header.h @@ -35,6 +35,7 @@ struct kinematic_obj int ori_height; double dim_reduction[4]; double set_dim_reduction[4]; + double x_shear; }; struct kinematic_obj_node @@ -143,4 +144,4 @@ bool collide_target(struct kinematic_obj *obj, struct target_obj *target); //Debug stuff, debug.c void state_string(char *str, enum PLAYER_STATE state); -void display_input(char *dir); \ No newline at end of file +void display_input(char *dir); diff --git a/obj/kinematics.c b/obj/kinematics.c index 3d1ea24..93c3973 100644 --- a/obj/kinematics.c +++ b/obj/kinematics.c @@ -9,7 +9,8 @@ struct kinematic_obj init_kinematic_obj(int width, int height){ .rect = {0,0,width,height}, .ori_width = width, .ori_height = height, - .dim_reduction = {0,0,0,0} + .dim_reduction = {0,0,0,0}, + .x_shear = 0.0 }; return obj; diff --git a/obj/player.c b/obj/player.c index 3950c2f..f7660ea 100644 --- a/obj/player.c +++ b/obj/player.c @@ -299,7 +299,7 @@ void player_input_check(struct player_obj *player){ // All velocity modification must be done before calling the move function move(&player->kinematic, accel); - + player->kinematic.x_shear = -player->kinematic.velocity.x / 600; // Handle jumping if (IsKeyPressed(JUMP) && jumps > 0){ player->state = JUMP_SQUAT; diff --git a/obj/squishy.c b/obj/squishy.c index d3b57f5..617ed3f 100644 --- a/obj/squishy.c +++ b/obj/squishy.c @@ -124,7 +124,7 @@ void calc_offsets(struct squishy_square *square){ void draw_squishy(struct squishy_square *square){ rlPushMatrix(); // TODO: Need a correction term to put the square in the box???? - shear_mat[4] = -square->parent->velocity.x / 600; + shear_mat[4] = square->parent->x_shear; rlMultMatrixf(shear_mat); translate_mat[12] = square->center.x; translate_mat[13] = square->center.y; diff --git a/obj/target.c b/obj/target.c index 7ebc30c..293c71a 100644 --- a/obj/target.c +++ b/obj/target.c @@ -27,13 +27,23 @@ bool collide_target(struct kinematic_obj *obj, struct target_obj *target){ Vector2 n = Vector2Subtract(target_center, obj_center); n = Vector2Normalize(n); - Vector2 pos_check = obj->pos; + Rectangle hitbox = obj->rect; + if (obj->x_shear > 0.5){ + if (obj->x_shear > 0){ + hitbox.x -= obj->x_shear * obj->ori_width / 2; + hitbox.width += obj->x_shear * obj->ori_width; + }else{ + hitbox.x -= -obj->x_shear * obj->ori_width / 2; + hitbox.width += -obj->x_shear * obj->ori_width; + } + } + Vector2 pos_check = (Vector2){hitbox.x, hitbox.y}; double obj_proj1 = Vector2DotProduct(pos_check, n); - pos_check.x += obj->rect.width; + pos_check.x += hitbox.width; double obj_proj2 = Vector2DotProduct(pos_check, n); - pos_check.y += obj->rect.height; + pos_check.y += hitbox.height; double obj_proj3 = Vector2DotProduct(pos_check, n); - pos_check.x -= obj->rect.width; + pos_check.x -= hitbox.width; double obj_proj4 = Vector2DotProduct(pos_check, n); double min_proj = fmin(fmin(fmin(obj_proj1, obj_proj2), obj_proj3), obj_proj4);