summaryrefslogtreecommitdiff
path: root/src/entity.h
blob: 81762b217a0e5a39584d8cdd861a4ea7d3372408 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef ENTITY_H
#define ENTITY_H

#include <stdbool.h>
#include <stdint.h>

#define ENTITIES_MAX 100

#ifndef M_PI
#define M_PI 3.141592f
#endif

struct Vec2d
{
    union
    {
        struct
        {
            float x;
            float y;
        };
        struct
        {
            float w;
            float h;
        };
        float xy[2];
        float d[2];
    };
};

// TODO: get rid of this or rename it
struct Entity
{
    float mass;
    float size;
    struct Vec2d position;
    struct Vec2d velocity;
    uint32_t color;
};

struct EntityRender
{
    float size;
    uint32_t color;
};

struct EntityPhysical
{
    struct Vec2d velocity;
    float mass;
};

struct Entities
{
    struct Vec2d positions[ENTITIES_MAX];
    struct EntityRender render[ENTITIES_MAX];
    struct EntityPhysical physics[ENTITIES_MAX];
    uint32_t num_entities;
};

void entity_accelerate(struct Entity *e, struct Vec2d *v);
struct Vec2d vec2d_add(struct Vec2d v0, struct Vec2d v1);
struct Vec2d vec2d_add_c(float x0, float y0, float x1, float y1);
struct Vec2d vec2d_al_to_xy(struct Vec2d v);
float vec2d_get_angle(float x, float y);
bool vec2d_equal(struct Vec2d v0, struct Vec2d v1);
float vec2d_get_length(float x, float y);
struct Vec2d vec2d_negate(struct Vec2d v);
struct Vec2d vec2d_normalize(float x, float y);
struct Vec2d vec2d_scale(struct Vec2d v, float s);
struct Vec2d vec2d_scale_c(float x, float y, float s);
struct Vec2d vec2d_xy_to_al(struct Vec2d v);

#endif