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

@@ -30,8 +30,9 @@ SDL_Color breakingBarColor = {128, 128, 0, 255};
void setActivePlayerSlot(Player *plr, ItemType activeSlotIndex) {
activeSlotIndex = activeSlotIndex % itemRegistryIndex;
if((activeSlotIndex < tileTypeIndex || (activeSlotIndex < itemRegistryIndex && activeSlotIndex >= ITEMREGISTRY_SIZE / 2)) && activeSlotIndex > 0) {
plr->inventory.activeSlotIndex = activeSlotIndex;
if ((activeSlotIndex < tileTypeIndex ||
(activeSlotIndex < itemRegistryIndex && activeSlotIndex >= ITEMREGISTRY_SIZE / 2)) && activeSlotIndex > 0) {
plr->inventory.activeSlotIndex = activeSlotIndex;
}
}
@@ -149,15 +150,27 @@ void initPlayer(Player *plr) {
}
void updatePlayer(Player *plr) {
if (plr->health == plr->prevHealth && plr->healthIdle < neededHealthIdle) {
plr->healthIdle++;
if (plr->health == plr->prevHealth) {
if (plr->healthIdle < neededHealthIdle)
plr->healthIdle++;
} else {
plr->healthIdle = 0; // Reset if health changed (e.g., took damage or regen happened)
}
if (plr->health < playerMaxHealth && plr->healthIdle >= neededHealthIdle) {
plr->health++;
// Dont reset healthIdle here — only reset if something changes externally
}
plr->prevHealth = plr->health;
if (plr->health <= 0) {
plr->rect.x = DISPLAY_WIDTH / 2;
plr->rect.y = DISPLAY_HEIGHT / 2;
}
}
void renderPlayer(Player *plr) {
SDL_Texture *originalTarget = SDL_GetRenderTarget(mainRenderer);
@@ -176,26 +189,39 @@ void renderPlayer(Player *plr) {
ItemType itemIndex = plr->inventory.activeSlotIndex;
//SDL_Texture *itemTex;
char itemStringCount[6];
if ((itemIndex < tileTypeIndex || (itemIndex < itemRegistryIndex && itemIndex >= ITEMREGISTRY_SIZE / 2)) && itemIndex > 0) {
if ((itemIndex < tileTypeIndex || (itemIndex < itemRegistryIndex && itemIndex >= ITEMREGISTRY_SIZE / 2)) &&
itemIndex > 0) {
plr->cursor.heldItemRect.x = plr->cursor.windowX;
plr->cursor.heldItemRect.y = plr->cursor.windowY;
//itemTex = ItemRegistry[itemIndex].textureOnBelt[plr->cursor.direction];
SDL_Rect itemAtlasRect = ItemRegistry[itemIndex].animation.atlasRects[plr->cursor.direction][(animationStep / ItemRegistry[itemIndex].animation.divisor) % ItemRegistry[itemIndex].animation.frameCount];
SDL_Rect itemAtlasRect = ItemRegistry[itemIndex].animation.atlasRects[plr->cursor.direction][(
(animationStep /
ItemRegistry[itemIndex].beltAnimation.divisor) %
(
ItemRegistry[itemIndex].beltAnimation.frameCount -
ItemRegistry[itemIndex].beltAnimation.startFrame)) +
ItemRegistry[itemIndex].beltAnimation.startFrame];
if (itemAtlasRect.w == 0 || itemAtlasRect.h == 0) {
itemAtlasRect = ItemRegistry[itemIndex].animation.atlasRects[ORIENT_LEFT][(animationStep / ItemRegistry[itemIndex].animation.divisor) % ItemRegistry[itemIndex].animation.frameCount];
itemAtlasRect = ItemRegistry[itemIndex].animation.atlasRects[ORIENT_LEFT][(
(animationStep /
ItemRegistry[itemIndex].beltAnimation.divisor) %
(
ItemRegistry[itemIndex].beltAnimation.frameCount -
ItemRegistry[itemIndex].beltAnimation.startFrame)) +
ItemRegistry[itemIndex].beltAnimation.startFrame];
}
if (itemAtlasRect.w != 0 && itemAtlasRect.h != 0) {
// if (plr->inventory.slotCounts[itemIndex] <= 0) {
// // Set a red tint (255, 0, 0)
// SDL_SetTextureColorMod(itemTex, 128, 128, 255);
//
// SDL_SetTextureAlphaMod(itemTex, 192);
// } else {
// SDL_SetTextureColorMod(itemTex, 255, 255, 255);
//
// SDL_SetTextureAlphaMod(itemTex, 255);
// }
if (plr->inventory.slotCounts[itemIndex] <= 0) {
// Set a red tint (255, 0, 0)
SDL_SetTextureColorMod(atlasTexture, 128, 128, 255);
SDL_SetTextureAlphaMod(atlasTexture, 230);
} else {
SDL_SetTextureColorMod(atlasTexture, 255, 255, 255);
SDL_SetTextureAlphaMod(atlasTexture, 255);
}
// SDL_RenderCopy(mainRenderer, itemTex, NULL,
// &plr->cursor.heldItemRect);
char nameItem[80];
@@ -204,6 +230,9 @@ void renderPlayer(Player *plr) {
renderText(mainRenderer, fonts[2], nameItem, plr->cursor.heldItemRect.x,
plr->cursor.heldItemRect.y - (fonts[2].size * 3 / 2));
}
SDL_SetTextureAlphaMod(atlasTexture, 255);
SDL_SetTextureColorMod(atlasTexture, 255, 255, 255);
}
@@ -213,7 +242,7 @@ void renderPlayer(Player *plr) {
if (plr->cursor.targetTile) {
uint16_t tempko = getBreakTime(plr->cursor.targetTile->type);
uint16_t tempko2 = plr->cursor.breakingProgress;
renderBar(mainRenderer, (DISPLAY_WIDTH / 2) - 128, DISPLAY_HEIGHT - 90, 200, 8,
renderBar(mainRenderer, (DISPLAY_WIDTH / 2) - 128, DISPLAY_HEIGHT - 110, 200, 8,
tempko, tempko2, breakingBarColor, 4);
}
@@ -229,17 +258,29 @@ void renderPlayer(Player *plr) {
if (ItemRegistry[i].name[0] == 0x00) {
continue;
}
SDL_Rect itemAtlasRectd = ItemRegistry[i].animation.atlasRects[plr->cursor.direction][(animationStep / ItemRegistry[i].animation.divisor) % ItemRegistry[i].animation.frameCount];
SDL_Rect itemAtlasRectd = ItemRegistry[i].animation.atlasRects[plr->cursor.direction][(
(animationStep /
ItemRegistry[i].beltAnimation.divisor) %
(
ItemRegistry[i].beltAnimation.frameCount -
ItemRegistry[i].beltAnimation.startFrame)) +
ItemRegistry[i].beltAnimation.startFrame];
if (itemAtlasRectd.w == 0 || itemAtlasRectd.h == 0) {
itemAtlasRectd = ItemRegistry[i].animation.atlasRects[ORIENT_LEFT][(animationStep / ItemRegistry[i].animation.divisor) % ItemRegistry[i].animation.frameCount];
itemAtlasRectd = ItemRegistry[i].animation.atlasRects[ORIENT_LEFT][(
(animationStep /
ItemRegistry[i].beltAnimation.divisor) %
(
ItemRegistry[i].beltAnimation.frameCount -
ItemRegistry[i].beltAnimation.startFrame)) +
ItemRegistry[i].beltAnimation.startFrame];
}
if (itemAtlasRectd.w != 0 && itemAtlasRectd.h != 0) {
// if (plr->inventory.slotCounts[i] <= 0) {
// // Set a red tint (255, 0, 0)
// SDL_SetTextureColorMod(itemTex, 128, 128, 255);
// }
if (plr->inventory.slotCounts[i] <= 0) {
// Set a red tint (255, 0, 0)
SDL_SetTextureColorMod(atlasTexture, 128, 128, 255);
}
SDL_RenderCopy(mainRenderer, atlasTexture, &itemAtlasRectd, &targetItemRect);
//SDL_SetTextureColorMod(itemTex, 255, 255, 255);
SDL_SetTextureColorMod(atlasTexture, 255, 255, 255);
if (plr->inventory.activeSlotIndex == i) {
SDL_SetRenderDrawColor(mainRenderer, 16, plr->inventory.slotCounts[i] > 0 ? 128 : 16,