diff options
Diffstat (limited to 'include/utils.h')
-rw-r--r-- | include/utils.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/include/utils.h b/include/utils.h new file mode 100644 index 0000000..59c1bc4 --- /dev/null +++ b/include/utils.h @@ -0,0 +1,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_ |