From 9ce0701cc748f79e880df476d64f7e2732143585 Mon Sep 17 00:00:00 2001 From: Jonathan Hager Date: Mon, 16 Jan 2023 16:41:12 +0100 Subject: [PATCH] Zwischenstand2 --- Sprite/sprite.c | 10 +- Textures/textureatlas.c | 145 ++++++++++++++++-- Textures/textureatlas.h | 7 +- .../worker/{umackern-0.png => arbeiten-0.png} | Bin .../worker/{umackern-1.png => arbeiten-1.png} | Bin .../{umackern-10.png => arbeiten-10.png} | Bin .../{umackern-11.png => arbeiten-11.png} | Bin .../{umackern-12.png => arbeiten-12.png} | Bin .../{umackern-13.png => arbeiten-13.png} | Bin .../{umackern-14.png => arbeiten-14.png} | Bin .../{umackern-15.png => arbeiten-15.png} | Bin .../{umackern-16.png => arbeiten-16.png} | Bin .../{umackern-17.png => arbeiten-17.png} | Bin .../{umackern-18.png => arbeiten-18.png} | Bin .../{umackern-19.png => arbeiten-19.png} | Bin .../worker/{umackern-2.png => arbeiten-2.png} | Bin .../{umackern-20.png => arbeiten-20.png} | Bin .../{umackern-21.png => arbeiten-21.png} | Bin .../{umackern-22.png => arbeiten-22.png} | Bin .../{umackern-23.png => arbeiten-23.png} | Bin .../{umackern-24.png => arbeiten-24.png} | Bin .../worker/{umackern-3.png => arbeiten-3.png} | Bin .../worker/{umackern-4.png => arbeiten-4.png} | Bin .../worker/{umackern-5.png => arbeiten-5.png} | Bin .../worker/{umackern-6.png => arbeiten-6.png} | Bin .../worker/{umackern-7.png => arbeiten-7.png} | Bin .../worker/{umackern-8.png => arbeiten-8.png} | Bin .../worker/{umackern-9.png => arbeiten-9.png} | Bin .../worker/{umackern.png => arbeiten.png} | Bin .../building/idle.png} | Bin 30 files changed, 140 insertions(+), 22 deletions(-) rename assets/entities/worker/{umackern-0.png => arbeiten-0.png} (100%) rename assets/entities/worker/{umackern-1.png => arbeiten-1.png} (100%) rename assets/entities/worker/{umackern-10.png => arbeiten-10.png} (100%) rename assets/entities/worker/{umackern-11.png => arbeiten-11.png} (100%) rename assets/entities/worker/{umackern-12.png => arbeiten-12.png} (100%) rename assets/entities/worker/{umackern-13.png => arbeiten-13.png} (100%) rename assets/entities/worker/{umackern-14.png => arbeiten-14.png} (100%) rename assets/entities/worker/{umackern-15.png => arbeiten-15.png} (100%) rename assets/entities/worker/{umackern-16.png => arbeiten-16.png} (100%) rename assets/entities/worker/{umackern-17.png => arbeiten-17.png} (100%) rename assets/entities/worker/{umackern-18.png => arbeiten-18.png} (100%) rename assets/entities/worker/{umackern-19.png => arbeiten-19.png} (100%) rename assets/entities/worker/{umackern-2.png => arbeiten-2.png} (100%) rename assets/entities/worker/{umackern-20.png => arbeiten-20.png} (100%) rename assets/entities/worker/{umackern-21.png => arbeiten-21.png} (100%) rename assets/entities/worker/{umackern-22.png => arbeiten-22.png} (100%) rename assets/entities/worker/{umackern-23.png => arbeiten-23.png} (100%) rename assets/entities/worker/{umackern-24.png => arbeiten-24.png} (100%) rename assets/entities/worker/{umackern-3.png => arbeiten-3.png} (100%) rename assets/entities/worker/{umackern-4.png => arbeiten-4.png} (100%) rename assets/entities/worker/{umackern-5.png => arbeiten-5.png} (100%) rename assets/entities/worker/{umackern-6.png => arbeiten-6.png} (100%) rename assets/entities/worker/{umackern-7.png => arbeiten-7.png} (100%) rename assets/entities/worker/{umackern-8.png => arbeiten-8.png} (100%) rename assets/entities/worker/{umackern-9.png => arbeiten-9.png} (100%) rename assets/entities/worker/{umackern.png => arbeiten.png} (100%) rename assets/{building.png => mapobjects/building/idle.png} (100%) diff --git a/Sprite/sprite.c b/Sprite/sprite.c index d53bf1d..debc33f 100644 --- a/Sprite/sprite.c +++ b/Sprite/sprite.c @@ -3,7 +3,7 @@ #include #include #include "../IsometricMap/isometricMap.h" -#include "../Textures/textureIDs.h" +#include "../definitions.h" #include "../Textures/animationHandler.h" #include "../Textures/animation.h" #include "../Textures/textureatlas.h" @@ -52,16 +52,16 @@ Sprite * SpriteCreate(TextureAtlas *atlas, int textureID, int x, int y){ //AnimationHandler create Animation **animations = 0; - if(textureID == TE_worker){ + if(textureID == TE_WORKER){ animations = atlas->workerAnimations; } - else if(textureID == TE_cursor){ + else if(textureID == TE_WORKER){ animations = atlas->cursorAnimation; } - else if(textureID == TE_building){ + else if(textureID == TE_BUILDING){ animations = atlas->buildingAnimation; } - else if(textureID == TE_baustelle){ + else if(textureID == TE_BAUSTELLE){ animations = atlas->baustelleAnimation; } else{ diff --git a/Textures/textureatlas.c b/Textures/textureatlas.c index 48f15dd..4653256 100644 --- a/Textures/textureatlas.c +++ b/Textures/textureatlas.c @@ -5,13 +5,14 @@ #include "stdio.h" TextureAtlas * TextureAtlasInit(){ - TextureAtlas *textures = malloc(sizeof(TextureAtlas)); + TextureAtlas *new = malloc(sizeof(TextureAtlas)); + TextureAtlasLoadTextures(new->textures); + //LoadCursorTextures(textures->cursorTextures, textures->cursorAnimation); + //LoadWorkerTextures(textures->workerTextures); + //LoadWorkerAnimations(textures->workerAnimations, textures->workerTextures); - LoadCursorTextures(textures->cursorTextures, textures->cursorAnimation); - LoadWorkerTextures(textures->workerTextures); - LoadWorkerAnimations(textures->workerAnimations, textures->workerTextures); - +/* //Das soll nicht hier hin, bin aber zu faul :| textures->building = LoadTexture("assets/building.png"); Animation *buildingAnimation = AnimationInit(); @@ -24,8 +25,10 @@ TextureAtlas * TextureAtlasInit(){ textures->buildingAnimation[5] = buildingAnimation; textures->buildingAnimation[6] = buildingAnimation; textures->buildingAnimation[7] = buildingAnimation; + */ //Das soll nicht hier hin, bin aber zu faul :| + /* textures->baustelle = LoadTexture("assets/construction.png"); Animation *baustelleAnimation = AnimationInit(); AnimationInsertBack(baustelleAnimation, &textures->baustelle); @@ -37,31 +40,143 @@ TextureAtlas * TextureAtlasInit(){ textures->baustelleAnimation[5] = baustelleAnimation; textures->baustelleAnimation[6] = baustelleAnimation; textures->baustelleAnimation[7] = baustelleAnimation; + */ - return textures; + return new; } -void TextureAtlasLoadTextures(TextureAtlas *atlas){ +void TextureAtlasLoadTextures(Texture2D **textures){ int i; for(i = 0; i < TE_AMOUNT; i++){ switch(i){ case TE_CURSOR: - //Laden + textures[TE_CURSOR] = malloc(2 * sizeof(Texture2D)); // So vielleicht + LoadCursorTextures(textures[TE_CURSOR]); break; case TE_WORKER: - // Laden + LoadEntityTextures(textures[TE_WORKER], "worker"); + break; + case TE_BUILDING: + LoadMapObjectTextures(textures[TE_BUILDING], "building"); + break; + case TE_BAUSTELLE: + LoadMapObjectTextures(textures[TE_BAUSTELLE], "baustelle"); break; + default: + printf("WARNING: TEXTUREATLAS TRIED LOADING NON DEFINED TEXTUREID!!\n"); + } + } +} + +void LoadEntityTextures(Texture2D *atlasrow, char *directoryPrefix){ + // Das klappt so nicht + atlasrow = malloc(TE_ENTITY_LENGTH * sizeof(Texture2D)); + + // pathToFile wird erstellt. z.B. assets/entities/ + worker ---> assets/entities/worker/ + char pathToFile[50] = "assets/entities/"; + strcat(pathToFile, directoryPrefix); + strcat(pathToFile, "/"); + + char animation[30] = "walk"; + char filename[100]; + char number[3] = ""; + char ending[5] = ".png"; + + // Since some Images need to be flipped, we have fewer pngs than textures later loaded. i counts textures + // file counts the filename and is incremented manually when needed + int i; + int file = 0; + for(i = 0; i < TE_ENTITY_LENGTH; i++){ + // Concatenate the correct string for the filename assets/worker/ + walk + - + 5 + .png + sprintf(number, "%d", file); + strcat(filename, pathToFile); + strcat(filename, animation); + strcat(filename, "-"); + strcat(filename, number); + strcat(filename, ending); + + //printf("file:%s:file\n", filename); + + // Set correct values for next iteration + int lol = i % 8; + + if(lol == 0){ + atlasrow[i] = LoadTexture(filename); + printf("\n"); + file++; + } + else if(lol == 2){ + Image tmp = LoadImage(filename); + ImageFlipHorizontal(&tmp); + atlasrow[i] = LoadTextureFromImage(tmp); + printf("flipped\n"); + file++; + } + else if(lol == 4){ + Image tmp = LoadImage(filename); + ImageFlipHorizontal(&tmp); + atlasrow[i] = LoadTextureFromImage(tmp); + printf("flipped\n"); + file++; + } + else if(lol == 6){ + Image tmp = LoadImage(filename); + ImageFlipHorizontal(&tmp); + atlasrow[i] = LoadTextureFromImage(tmp); + printf("flipped\n"); + file++; + } + else if(lol == 7){ + atlasrow[i] = LoadTexture(filename); + printf("\n"); + file++; + } + else{ + atlasrow[i] = LoadTexture(filename); + printf("\n"); + } + + strcpy(filename, ""); + strcpy(number, ""); + + if(i == 39){ + strcpy(animation, "arbeiten"); + file = 0; + } + else if(i == 79){ + strcpy(animation, "die"); + file = 0; } } + +} + +void LoadMapObjectTextures(Texture2D *atlasrow, char *directoryPrefix){ + atlasrow = malloc(TE_MAPOBJECT_LENGTH * sizeof(Texture2D)); + + // pathToFile wird erstellt. z.B. assets/mapobjects/ + building ---> assets/mapobjects/building/ + char pathToFile[50] = "assets/mapobjects/"; + strcat(pathToFile, directoryPrefix); + strcat(pathToFile, "/"); + + //char animation[30] = "walk"; + char filename[100]; + //char number[3] = ""; + + char ending[5] = ".png"; + + strcat(filename, pathToFile); + strcat(filename, "idle"); + strcat(filename, ending); + + atlasrow[0] = LoadTexture(filename); } -void LoadCursorTextures(Texture2D *cursorTextures, Animation **cursorAnimation){ - *cursorTextures = LoadTexture("assets/cursor.gif"); - *(cursorTextures + 1) = LoadTexture("assets/cursor_down.gif"); +void LoadCursorTextures(Texture2D *cursorTextures){ + cursorTextures = malloc(2 * sizeof(Texture2D)); - Animation *new = AnimationInit(); - AnimationInsertBack(new, cursorTextures); - cursorAnimation[0] = new; + cursorTextures[0] = LoadTexture("assets/cursor.gif"); + cursorTextures[1] = LoadTexture("assets/cursor_down.gif"); } void LoadWorkerTextures(Texture2D *workerTextures){ diff --git a/Textures/textureatlas.h b/Textures/textureatlas.h index 5e268a2..09d2ef8 100644 --- a/Textures/textureatlas.h +++ b/Textures/textureatlas.h @@ -25,8 +25,11 @@ typedef struct TextureAtlas{ // Initialize the full TextureAtlas struct with all Textures used in the game TextureAtlas * TextureAtlasInit(); -void TextureAtlasLoadTextures(TextureAtlas *atlas); -void LoadCursorTextures(Texture2D *cursorTextures, Animation **cursorAnimation); +void TextureAtlasLoadTextures(Texture2D **textures); +void LoadCursorTextures(Texture2D *cursorTextures); +void LoadEntityTextures(Texture2D *atlasrow, char *directoryPrefix); +void LoadMapObjectTextures(Texture2D *atlasrow, char *directoryPrefix); + void LoadWorkerTextures(Texture2D *workerTextures); void LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTextures); diff --git a/assets/entities/worker/umackern-0.png b/assets/entities/worker/arbeiten-0.png similarity index 100% rename from assets/entities/worker/umackern-0.png rename to assets/entities/worker/arbeiten-0.png diff --git a/assets/entities/worker/umackern-1.png b/assets/entities/worker/arbeiten-1.png similarity index 100% rename from assets/entities/worker/umackern-1.png rename to assets/entities/worker/arbeiten-1.png diff --git a/assets/entities/worker/umackern-10.png b/assets/entities/worker/arbeiten-10.png similarity index 100% rename from assets/entities/worker/umackern-10.png rename to assets/entities/worker/arbeiten-10.png diff --git a/assets/entities/worker/umackern-11.png b/assets/entities/worker/arbeiten-11.png similarity index 100% rename from assets/entities/worker/umackern-11.png rename to assets/entities/worker/arbeiten-11.png diff --git a/assets/entities/worker/umackern-12.png b/assets/entities/worker/arbeiten-12.png similarity index 100% rename from assets/entities/worker/umackern-12.png rename to assets/entities/worker/arbeiten-12.png diff --git a/assets/entities/worker/umackern-13.png b/assets/entities/worker/arbeiten-13.png similarity index 100% rename from assets/entities/worker/umackern-13.png rename to assets/entities/worker/arbeiten-13.png diff --git a/assets/entities/worker/umackern-14.png b/assets/entities/worker/arbeiten-14.png similarity index 100% rename from assets/entities/worker/umackern-14.png rename to assets/entities/worker/arbeiten-14.png diff --git a/assets/entities/worker/umackern-15.png b/assets/entities/worker/arbeiten-15.png similarity index 100% rename from assets/entities/worker/umackern-15.png rename to assets/entities/worker/arbeiten-15.png diff --git a/assets/entities/worker/umackern-16.png b/assets/entities/worker/arbeiten-16.png similarity index 100% rename from assets/entities/worker/umackern-16.png rename to assets/entities/worker/arbeiten-16.png diff --git a/assets/entities/worker/umackern-17.png b/assets/entities/worker/arbeiten-17.png similarity index 100% rename from assets/entities/worker/umackern-17.png rename to assets/entities/worker/arbeiten-17.png diff --git a/assets/entities/worker/umackern-18.png b/assets/entities/worker/arbeiten-18.png similarity index 100% rename from assets/entities/worker/umackern-18.png rename to assets/entities/worker/arbeiten-18.png diff --git a/assets/entities/worker/umackern-19.png b/assets/entities/worker/arbeiten-19.png similarity index 100% rename from assets/entities/worker/umackern-19.png rename to assets/entities/worker/arbeiten-19.png diff --git a/assets/entities/worker/umackern-2.png b/assets/entities/worker/arbeiten-2.png similarity index 100% rename from assets/entities/worker/umackern-2.png rename to assets/entities/worker/arbeiten-2.png diff --git a/assets/entities/worker/umackern-20.png b/assets/entities/worker/arbeiten-20.png similarity index 100% rename from assets/entities/worker/umackern-20.png rename to assets/entities/worker/arbeiten-20.png diff --git a/assets/entities/worker/umackern-21.png b/assets/entities/worker/arbeiten-21.png similarity index 100% rename from assets/entities/worker/umackern-21.png rename to assets/entities/worker/arbeiten-21.png diff --git a/assets/entities/worker/umackern-22.png b/assets/entities/worker/arbeiten-22.png similarity index 100% rename from assets/entities/worker/umackern-22.png rename to assets/entities/worker/arbeiten-22.png diff --git a/assets/entities/worker/umackern-23.png b/assets/entities/worker/arbeiten-23.png similarity index 100% rename from assets/entities/worker/umackern-23.png rename to assets/entities/worker/arbeiten-23.png diff --git a/assets/entities/worker/umackern-24.png b/assets/entities/worker/arbeiten-24.png similarity index 100% rename from assets/entities/worker/umackern-24.png rename to assets/entities/worker/arbeiten-24.png diff --git a/assets/entities/worker/umackern-3.png b/assets/entities/worker/arbeiten-3.png similarity index 100% rename from assets/entities/worker/umackern-3.png rename to assets/entities/worker/arbeiten-3.png diff --git a/assets/entities/worker/umackern-4.png b/assets/entities/worker/arbeiten-4.png similarity index 100% rename from assets/entities/worker/umackern-4.png rename to assets/entities/worker/arbeiten-4.png diff --git a/assets/entities/worker/umackern-5.png b/assets/entities/worker/arbeiten-5.png similarity index 100% rename from assets/entities/worker/umackern-5.png rename to assets/entities/worker/arbeiten-5.png diff --git a/assets/entities/worker/umackern-6.png b/assets/entities/worker/arbeiten-6.png similarity index 100% rename from assets/entities/worker/umackern-6.png rename to assets/entities/worker/arbeiten-6.png diff --git a/assets/entities/worker/umackern-7.png b/assets/entities/worker/arbeiten-7.png similarity index 100% rename from assets/entities/worker/umackern-7.png rename to assets/entities/worker/arbeiten-7.png diff --git a/assets/entities/worker/umackern-8.png b/assets/entities/worker/arbeiten-8.png similarity index 100% rename from assets/entities/worker/umackern-8.png rename to assets/entities/worker/arbeiten-8.png diff --git a/assets/entities/worker/umackern-9.png b/assets/entities/worker/arbeiten-9.png similarity index 100% rename from assets/entities/worker/umackern-9.png rename to assets/entities/worker/arbeiten-9.png diff --git a/assets/entities/worker/umackern.png b/assets/entities/worker/arbeiten.png similarity index 100% rename from assets/entities/worker/umackern.png rename to assets/entities/worker/arbeiten.png diff --git a/assets/building.png b/assets/mapobjects/building/idle.png similarity index 100% rename from assets/building.png rename to assets/mapobjects/building/idle.png