From 87d07175058ee4ae18fce608de81c68d7d9bb178 Mon Sep 17 00:00:00 2001 From: BoredGuy Date: Tue, 26 Aug 2025 12:33:32 +0300 Subject: Player Improvements --- src/game.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/game.c') diff --git a/src/game.c b/src/game.c index 4a10830..d6e8ce3 100644 --- a/src/game.c +++ b/src/game.c @@ -87,6 +87,12 @@ void DrawEntitySprite(const Entity* e, int spriteIndex) { float rotation = 0.0f; Rectangle destRect = GetSpriteDrawDestinationRectGlobal(e, spriteIndex); + if (drawnSprite->flipX) + srcRect.width = -srcRect.width; + + if (drawnSprite->flipY) + srcRect.height = -srcRect.width; + DrawTexturePro(drawnSprite->texture, srcRect, destRect, origin, rotation, WHITE); } @@ -193,3 +199,39 @@ void UpdateCurrentSpriteAnimation(Sprite* sprite, float dt) { } } } + +Rectangle GetSrcRectFromIndex(Texture texture, int framesX, int framesY, int index) { + const float frameWidth = (float)texture.width / framesX; + const float frameHeight = (float)texture.height / framesY; + + return (Rectangle) { + .x = (index % framesY) * frameWidth, + .y = (index / framesY) * frameHeight, + .width = frameWidth, + .height = frameHeight + }; +} + +Animation AnimationFromIndices(AnimationFromIndicesParams params) { + int numFrames = params.numFrames; + bool isLooping = params.isLooping; + Texture texture = params.texture; + int framesX = params.framesX; + int framesY = params.framesY; + int* indices = params.indices; + float* frameTimes = params.frameTimes; + + Animation animation = (Animation) { + .numFrames = numFrames, + .isLooping = isLooping, + + .currentFrame = 0 + }; + + for (int i = 0; i < numFrames; i++) { + animation.srcRects[i] = GetSrcRectFromIndex(texture, framesX, framesY, indices[i]); + animation.frameTimes[i] = frameTimes[i]; + } + + return animation; +} -- cgit v1.2.3