blob: 74378605e1555754e1c7e9421eef9c7b04d68a5c (
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
76
77
78
79
80
81
82
83
84
85
86
|
#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];
}
static inline Rectangle GetEntityHitboxGlobal(const Entity* e, int hbIndex) {
Rectangle hitBoxGlobal = e->hitBoxes[hbIndex];
hitBoxGlobal.x += e->position.x;
hitBoxGlobal.y += e->position.y;
return hitBoxGlobal;
}
static inline Rectangle GetEntityHurtboxGlobal(const Entity* e, int hbIndex) {
Rectangle hurtBoxGlobal = e->hurtBoxes[hbIndex];
hurtBoxGlobal.x += e->position.x;
hurtBoxGlobal.y += e->position.y;
return hurtBoxGlobal;
}
static inline void ResetAnimation(Animation* animation) {
animation->currentFrame = 0;
animation->currentFrameTimer = 0;
animation->isComplete = false;
}
#endif // UTILS_H_
|