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

@@ -113,7 +113,6 @@ void registerTile(char fname[20], SDL_Renderer *renderer) {
};
// printf("Bound %s to %d orient %s\n", fname, indexTile, OrientStrings[o]);
TileRegistry[indexTile].animation.textures[o][frame] = textures[o];
SDL_SetTextureBlendMode(textures[o], SDL_BLENDMODE_BLEND);
TileRegistry[indexTile].animation.atlasRects[o][frame] = allocate_32x32(textures[o], renderer);
}
@@ -126,6 +125,10 @@ void registerTile(char fname[20], SDL_Renderer *renderer) {
TileRegistry[indexTile].type = tileTypeIndex;
TileRegistry[indexTile].breakTime = 15;
TileRegistry[indexTile].itemMoves = false;
TileRegistry[indexTile].walkable = false;
TileRegistry[indexTile].needsTicks = false;
TileRegistry[indexTile].updateTileCallback = NULL;
if (indexTile + 1 > tileTypeIndex) {
tileTypeIndex = indexTile + 1;
@@ -159,7 +162,6 @@ void registerBackgroundTile(char fname[20], SDL_Renderer *renderer) {
//printf("Bound %s to %d\n", fname, indexBgTile);
BackgroundTileRegistry[indexBgTile].animation.textures[frame] = texture;
BackgroundTileRegistry[indexBgTile].animation.atlasRects[frame] = allocate_32x32(texture, renderer);
BackgroundTileRegistry[indexBgTile].type = indexBgTile;
@@ -257,6 +259,17 @@ void loadBackgroundTiles(SDL_Renderer *renderer) {
}
}
void preSetupTiles() {
TileRegistry[TYPE_MINER].animation.startFrame = 1;
TileRegistry[TYPE_FURNACE].animation.divisor = 8;
TileRegistry[TYPE_CORE].animation.divisor = 8;
BackgroundTileRegistry[BGType_WATER_DEEP].animation.divisor = 16;
BackgroundTileRegistry[BGType_WATER_SHALLOW].animation.divisor = 12;
BackgroundTileRegistry[BGType_GRASS_FLOWER0].animation.divisor = 16;
BackgroundTileRegistry[BGType_GRASS_FLOWER1].animation.divisor = 16;
BackgroundTileRegistry[BGType_GRASS_FLOWER2].animation.divisor = 16;
}
void setupTiles() {
TileRegistry[TYPE_AIR].breakTime = 0;
TileRegistry[TYPE_BELT].itemMoves = true;
@@ -268,33 +281,34 @@ void setupTiles() {
TileRegistry[TYPE_BELT].allowedInItems[l][i] = true;
}
}
for (ItemType i = 0; i < itemRegistryIndex; i++) {
if (FurnaceRecipes[i] != 0) {
TileRegistry[TYPE_FURNACE].allowedInItems[FURNACE_INPUT_SLOT][i] = true;
}
TileRegistry[TYPE_SPLITTER].allowedInItems[0][i] = true;
}
; TileRegistry[TYPE_FURNACE].outputLane[FURNACE_OUTPUT_SLOT] = 1;
TileRegistry[TYPE_FURNACE].startFrame = 1;
TileRegistry[TYPE_SPLITTER].outputLane[0] = true;
TileRegistry[TYPE_SPLITTER].needsTicks = true;
TileRegistry[TYPE_SPLITTER].walkable = true;
TileRegistry[TYPE_SPLITTER].allDir = true;
TileRegistry[TYPE_FURNACE].outputLane[FURNACE_OUTPUT_SLOT] = 1;
TileRegistry[TYPE_FURNACE].animation.startFrame = 1;
TileRegistry[TYPE_FURNACE].needsTicks = true;
TileRegistry[TYPE_FURNACE].animation.divisor = 8;
TileRegistry[TYPE_BELT].needsTicks = true;
TileRegistry[TYPE_BELT].walkable = true;
TileRegistry[TYPE_MINER].needsTicks = true;
TileRegistry[TYPE_MINER].outputLane[MINER_OUTPUT_SLOT] = 1;
TileRegistry[TYPE_MINER].startFrame = 1;
TileRegistry[TYPE_AIR].walkable = true;
TileRegistry[TYPE_TURRET].needsTicks = true;
TileRegistry[TYPE_TURRET].allowedInItems[TURRET_AMMO_INPUT_SLOT][IRON_INGOT] = true;
for (ItemType i = 0; i < ITEMREGISTRY_SIZE; i++) {
if (AmmoDamages[i] > 0)
TileRegistry[TYPE_TURRET].allowedInItems[TURRET_AMMO_INPUT_SLOT][i] = true;
}
BackgroundTileRegistry[BGType_WATER_DEEP].animation.divisor = 16;
BackgroundTileRegistry[BGType_WATER_SHALLOW].animation.divisor = 12;
BackgroundTileRegistry[BGType_GRASS_FLOWER0].animation.divisor = 16;
BackgroundTileRegistry[BGType_GRASS_FLOWER1].animation.divisor = 16;
BackgroundTileRegistry[BGType_GRASS_FLOWER2].animation.divisor = 16;
BackgroundTileRegistry[BGType_WATER_SHALLOW].walkable = false;
BackgroundTileRegistry[BGType_WATER_DEEP].walkable = false;
initFurnaceTile();
}
uint16_t getBreakTime(int type) {
@@ -358,8 +372,6 @@ void renderAllTiles(SDL_Renderer *renderer, SDL_Rect playerRect) {
printf("Error on tile %d, %d\n", x, y);
backgroundMap[y][x].type = BGType_PLATINUM_ORE;
} else {
SDL_Texture *tex = BackgroundTileRegistry[bt.type].animation.textures[animationStep %
BackgroundTileRegistry[bt.type].animation.frameCount];
SDL_Rect atlRect = BackgroundTileRegistry[bt.type].animation.atlasRects[
(animationStep / BackgroundTileRegistry[bt.type].animation.divisor) %
BackgroundTileRegistry[bt.type].animation.frameCount];
@@ -396,20 +408,23 @@ void renderAllTiles(SDL_Renderer *renderer, SDL_Rect playerRect) {
default: {
char animationFrame = ((animationStep / TileRegistry[t.type].animation.divisor) %
(TileRegistry[t.type].animation.frameCount -
TileRegistry[t.type].startFrame)) + TileRegistry[t.type].startFrame;
TileRegistry[t.type].animation.startFrame)) +
TileRegistry[t.type].animation.startFrame;
if (t.fixedFrame > 0) {
animationFrame = t.fixedFrame - 1;
}
SDL_Rect atlRect = TileRegistry[t.type].animation.atlasRects[t.direction][animationFrame];
SDL_Texture *tex = TileRegistry[t.type].animation.textures[t.direction][animationFrame];
if (atlRect.w == 0 || atlRect.h == 0) {
tex = TileRegistry[t.type].animation.textures[ORIENT_LEFT][animationFrame];
atlRect = TileRegistry[t.type].animation.atlasRects[ORIENT_LEFT][
animationFrame];
}
if (atlRect.w != 0 && atlRect.h != 0) {
//SDL_RenderCopy(renderer, tex, NULL, &dstRect);
SDL_RenderCopy(renderer, atlasTexture, &atlRect, &dstRect);
if (t.health < TileRegistry[t.type].maxHealth) {
char healthStr[12];
snprintf(healthStr, 12, "%d/%d", t.health, TileRegistry[t.type].maxHealth);
renderText(renderer, fonts[3], healthStr, dstRect.x, dstRect.y);
}
// if (t.health < TileRegistry[t.type].maxHealth) {
// SDL_Color tileHealthColor = {(t.health / TileRegistry[t.type].maxHealth ) * 255, (TileRegistry[t.type].maxHealth / t.health) * 255, 0, 255};
// renderBar(mainRenderer, x * TILE_SIZE, (y * TILE_SIZE) + (TILE_SIZE / 2), TILE_SIZE, 8,
@@ -439,7 +454,7 @@ void renderAllTiles(SDL_Renderer *renderer, SDL_Rect playerRect) {
.h = TILE_SIZE
};
adjustRect(&dstRect, playerRect);
renderText(renderer, fonts[3], locChar, dstRect.x, dstRect.y);
renderText(renderer, fonts[4], locChar, dstRect.x, dstRect.y);
}
if (t.type == TYPE_BELT || itemViewing) {
for (uint8_t lane = 0; lane < ItemSlotCount; lane++) {