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

51
main.c
View File

@@ -83,6 +83,7 @@ const int delayNeeded = 1000 / targetFPS;
#define smallFont fonts[1]
#define smallerFont fonts[2]
#define smallestFont fonts[3]
#define reallySmallestFont fonts[4]
char *autosaveName = "autosave.dat";
@@ -150,11 +151,12 @@ int init() {
loadBackgroundTiles(mainRenderer);
loadTiles(mainRenderer);
preSetupTiles();
loadItems(mainRenderer);
loadEntities(mainRenderer);
setupTiles();
// for (ItemType i = 0; i < ITEMREGISTRY_SIZE; i++) {
// if (strlen(ItemRegistry[i].name)) {
// printf("%d -> %s\n", i, ItemRegistry[i].name);
@@ -206,10 +208,11 @@ int init() {
SDL_RenderSetViewport(mainRenderer, &viewport);
SDL_SetRenderDrawBlendMode(mainRenderer, SDL_BLENDMODE_BLEND);
biggerFont = prepText(mainRenderer, 16, "assets/PublicPixel.ttf", 255, 255, 255, 255);
smallFont = prepText(mainRenderer, 12, "assets/PublicPixel.ttf", 255, 255, 255, 255);
smallerFont = prepText(mainRenderer, 8, "assets/PublicPixel.ttf", 255, 255, 255, 255);
smallestFont = prepText(mainRenderer, 4, "assets/PublicPixel.ttf", 255, 255, 255, 255);
biggerFont = prepText(mainRenderer, 32, "assets/PublicPixel.ttf");
smallFont = prepText(mainRenderer, 16, "assets/PublicPixel.ttf");
smallerFont = prepText(mainRenderer, 12, "assets/PublicPixel.ttf");
smallestFont = prepText(mainRenderer, 8, "assets/PublicPixel.ttf");
reallySmallestFont = prepText(mainRenderer, 4, "assets/PublicPixel.ttf");
SDL_RenderSetLogicalSize(mainRenderer, DISPLAY_WIDTH, DISPLAY_HEIGHT);
initPlayer(&player);
@@ -250,6 +253,17 @@ int render() {
} else {
SDL_RenderCopy(mainRenderer, atlasTexture, &rect2, &rect2);
unsigned int ix = ATLAS_SIZE;
for (unsigned char i = 1; i < fontCount; i++) {
SDL_Rect tmpRectFont = fonts[i].atlasRect;
tmpRectFont.x += ix;
SDL_RenderCopy(mainRenderer, fonts[i].atlas, &fonts[i].atlasRect, &tmpRectFont);
ix += fonts[i].atlasRect.w;
}
SDL_Rect tmpRectFont = fonts[0].atlasRect;
tmpRectFont.x += ATLAS_SIZE;
tmpRectFont.y = fonts[1].atlasRect.h;
SDL_RenderCopy(mainRenderer, fonts[0].atlas, &fonts[0].atlasRect, &tmpRectFont);
}
@@ -546,6 +560,31 @@ void processKeyboardHeld() {
setActivePlayerSlot(&player, 0);
}
}
if (keyboardState[SDL_SCANCODE_E]) {
if (player.cursor.targetTile->health < TileRegistry[player.cursor.targetTile->type].maxHealth) {
player.cursor.targetTile->health++;
}
for (int x = playerTileX - 2; x < playerTileX + 2; x++) {
if (x < 0) {
continue;
}
if (x >= MAP_WIDTH) {
continue;
}
for (int y = playerTileY - 2; y < playerTileY + 2; y++) {
if (y < 0) {
continue;
}
if (y >= MAP_HEIGHT) {
continue;
}
Tile *t = &tileMap[y][x];
if (t->health < TileRegistry[t->type].maxHealth) {
t->health++;
}
}
}
}
if (keyboardState[SDL_SCANCODE_F9]) {
player.inventory.slotCounts[player.inventory.activeSlotIndex]++;
}
@@ -649,7 +688,7 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char *args[])
}
}
updateItems();
updateEntities();
updateEntities(&player);
updatePlayer(&player);
updateTiles();
animationStep++;