|
|
|
|
@ -8,39 +8,8 @@ TextureAtlas * TextureAtlasInit(){
|
|
|
|
|
TextureAtlas *new = malloc(sizeof(TextureAtlas));
|
|
|
|
|
|
|
|
|
|
TextureAtlasLoadTextures(new->textures);
|
|
|
|
|
//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();
|
|
|
|
|
AnimationInsertBack(buildingAnimation, &textures->building);
|
|
|
|
|
textures->buildingAnimation[0] = buildingAnimation;
|
|
|
|
|
textures->buildingAnimation[1] = buildingAnimation;
|
|
|
|
|
textures->buildingAnimation[2] = buildingAnimation;
|
|
|
|
|
textures->buildingAnimation[3] = buildingAnimation;
|
|
|
|
|
textures->buildingAnimation[4] = buildingAnimation;
|
|
|
|
|
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);
|
|
|
|
|
textures->baustelleAnimation[0] = baustelleAnimation;
|
|
|
|
|
textures->baustelleAnimation[1] = baustelleAnimation;
|
|
|
|
|
textures->baustelleAnimation[2] = baustelleAnimation;
|
|
|
|
|
textures->baustelleAnimation[3] = baustelleAnimation;
|
|
|
|
|
textures->baustelleAnimation[4] = baustelleAnimation;
|
|
|
|
|
textures->baustelleAnimation[5] = baustelleAnimation;
|
|
|
|
|
textures->baustelleAnimation[6] = baustelleAnimation;
|
|
|
|
|
textures->baustelleAnimation[7] = baustelleAnimation;
|
|
|
|
|
*/
|
|
|
|
|
TextureAtlasLoadAnimations(new->animations, new->textures);
|
|
|
|
|
|
|
|
|
|
return new;
|
|
|
|
|
}
|
|
|
|
|
@ -50,16 +19,19 @@ void TextureAtlasLoadTextures(Texture2D **textures){
|
|
|
|
|
for(i = 0; i < TE_AMOUNT; i++){
|
|
|
|
|
switch(i){
|
|
|
|
|
case TE_CURSOR:
|
|
|
|
|
textures[TE_CURSOR] = malloc(2 * sizeof(Texture2D)); // So vielleicht
|
|
|
|
|
textures[TE_CURSOR] = malloc(2 * sizeof(Texture2D));
|
|
|
|
|
LoadCursorTextures(textures[TE_CURSOR]);
|
|
|
|
|
break;
|
|
|
|
|
case TE_WORKER:
|
|
|
|
|
textures[TE_WORKER] = malloc(TE_ENTITY_LENGTH * sizeof(Texture2D));
|
|
|
|
|
LoadEntityTextures(textures[TE_WORKER], "worker");
|
|
|
|
|
break;
|
|
|
|
|
case TE_BUILDING:
|
|
|
|
|
textures[TE_BUILDING] = malloc(TE_MAPOBJECT_LENGTH * sizeof(Texture2D));
|
|
|
|
|
LoadMapObjectTextures(textures[TE_BUILDING], "building");
|
|
|
|
|
break;
|
|
|
|
|
case TE_BAUSTELLE:
|
|
|
|
|
textures[TE_BAUSTELLE] = malloc(TE_MAPOBJECT_LENGTH * sizeof(Texture2D));
|
|
|
|
|
LoadMapObjectTextures(textures[TE_BAUSTELLE], "baustelle");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
@ -69,8 +41,6 @@ void TextureAtlasLoadTextures(Texture2D **textures){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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/";
|
|
|
|
|
@ -78,7 +48,7 @@ void LoadEntityTextures(Texture2D *atlasrow, char *directoryPrefix){
|
|
|
|
|
strcat(pathToFile, "/");
|
|
|
|
|
|
|
|
|
|
char animation[30] = "walk";
|
|
|
|
|
char filename[100];
|
|
|
|
|
char filename[100] = "";
|
|
|
|
|
char number[3] = "";
|
|
|
|
|
char ending[5] = ".png";
|
|
|
|
|
|
|
|
|
|
@ -152,7 +122,6 @@ void LoadEntityTextures(Texture2D *atlasrow, char *directoryPrefix){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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/";
|
|
|
|
|
@ -160,7 +129,7 @@ void LoadMapObjectTextures(Texture2D *atlasrow, char *directoryPrefix){
|
|
|
|
|
strcat(pathToFile, "/");
|
|
|
|
|
|
|
|
|
|
//char animation[30] = "walk";
|
|
|
|
|
char filename[100];
|
|
|
|
|
char filename[100] = "";
|
|
|
|
|
//char number[3] = "";
|
|
|
|
|
|
|
|
|
|
char ending[5] = ".png";
|
|
|
|
|
@ -173,83 +142,52 @@ void LoadMapObjectTextures(Texture2D *atlasrow, char *directoryPrefix){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LoadCursorTextures(Texture2D *cursorTextures){
|
|
|
|
|
cursorTextures = malloc(2 * sizeof(Texture2D));
|
|
|
|
|
|
|
|
|
|
cursorTextures[0] = LoadTexture("assets/cursor.gif");
|
|
|
|
|
cursorTextures[1] = LoadTexture("assets/cursor_down.gif");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LoadWorkerTextures(Texture2D *workerTextures){
|
|
|
|
|
|
|
|
|
|
char beginning[30] = "assets/worker/walk-";
|
|
|
|
|
char filename[30] = "";
|
|
|
|
|
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
|
|
|
|
|
void TextureAtlasLoadAnimations(Animation ****animations, Texture2D **textures){
|
|
|
|
|
int i;
|
|
|
|
|
int file = 0;
|
|
|
|
|
for(i = 0; i < 104; i++){
|
|
|
|
|
// Concatenate the correct string for the filename (beginning + i + ending)
|
|
|
|
|
sprintf(number, "%d", file);
|
|
|
|
|
strcat(filename, beginning);
|
|
|
|
|
strcat(filename, number);
|
|
|
|
|
strcat(filename, ending);
|
|
|
|
|
|
|
|
|
|
//printf("file:%s:file\n", filename);
|
|
|
|
|
|
|
|
|
|
// Set correct values for next iteration
|
|
|
|
|
int lol = i % 8;
|
|
|
|
|
for(i = 0; i < AN_AMOUNT; i++){
|
|
|
|
|
switch(i){
|
|
|
|
|
case AN_WORKER:
|
|
|
|
|
animations[AN_WORKER] = malloc(AN_ENTITY_AMOUNT * sizeof(Animation *));
|
|
|
|
|
LoadEntityAnimations(animations[AN_WORKER], textures[TE_WORKER], AN_WORKER);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("WARNING: TEXTUREATLAS TRIED LOADING NON DEFINED ANIMATION!!\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LoadEntityAnimations(Animation ***animationsrow, Texture2D *atlasrow, int id){
|
|
|
|
|
int i;
|
|
|
|
|
int j;
|
|
|
|
|
int frame;
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < AN_ENTITY_AMOUNT; i++){
|
|
|
|
|
animationsrow[i] = malloc(DIRECTIONS_AMOUNT * sizeof(Animation));
|
|
|
|
|
|
|
|
|
|
// TODO: walk und umackern läuft nicht bis 24 sondern nur 23
|
|
|
|
|
if(lol == 0){
|
|
|
|
|
*(workerTextures + i) = LoadTexture(filename);
|
|
|
|
|
printf("\n");
|
|
|
|
|
file++;
|
|
|
|
|
}
|
|
|
|
|
else if(lol == 2){
|
|
|
|
|
Image tmp = LoadImage(filename);
|
|
|
|
|
ImageFlipHorizontal(&tmp);
|
|
|
|
|
*(workerTextures + i) = LoadTextureFromImage(tmp);
|
|
|
|
|
printf("flipped\n");
|
|
|
|
|
file++;
|
|
|
|
|
}
|
|
|
|
|
else if(lol == 4){
|
|
|
|
|
Image tmp = LoadImage(filename);
|
|
|
|
|
ImageFlipHorizontal(&tmp);
|
|
|
|
|
*(workerTextures + i) = LoadTextureFromImage(tmp);
|
|
|
|
|
printf("flipped\n");
|
|
|
|
|
file++;
|
|
|
|
|
}
|
|
|
|
|
else if(lol == 6){
|
|
|
|
|
Image tmp = LoadImage(filename);
|
|
|
|
|
ImageFlipHorizontal(&tmp);
|
|
|
|
|
*(workerTextures + i) = LoadTextureFromImage(tmp);
|
|
|
|
|
printf("flipped\n");
|
|
|
|
|
file++;
|
|
|
|
|
}
|
|
|
|
|
else if(lol == 7){
|
|
|
|
|
*(workerTextures + i) = LoadTexture(filename);
|
|
|
|
|
printf("\n");
|
|
|
|
|
file++;
|
|
|
|
|
int obergrenze;
|
|
|
|
|
if(i == AN_ENTITY_DIE){
|
|
|
|
|
obergrenze = 3;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
*(workerTextures + i) = LoadTexture(filename);
|
|
|
|
|
printf("\n");
|
|
|
|
|
obergrenze = 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strcpy(filename, "");
|
|
|
|
|
strcpy(number, "");
|
|
|
|
|
for(j = 0; j < DIRECTIONS_AMOUNT; j++){
|
|
|
|
|
Animation *newAnimation = AnimationInit();
|
|
|
|
|
frame = i * DIRECTIONS_AMOUNT * 5 + j;
|
|
|
|
|
|
|
|
|
|
if(i == 39){
|
|
|
|
|
strcpy(beginning, "assets/worker/umackern-");
|
|
|
|
|
file = 0;
|
|
|
|
|
}
|
|
|
|
|
else if(i == 79){
|
|
|
|
|
strcpy(beginning, "assets/worker/die-");
|
|
|
|
|
file = 0;
|
|
|
|
|
int frameCounter;
|
|
|
|
|
for(frameCounter = 0; frameCounter < obergrenze; frameCounter++){
|
|
|
|
|
AnimationInsertBack(newAnimation, (atlasrow + frame));
|
|
|
|
|
frame += 8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
animationsrow[i][j] = newAnimation;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|