summaryrefslogtreecommitdiff
path: root/include/utils.h
blob: 59c1bc40f186a032427be4aa7c4877d8d8fbb1c9 (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
#ifndef UTILS_H_
#define UTILS_H_

#include <stdbool.h>
#include "game.h"

static inline bool EntityAllocated(const Entity* e) {
    return (e->flags & ENTITY_ALLOCATED);
}

static inline bool PhysicsEnabled(const Entity* e) {
    return EntityAllocated(e) && (e->flags & ENTITY_PHYSICS_ACTIVE);
}

static inline bool SameEntity(const Entity* a, const Entity* b) {
    return a->id == b->id;
}

static inline void AddSpriteToEntity(Entity* e, Sprite s) {
    if (e->numSprites < MAX_SPRITE_COUNT) {
        e->sprites[e->numSprites++] = s;
    }
}

static inline bool IsAnimated(const Sprite* s) {
  return s->numAnimations > 0;
}

static inline bool ShouldDrawEntity(const Entity* e, DrawLayer layerDrawing) {
    return EntityAllocated(e)
        && (e->flags & ENTITY_VISIBLE);
}

static inline Rectangle GetSpriteDrawDestinationRectGlobal(const Entity* e, int spriteIndex) {
    Rectangle destRectGlobal = e->sprites[spriteIndex].destRect;

    destRectGlobal.x += e->position.x;
    destRectGlobal.y += e->position.y;

    return destRectGlobal;
}

static inline Rectangle GetPhysicsColliderGlobal(const Entity* e) {
    Rectangle physicsColliderGlobal = e->physicsCollider;
    physicsColliderGlobal.x += e->position.x;
    physicsColliderGlobal.y += e->position.y;

    return physicsColliderGlobal;
}

static inline Animation* GetCurrentAnimation(Sprite* s) {
    return &s->animations[s->currentAnimation];
}

#endif // UTILS_H_