diff --git a/include/header.h b/include/header.h index 3c4aff6..51b7d94 100644 --- a/include/header.h +++ b/include/header.h @@ -75,6 +75,7 @@ void move(struct kinematic_obj *obj, Vector2 acceleration); void set_position(struct kinematic_obj *obj, int x, int y); bool place_meeting(struct kinematic_obj *obj, Vector2 dir); void scale_rect(struct kinematic_obj *obj); +void adjust_hitbox(struct kinematic_obj *obj); // Math functions, math.c long mag(Vector2 vec); diff --git a/obj/kinematics.c b/obj/kinematics.c index 581efdc..b5624ac 100644 --- a/obj/kinematics.c +++ b/obj/kinematics.c @@ -27,13 +27,17 @@ void move(struct kinematic_obj *obj, Vector2 acceleration){ Rectangle collide_rect; struct kinematic_obj_node *current; - //Simplistic Collision Handling for AABB, Could add coeff of restitution? - // TODO: Dont reset velocity if clipping vector is not the same dir as the movement dir + // Simplistic Collision Handling for AABB, Could add coeff of restitution? + // TODO: Implement the slightly better method of collision from: + // https://hopefultoad.blogspot.com/2017/09/2d-aabb-collision-detection-and-response.html + + // Also think about what happens if the square is completely inside the shape + // Then extend to multiple object + // Might need to check distance obj->velocity.x += acceleration.x * delta; obj->pos.x += obj->velocity.x * delta; obj->rect.x = obj->pos.x + obj->dim_reduction[0]; obj->rect.width = obj->ori_width - obj->dim_reduction[0] - obj->dim_reduction[2]; - current = kinematic_HEAD; while(current != NULL){ if(current->obj != obj){ @@ -112,3 +116,10 @@ Vector2 center(Rectangle rect){ .y = rect.y + rect.height/2 }; } + +void adjust_hitbox(struct kinematic_obj *obj){ + approach(&obj->dim_reduction[0], obj->set_dim_reduction[0], 0.2); + approach(&obj->dim_reduction[1], obj->set_dim_reduction[1], 0.2); + approach(&obj->dim_reduction[2], obj->set_dim_reduction[2], 0.2); + approach(&obj->dim_reduction[3], obj->set_dim_reduction[3], 0.2); +} diff --git a/obj/player.c b/obj/player.c index c81c3c2..d441b5e 100644 --- a/obj/player.c +++ b/obj/player.c @@ -127,8 +127,8 @@ void player_input_check(struct player_obj *player){ set_squish_target_offset(player->image, 1, 0); if(frame_counterkinematic.dim_reduction[0], player->kinematic.set_dim_reduction[0], 0.2); - approach(&player->kinematic.dim_reduction[1], player->kinematic.set_dim_reduction[1], 0.2); - approach(&player->kinematic.dim_reduction[2], player->kinematic.set_dim_reduction[2], 0.2); - approach(&player->kinematic.dim_reduction[3], player->kinematic.set_dim_reduction[3], 0.2); - - //scale_rect(&player->kinematic); + adjust_hitbox(&player->kinematic); if (IsKeyPressed(JUMP) && jumps > 0){ player->state = JUMP_SQUAT; @@ -187,4 +182,26 @@ void player_input_check(struct player_obj *player){ } move(&player->kinematic, accel); + + //Skidding + if (on_ground == true){ + if (IsKeyDown(LEFT)){ + if (player->kinematic.velocity.x > 0){ + set_squish_target_offset(player->image, 0, 15); + player->kinematic.dim_reduction[0] = 10; + }else{ + set_squish_target_offset(player->image, 0, 0); + player->kinematic.dim_reduction[0] = 0; + } + } + else if(IsKeyDown(RIGHT)){ + if (player->kinematic.velocity.x < 0){ + set_squish_target_offset(player->image, 2, 15); + player->kinematic.dim_reduction[2] = 10; + }else{ + set_squish_target_offset(player->image, 2, 0); + player->kinematic.dim_reduction[2] = 0; + } + } + } } diff --git a/obj/squishy.c b/obj/squishy.c index 99d59a3..fd80cd3 100644 --- a/obj/squishy.c +++ b/obj/squishy.c @@ -4,6 +4,16 @@ #define INTERP_FACTOR 0.2 #define OFFSET_VALUE 20 +float shear_mat[16] = {1.0, 0.0, 0, 0, + 0.1, 1.0, 0, 0, + 0, 0, 1.0, 0, + 0, 0, 0, 1.0}; + +float translate_mat[16] = {1,0,0,0, + 0,1,0,0, + 0,0,1,0, + 0,0,0,1}; + void three_point_beizer(Vector2 start, Vector2 mid, Vector2 end, Vector2* arr); void calc_offsets(struct squishy_square *square); @@ -112,10 +122,12 @@ void calc_offsets(struct squishy_square *square){ void draw_squishy(struct squishy_square *square){ rlPushMatrix(); - rlTranslatef(square->center.x, square->center.y, 0.0f); - //rlTranslatef(0.0f, square->parent->rect.height/2, 0.0f); - //rlScalef(0.5, 0.5, 1.0); - //rlTranslatef(0.0f, -square->parent->rect.height/2, 0.0f); + // TODO: Need a correction term to put the square in the box???? + rlMultMatrixf(shear_mat); + translate_mat[12] = square->center.x; + translate_mat[13] = square->center.y; + rlMultMatrixf(translate_mat); + int i; for(i=0;itop_vertices[i], (Vector2){0,0}, square->top_vertices[i+1], square->color);