forked from kdx/jtmm2-old
More vector related features
This commit is contained in:
parent
8d559b013a
commit
0a4dab8ee2
|
@ -7,10 +7,19 @@ typedef struct Vec
|
|||
float y;
|
||||
} Vec;
|
||||
|
||||
/* like memcpy but for vectors */
|
||||
void vec_cpy(Vec *destination, Vec *source);
|
||||
|
||||
/* apply a force on a vector */
|
||||
void vec_add(Vec *vector, Vec force);
|
||||
|
||||
/* apply the opposite of a force on a vector */
|
||||
void vec_sub(Vec *vector, Vec force);
|
||||
|
||||
/* multiply a vector by a scale */
|
||||
void vec_mul(Vec *vector, float scale);
|
||||
|
||||
/* divise a vector by a scale */
|
||||
void vec_div(Vec *vector, float scale);
|
||||
|
||||
#endif /* _DEF_VEC */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
w#include <gint/display.h>
|
||||
#include <gint/display.h>
|
||||
#include <gint/keyboard.h>
|
||||
#include <gint/std/string.h>
|
||||
|
||||
|
@ -15,7 +15,7 @@ int main(void)
|
|||
|
||||
/* create player */
|
||||
Player player = {
|
||||
.position = (Vec){32, 32}
|
||||
.position = {32, 32}
|
||||
};
|
||||
|
||||
/* create level */
|
||||
|
@ -28,8 +28,7 @@ int main(void)
|
|||
Camera camera = {
|
||||
.follow = &player.position
|
||||
};
|
||||
camera.position.x = player.position.x;
|
||||
camera.position.y = player.position.y;
|
||||
vec_cpy(&camera.position, &player.position);
|
||||
|
||||
/* main game loop */
|
||||
step_event(&player, &level, &camera);
|
||||
|
|
18
src/vec.c
18
src/vec.c
|
@ -1,5 +1,11 @@
|
|||
#include "vec.h"
|
||||
|
||||
void vec_cpy(Vec *destination, Vec *source)
|
||||
{
|
||||
destination->x = source->x;
|
||||
destination->y = source->y;
|
||||
}
|
||||
|
||||
void vec_add(Vec *vector, Vec force)
|
||||
{
|
||||
vector->x += force.x;
|
||||
|
@ -11,3 +17,15 @@ void vec_sub(Vec *vector, Vec force)
|
|||
vector->x -= force.x;
|
||||
vector->y -= force.y;
|
||||
}
|
||||
|
||||
void vec_mul(Vec *vector, float scale)
|
||||
{
|
||||
vector->x *= scale;
|
||||
vector->y *= scale;
|
||||
}
|
||||
|
||||
void vec_div(Vec *vector, float scale)
|
||||
{
|
||||
vector->x /= scale;
|
||||
vector->y /= scale;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue