summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/background.c1
-rw-r--r--src/game.c45
-rw-r--r--src/physics.c13
-rw-r--r--src/player.c1
4 files changed, 34 insertions, 26 deletions
diff --git a/src/background.c b/src/background.c
index d3588a7..c9ed1fb 100644
--- a/src/background.c
+++ b/src/background.c
@@ -3,6 +3,7 @@
#include <raymath.h>
#include <assert.h>
#include <stdlib.h>
+#include "utils.h"
void AddBackground(const char* backgroundTextureName) {
Entity e = {0};
diff --git a/src/game.c b/src/game.c
index 55b65c2..8659939 100644
--- a/src/game.c
+++ b/src/game.c
@@ -8,23 +8,10 @@
#include "player.h"
#include "background.h"
#include <math.h>
+#include "utils.h"
Game game;
-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;
-}
-
void AddEntity(Entity* e) {
static int nextId = 0;
@@ -158,3 +145,33 @@ void AddWall(float xpos, float ypos, float width, float height) {
AddEntity(&wall);
}
+
+static inline float GetCurrentFrameTime(const Animation* animation) {
+ return animation->frameTimes[animation->currentFrame];
+}
+
+void UpdateCurrentSpriteAnimation(Sprite* sprite, float dt) {
+ if (!IsAnimated(sprite))
+ return;
+
+ Animation* currentAnimation = GetCurrentAnimation(sprite);
+
+ if (currentAnimation->isComplete)
+ return;
+
+ currentAnimation->currentFrameTimer += dt;
+
+ if (currentAnimation->currentFrameTimer >= GetCurrentFrameTime(currentAnimation)) {
+ currentAnimation->currentFrame++;
+ currentAnimation->currentFrameTimer = 0;
+ }
+
+ if (currentAnimation->currentFrame >= currentAnimation->numFrames) {
+ if (currentAnimation->isLooping)
+ currentAnimation->currentFrame = 0;
+ else {
+ currentAnimation->currentFrame = currentAnimation->numFrames - 1;
+ currentAnimation->isComplete = true;
+ }
+ }
+}
diff --git a/src/physics.c b/src/physics.c
index 51e80f5..bc93a29 100644
--- a/src/physics.c
+++ b/src/physics.c
@@ -1,20 +1,9 @@
#include "physics.h"
#include "game.h"
+#include "utils.h"
extern Game game;
-static inline bool PhysicsEnabled(const Entity* e) {
- return EntityAllocated(e) && (e->flags & ENTITY_PHYSICS_ACTIVE);
-}
-
-static inline Rectangle GetPhysicsColliderGlobal(const Entity* e) {
- Rectangle physicsColliderGlobal = e->physicsCollider;
- physicsColliderGlobal.x += e->position.x;
- physicsColliderGlobal.y += e->position.y;
-
- return physicsColliderGlobal;
-}
-
void MoveAndSlide(Entity* e, float deltaTime) {
Vector2 velocity = e->velocity;
Rectangle physicsCollider = GetPhysicsColliderGlobal(e);
diff --git a/src/player.c b/src/player.c
index 67f971f..62675f4 100644
--- a/src/player.c
+++ b/src/player.c
@@ -5,6 +5,7 @@
#include "player.h"
#include "physics.h"
#include "assets.h"
+#include "utils.h"
extern Game game;