blob: 5a4a4acb3ecee23f84ea989c89a17f405d8787dd (
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
|
#ifndef UTILS_H_
#define UTILS_H_
#include <stdbool.h>
#include "game.h"
#define UNUSED(x) (void)x
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 int AddSpriteToEntity(Entity* e, Sprite s) {
if (e->numSprites < MAX_SPRITE_COUNT) {
e->sprites[e->numSprites++] = s;
}
return e->numSprites - 1;
}
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];
}
static inline Rectangle GetCurrentSourceRectangle(const Animation* animation) {
return animation->srcRects[animation->currentFrame];
}
#endif // UTILS_H_
|