Account for shear when colliding target

master
En Yi 2020-03-21 15:17:58 +08:00 committed by En Yi
parent 3578fb7d06
commit b9b958a8db
5 changed files with 20 additions and 8 deletions

View File

@ -35,6 +35,7 @@ struct kinematic_obj
int ori_height; int ori_height;
double dim_reduction[4]; double dim_reduction[4];
double set_dim_reduction[4]; double set_dim_reduction[4];
double x_shear;
}; };
struct kinematic_obj_node struct kinematic_obj_node
@ -143,4 +144,4 @@ bool collide_target(struct kinematic_obj *obj, struct target_obj *target);
//Debug stuff, debug.c //Debug stuff, debug.c
void state_string(char *str, enum PLAYER_STATE state); void state_string(char *str, enum PLAYER_STATE state);
void display_input(char *dir); void display_input(char *dir);

View File

@ -9,7 +9,8 @@ struct kinematic_obj init_kinematic_obj(int width, int height){
.rect = {0,0,width,height}, .rect = {0,0,width,height},
.ori_width = width, .ori_width = width,
.ori_height = height, .ori_height = height,
.dim_reduction = {0,0,0,0} .dim_reduction = {0,0,0,0},
.x_shear = 0.0
}; };
return obj; return obj;

View File

@ -299,7 +299,7 @@ void player_input_check(struct player_obj *player){
// All velocity modification must be done before calling the move function // All velocity modification must be done before calling the move function
move(&player->kinematic, accel); move(&player->kinematic, accel);
player->kinematic.x_shear = -player->kinematic.velocity.x / 600;
// Handle jumping // Handle jumping
if (IsKeyPressed(JUMP) && jumps > 0){ if (IsKeyPressed(JUMP) && jumps > 0){
player->state = JUMP_SQUAT; player->state = JUMP_SQUAT;

View File

@ -124,7 +124,7 @@ void calc_offsets(struct squishy_square *square){
void draw_squishy(struct squishy_square *square){ void draw_squishy(struct squishy_square *square){
rlPushMatrix(); rlPushMatrix();
// TODO: Need a correction term to put the square in the box???? // 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); rlMultMatrixf(shear_mat);
translate_mat[12] = square->center.x; translate_mat[12] = square->center.x;
translate_mat[13] = square->center.y; translate_mat[13] = square->center.y;

View File

@ -27,13 +27,23 @@ bool collide_target(struct kinematic_obj *obj, struct target_obj *target){
Vector2 n = Vector2Subtract(target_center, obj_center); Vector2 n = Vector2Subtract(target_center, obj_center);
n = Vector2Normalize(n); 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); 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); 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); 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 obj_proj4 = Vector2DotProduct(pos_check, n);
double min_proj = fmin(fmin(fmin(obj_proj1, obj_proj2), obj_proj3), obj_proj4); double min_proj = fmin(fmin(fmin(obj_proj1, obj_proj2), obj_proj3), obj_proj4);