This commit is contained in:
2025-06-08 17:22:30 +02:00
parent 64cac7578d
commit 79c8b747cd
16 changed files with 686 additions and 79 deletions

View File

@@ -104,10 +104,10 @@ void registerTile(char fname[20], SDL_Renderer *renderer) {
NULL,
texture,
NULL,
createFlippedTexture(renderer, texture, SDL_FLIP_HORIZONTAL),
NULL,
createRotatedTexture(renderer, texture, 90),
NULL,
createFlippedTexture(renderer, texture, SDL_FLIP_HORIZONTAL),
NULL,
createRotatedTexture(renderer, texture, 270)
};
@@ -118,6 +118,7 @@ void registerTile(char fname[20], SDL_Renderer *renderer) {
}
TileRegistry[indexTile].type = indexTile;
TileRegistry[indexTile].maxHealth = 200;
TileRegistry[indexTile].animation.frameCount = frame + 1;
TileRegistry[indexTile].animation.divisor = 1;
@@ -162,18 +163,13 @@ void registerBackgroundTile(char fname[20], SDL_Renderer *renderer) {
BackgroundTileRegistry[indexBgTile].type = indexBgTile;
BackgroundTileRegistry[indexBgTile].animation.frameCount = frame + 1;
BackgroundTileRegistry[indexBgTile].animation.divisor = 1;
BackgroundTileRegistry[indexBgTile].walkable = true;
if (indexBgTile + 1 > backgroundTileTypeIndex) {
backgroundTileTypeIndex = indexBgTile + 1;
}
}
int compareStrings(const void *a, const void *b) {
const char *strA = *(const char **) a;
const char *strB = *(const char **) b;
return strcmp(strA, strB);
}
void loadTiles(SDL_Renderer *renderer) {
DIR *dir = opendir("./assets/tiles");
if (!dir) {
@@ -281,15 +277,19 @@ void setupTiles() {
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;
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;
}
uint16_t getBreakTime(int type) {
@@ -347,14 +347,21 @@ void renderAllTiles(SDL_Renderer *renderer, SDL_Rect playerRect) {
adjustRect(&dstRect, playerRect);
BackgroundTile bt = backgroundMap[y][x];
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];
if (atlRect.w != 0 && atlRect.h != 0) {
SDL_RenderCopy(renderer, atlasTexture, &atlRect, &dstRect);
//SDL_RenderCopy(renderer, tex, NULL, &dstRect);
if (bt.type > BGType_END) {
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderFillRect(renderer, &dstRect);
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];
if (atlRect.w != 0 && atlRect.h != 0) {
SDL_RenderCopy(renderer, atlasTexture, &atlRect, &dstRect);
//SDL_RenderCopy(renderer, tex, NULL, &dstRect);
}
}
}
}
@@ -398,6 +405,11 @@ void renderAllTiles(SDL_Renderer *renderer, SDL_Rect playerRect) {
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) {
// 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,
// TileRegistry[t.type].maxHealth, t.health, tileHealthColor, 4);
// }
}
}
}
@@ -437,6 +449,13 @@ void renderAllTiles(SDL_Renderer *renderer, SDL_Rect playerRect) {
SDL_SetRenderTarget(renderer, oldTarget);
}
bool isWalkable(MiniRect tileCoords) {
BackgroundTileType bgt = BackgroundTileRegistry[backgroundMap[tileCoords.y][tileCoords.x].type];
TileTypeReg fgt = TileRegistry[tileMap[tileCoords.y][tileCoords.x].type];
return bgt.walkable && fgt.walkable;
}
void updateTiles() {
}