Use raymath for vector calc
parent
4dcd45c512
commit
206b0d61a6
|
@ -1,5 +1,5 @@
|
|||
#include "header.h"
|
||||
#include <math.h>
|
||||
#include <raymath.h>
|
||||
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];
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "header.h"
|
||||
|
||||
#include <raymath.h>
|
||||
|
||||
#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;
|
||||
|
|
|
@ -1,15 +1,6 @@
|
|||
#include "header.h"
|
||||
#include <math.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue