diff --git a/obj/kinematics.c b/obj/kinematics.c index e1ede3d..2f34f84 100644 --- a/obj/kinematics.c +++ b/obj/kinematics.c @@ -1,5 +1,5 @@ #include "header.h" -#include +#include extern struct kinematic_obj_node *kinematic_HEAD; struct kinematic_obj init_kinematic_obj(int width, int height){ @@ -33,12 +33,11 @@ void move(struct kinematic_obj *obj, Vector2 acceleration){ // TODO: extend to multiple object collision, Might need to check distance // Move the object and apply hitbox reduction - obj->velocity.x += acceleration.x * delta; - obj->pos.x += obj->velocity.x * delta; + obj->velocity = Vector2Add(obj->velocity, Vector2Scale(acceleration, delta)); + obj->pos = Vector2Add(obj->pos, Vector2Scale(obj->velocity, 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]; - obj->velocity.y += acceleration.y * delta; - obj->pos.y += obj->velocity.y * delta; obj->rect.y = obj->pos.y + obj->dim_reduction[1]; obj->rect.height = obj->ori_height - obj->dim_reduction[1] - obj->dim_reduction[3]; diff --git a/obj/player.c b/obj/player.c index 9a82cf1..3bacef5 100644 --- a/obj/player.c +++ b/obj/player.c @@ -1,5 +1,5 @@ #include "header.h" - +#include #define PLAYER_ACCEL 1600 #define AIR_ACCEL 800 @@ -272,9 +272,7 @@ void player_input_check(struct player_obj *player){ } // Apply the scalar value, normalised to the unit direction - double m = mag(dash_vec); - dash_vec.x = dash_vec.x * DASH_SPD/m; - dash_vec.y = dash_vec.y * DASH_SPD/m; + dash_vec = Vector2Scale(Vector2Normalize(dash_vec), DASH_SPD); --dash_count; frame_counter=0; afterimage_fcounter=0; diff --git a/utilities/math.c b/utilities/math.c index 7999c9d..2b12236 100644 --- a/utilities/math.c +++ b/utilities/math.c @@ -1,15 +1,6 @@ #include "header.h" #include -double mag(Vector2 vec){ - return sqrt(vec.x*vec.x + vec.y*vec.y); -} - -Vector2 dir(Vector2 vec){ - long vec_mag = mag(vec); - return (Vector2){.x = vec.x/vec_mag,.y = vec.y/vec_mag}; -} - int sign(double val){ return (val > 0)?1:-1; }