Most texure work

This commit is contained in:
2025-06-10 21:59:51 +02:00
parent a17e3abbff
commit 39c31f0042
103 changed files with 666 additions and 246 deletions

View File

@@ -9,10 +9,15 @@
#include "../player/player.h"
#include "../items/item.h"
#include "../util/atlas.h"
#include "../util/font.h"
void generateBeltFrames(SDL_Renderer *renderer) {
SDL_Texture *baseTexture = TileRegistry[TYPE_BELT].animation.textures[ORIENT_LEFT][0]; // Base belt tile
SDL_Texture *baseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET,
TILE_SIZE,
TILE_SIZE);
SDL_Texture *oldTarget = SDL_GetRenderTarget(renderer);
SDL_SetRenderTarget(renderer, baseTexture);
SDL_RenderCopy(renderer, atlasTexture, &TileRegistry[TYPE_BELT].animation.atlasRects[ORIENT_LEFT][0], NULL);
const int frameCount = TILE_SIZE; // 32 frames, 1px per frame = full seamless loop
for (OrientDirection dir = ORIENT_LEFT_DOWN; dir < ORIENT_DIRECTION_COUNT; dir++) {
@@ -79,7 +84,6 @@ void generateBeltFrames(SDL_Renderer *renderer) {
SDL_RenderCopy(renderer, rotated, NULL, &dst1);
SDL_RenderCopy(renderer, rotated, NULL, &dst2);
TileRegistry[TYPE_BELT].animation.textures[dir][f] = frame;
TileRegistry[TYPE_BELT].animation.atlasRects[dir][f] = allocate_32x32(frame, renderer);
}
@@ -88,6 +92,7 @@ void generateBeltFrames(SDL_Renderer *renderer) {
TileRegistry[TYPE_BELT].animation.divisor = 1;
}
SDL_DestroyTexture(baseTexture);
SDL_SetRenderTarget(renderer, oldTarget);
}
@@ -103,4 +108,9 @@ void renderBelt(int x, int y, int w, int h, OrientDirection dir, SDL_Rect player
(animationStep / TileRegistry[TYPE_BELT].animation.divisor) %
TileRegistry[TYPE_BELT].animation.frameCount],
&dst);
if (tileMap[y][x].health < TileRegistry[TYPE_BELT].maxHealth) {
char healthStr[12];
snprintf(healthStr, 12, "%d/%d", tileMap[y][x].health, TileRegistry[tileMap[y][x].type].maxHealth);
renderText(renderer, fonts[3], healthStr, dst.x, dst.y);
}
}