diff --git a/Entity/entity.c b/Entity/entity.c index 62db4e5..fcf9d60 100644 --- a/Entity/entity.c +++ b/Entity/entity.c @@ -3,10 +3,14 @@ #include #include #include "../Sprite/sprite.h" +#include "../MapObject/mapobject.h" +#include "../definitions.h" +#include "../Textures/textureatlas.h" -Entity * EntityInit(Sprite *sprite){ +Entity * EntityInit(Sprite *sprite, int profession, TextureAtlas *atlas){ Entity *new = malloc(sizeof(Entity)); - + + new->angle = 0; new->sprite = sprite; new->destX = 0; new->destY = 0; @@ -14,6 +18,19 @@ Entity * EntityInit(Sprite *sprite){ new->selected = 0; new->next = 0; new->prev = 0; + new->task = TaskInit(); + new->profession = profession; + + Animation ***animations = 0; + + if(profession == TE_WORKER){ + animations = atlas->animations[AN_WORKER]; + } + else{ + printf("\n\n\n\n\n\n\n\nEntityCreate mit falscher ID (%d) aufgerufen oder ID nicht bekannt!!!\n\n\n\n\n\n\n\n", profession); + } + + new->animationHandler = AnimationHandlerInit(animations, &new->sprite->texture); return new; } @@ -97,13 +114,82 @@ void EntityListActAllEntities(Game *game){ angle = angle * RAD2DEG; angle -= 35.26; - current->sprite->angle = angle; - + if(angle <= 22.5 && angle >= -22.5){ + // E + AnimationChangeDirection(current->animationHandler, E); + } + else if(angle > 0 && angle <= 67.5){ + // NE + AnimationChangeDirection(current->animationHandler, NE); + } + else if(angle > 0 && angle <= 112.5){ + // N + AnimationChangeDirection(current->animationHandler, N); + } + else if(angle > 0 && angle <= 157.5){ + // NW + AnimationChangeDirection(current->animationHandler, NW); + } + else if(angle < 0 && angle >= -67.5){ + // SE + AnimationChangeDirection(current->animationHandler, SE); + } + else if(angle < 0 && angle >= -112.5){ + // S + AnimationChangeDirection(current->animationHandler, S); + } + else if(angle < 0 && angle >= -157.5){ + // SW + AnimationChangeDirection(current->animationHandler, SW); + } + else{ + // W + AnimationChangeDirection(current->animationHandler, W); + } } + + } + else{ + /* + if(current->profession == PR_BUILDER){ + if(current->task->target == 0){ + // Prüft, ob eine Baustelle existiert + MapObject *currentMO = game->mapObjects->head; + while(currentMO != 0){ + if(currentMO->id == MO_Baustelle){ + current->hasDestination = 1; + current->destX = currentMO->sprite->x; + current->destY = currentMO->sprite->y; + current->task->target = currentMO; + break; + } + currentMO = currentMO->next; + } + } + else{ + // Is beim target angekommen + /* + MapObject *obj = current->task->target; + printf("Hier\n"); + Sprite *new = SpriteCreate(game->textures, 2, obj->sprite->x, obj->sprite->y); + SpriteListRemove(game->sprites, obj->sprite); + SpriteListInsert(game->sprites, new); + free(obj->sprite); + MapObject *newObject = MapObjectInit(new, MO_Building); + MapObjectListRemove(game->mapObjects, obj); + MapObjectListInsert(game->mapObjects, newObject); + current->task->target = 0; + free(obj); + */ + //} + + //} + } - SpriteUpdate(current->sprite); + AnimationUpdate(current->animationHandler); + SpriteUpdate(current->sprite); SpriteListSpriteChanged(game->sprites, current->sprite); current = current->next; diff --git a/Entity/entity.h b/Entity/entity.h index 672bfc4..a7f1e76 100644 --- a/Entity/entity.h +++ b/Entity/entity.h @@ -2,15 +2,21 @@ #define ENTITY_H_ #include "../Sprite/sprite.h" #include "../game.h" +#include "task.h" +#include "../Textures/animationHandler.h" typedef struct Entity Entity; typedef struct Entity{ Sprite *sprite; + AnimationHandler *animationHandler; + float angle; float destX; float destY; int hasDestination; int selected; + Task *task; + int profession; Entity *next; Entity *prev; @@ -21,7 +27,7 @@ typedef struct EntityList{ Entity *tail; } EntityList; -Entity * EntityInit(Sprite *sprite); +Entity * EntityInit(Sprite *sprite, int profession, TextureAtlas *atlas); EntityList * EntityListInit(); void EntityListPrintForward(EntityList *entities); diff --git a/Entity/task.c b/Entity/task.c new file mode 100644 index 0000000..b2f3db4 --- /dev/null +++ b/Entity/task.c @@ -0,0 +1,8 @@ +#include +#include "task.h" + +Task * TaskInit(){ + Task *new = malloc(sizeof(Task)); + new->target = 0; + return new; +} \ No newline at end of file diff --git a/Entity/task.h b/Entity/task.h new file mode 100644 index 0000000..3c99985 --- /dev/null +++ b/Entity/task.h @@ -0,0 +1,12 @@ +#ifndef TASK_H_ +#define TASK_H_ + +typedef struct Task Task; + +typedef struct Task{ + void *target; +} Task; + +Task * TaskInit(); + +#endif \ No newline at end of file diff --git a/Input/inputHandler.c b/Input/inputHandler.c index 2beba3c..6f468a5 100644 --- a/Input/inputHandler.c +++ b/Input/inputHandler.c @@ -3,11 +3,13 @@ #include "../Sprite/sprite.h" #include "../IsometricMap/isometricMap.h" #include "../Entity/entity.h" +#include "../MapObject/mapobject.h" #include #include #include #include "../IsometricMap/tile.h" #include "../game.h" +#include "../definitions.h" void DrawRect(Vector2 rectStart, Vector2 *mousePosition){ float width = GetMousePosition().x - rectStart.x; @@ -69,6 +71,16 @@ void mouseInput(Game *game){ IsometricMapChangeTextureIdOfTile(map, (int) inputHandler->cursorWorldTile.x, (int) inputHandler->cursorWorldTile.y, 0); } + if(IsKeyPressed(KEY_G)){ + // Baustelle adden + /* + Sprite *new = SpriteCreate(game->textures, 3, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y); + MapObject *newObject = MapObjectInit(new, MO_Baustelle); + SpriteListInsert(game->sprites, new); + MapObjectListInsert(game->mapObjects, newObject); + */ + } + // hardcoded layer amount float tileWidthHalf = map->tileTextures[0].width / 2; float tileHeightQuarter = map->tileTextures[0].height / 4; @@ -99,7 +111,7 @@ void mouseInput(Game *game){ inputHandler->pressed = 1; // Cursorsprite is changed to "down" - inputHandler->cursorSprite->texture = (inputHandler->cursorTextures) + 1; + game->cursorSprite->texture = &game->textures->textures[TE_CURSOR][1]; } } @@ -111,7 +123,7 @@ void mouseInput(Game *game){ if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)){ inputHandler->pressed = 0; // Cursorsprite is changed back to normal - inputHandler->cursorSprite->texture = (inputHandler->cursorTextures); + game->cursorSprite->texture = &game->textures->textures[TE_CURSOR][0]; float width = GetMousePosition().x - inputHandler->rectStart.x; float height = GetMousePosition().y - inputHandler->rectStart.y; @@ -125,8 +137,8 @@ void mouseInput(Game *game){ else if(inputHandler->cursorWorldPos.x > maxWidth){ printf("OutOfBoundsDestination Spawn\n");} else if(inputHandler->cursorWorldPos.y > maxHeight){ printf("OutOfBoundsDestination Spawn\n");} else { - Sprite *newSprite = SpriteCreate(game->textures, 1, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y); - Entity *entity = EntityInit(newSprite); + Sprite *newSprite = SpriteCreate(game->textures, TE_WORKER, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y); + Entity *entity = EntityInit(newSprite, TE_WORKER, game->textures); EntityListInsert(game->entities, entity); SpriteListInsert(game->sprites, newSprite); //ListPrintForward(sprites); diff --git a/Input/inputHandler.h b/Input/inputHandler.h index c6c4afc..b718cb8 100644 --- a/Input/inputHandler.h +++ b/Input/inputHandler.h @@ -12,8 +12,6 @@ typedef struct InputHandler{ Vector2 cursorWorldPos; Vector2 cursorWorldTile; int selectedLayer; - Texture2D *cursorTextures; - Sprite *cursorSprite; } InputHandler; void mouseInput(Game *game); diff --git a/IsometricMap/isometricMap.c b/IsometricMap/isometricMap.c index cc92c2f..aa151fb 100644 --- a/IsometricMap/isometricMap.c +++ b/IsometricMap/isometricMap.c @@ -165,5 +165,4 @@ void IsometricMapDraw(Game *game){ } } - SpriteListDrawAllSprites(game->sprites, game->map, game->camera); } diff --git a/Makefile b/Makefile index c687b41..4e3ee93 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC = gcc FLAGS = -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -OBJS = main.o sprite.o inputHandler.o isometricMap.o game.o textureatlas.o animation.o animationHandler.o button.o uiContainer.o debug.o mapobject.o entity.o selectable.o +OBJS = main.o sprite.o inputHandler.o isometricMap.o game.o textureatlas.o animation.o animationHandler.o button.o uiContainer.o debug.o mapobject.o entity.o selectable.o task.o spiel: $(OBJS) $(CC) -o spiel $(OBJS) $(FLAGS) @@ -47,5 +47,8 @@ mapobject.o: MapObject/mapobject.c selectable.o: Ui/selectable.c $(CC) -c Ui/selectable.c $(FLAGS) +task.o: Entity/task.c + $(CC) -c Entity/task.c $(FLAGS) + clean: rm *.o spiel diff --git a/MapObject/mapobject.c b/MapObject/mapobject.c index b30e3d6..7a1b124 100644 --- a/MapObject/mapobject.c +++ b/MapObject/mapobject.c @@ -1,10 +1,11 @@ #include "mapobject.h" #include -MapObject * MapObjectInit(Sprite *sprite){ +MapObject * MapObjectInit(Sprite *sprite, int id){ MapObject *new = malloc(sizeof(MapObject)); new->sprite = sprite; + new->id = id; new->next = 0; new->prev = 0; diff --git a/MapObject/mapobject.h b/MapObject/mapobject.h index 44a570c..68fd140 100644 --- a/MapObject/mapobject.h +++ b/MapObject/mapobject.h @@ -7,6 +7,7 @@ typedef struct MapObjectList MapObjectList; typedef struct MapObject{ Sprite *sprite; + int id; MapObject *next; MapObject *prev; @@ -17,7 +18,7 @@ typedef struct MapObjectList{ MapObject *tail; } MapObjectList; -MapObject * MapObjectInit(Sprite *sprite); +MapObject * MapObjectInit(Sprite *sprite, int id); MapObjectList * MapObjectListInit(); void MapObjectListPrintForward(MapObjectList *mapObjects); diff --git a/Sprite/sprite.c b/Sprite/sprite.c index 865d55a..59e00d4 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" @@ -43,68 +43,17 @@ void SpriteUpdate(Sprite *sprite){ sprite->depth = sprite->x + sprite->y + sprite->z; - if(sprite->angle <= 22.5 && sprite->angle >= -22.5){ - // E - AnimationChangeAnimation(sprite->animationHandler, E); - } - else if(sprite->angle > 0 && sprite->angle <= 67.5){ - // NE - AnimationChangeAnimation(sprite->animationHandler, NE); - } - else if(sprite->angle > 0 && sprite->angle <= 112.5){ - // N - AnimationChangeAnimation(sprite->animationHandler, N); - } - else if(sprite->angle > 0 && sprite->angle <= 157.5){ - // NW - AnimationChangeAnimation(sprite->animationHandler, NW); - } - else if(sprite->angle < 0 && sprite->angle >= -67.5){ - // SE - AnimationChangeAnimation(sprite->animationHandler, SE); - } - else if(sprite->angle < 0 && sprite->angle >= -112.5){ - // S - AnimationChangeAnimation(sprite->animationHandler, S); - } - else if(sprite->angle < 0 && sprite->angle >= -157.5){ - // SW - AnimationChangeAnimation(sprite->animationHandler, SW); - } - else{ - // W - AnimationChangeAnimation(sprite->animationHandler, W); - } - - AnimationUpdate(sprite->animationHandler); - sprite->texture = sprite->animationHandler->currentFrame->texture; +// sprite->texture = sprite->animationHandler->currentFrame->texture; } Sprite * SpriteCreate(TextureAtlas *atlas, int textureID, int x, int y){ Sprite *newSprite = malloc(sizeof(Sprite)); - //AnimationHandler create - Animation **animations = 0; - - if(textureID == worker){ - animations = atlas->workerAnimations; - } - else if(textureID == cursor){ - animations = atlas->cursorAnimation; - } - else{ - printf("\n\n\n\n\n\n\n\nSpriteCreate mit falscher ID (%d) aufgerufen oder ID nicht bekannt!!!\n\n\n\n\n\n\n\n", textureID); - } - - AnimationHandler *newHandler = AnimationHandlerInit(animations); - - newSprite->animationHandler = newHandler; - newSprite->texture = newSprite->animationHandler->currentFrame->texture; + newSprite->texture = atlas->textures[textureID]; newSprite->x = x - newSprite->texture->width / 2; newSprite->y = y - newSprite->texture->height / 2; newSprite->z = 0; newSprite->depth = newSprite->x + newSprite->y; - newSprite->angle = 0; newSprite->next = 0; newSprite->prev = 0; diff --git a/Sprite/sprite.h b/Sprite/sprite.h index a4dbf1c..8f819e8 100644 --- a/Sprite/sprite.h +++ b/Sprite/sprite.h @@ -9,13 +9,11 @@ typedef struct Sprite Sprite; typedef struct SpriteList SpriteList; typedef struct Sprite { - AnimationHandler *animationHandler; Texture2D *texture; float x; float y; float z; float depth; - float angle; Sprite *next; Sprite *prev; diff --git a/Textures/animationHandler.c b/Textures/animationHandler.c index 968dd4a..5226e9d 100644 --- a/Textures/animationHandler.c +++ b/Textures/animationHandler.c @@ -1,21 +1,26 @@ #include "animationHandler.h" #include "animation.h" -#include "stdlib.h" -#include "stdio.h" +#include +#include -AnimationHandler * AnimationHandlerInit(Animation **animations){ +AnimationHandler * AnimationHandlerInit(Animation ***animations, Texture2D **spriteTexture){ AnimationHandler *new = malloc(sizeof(AnimationHandler)); + new->spriteTexture = spriteTexture; new->animations = animations; - new->currentAnimation = 0; - new->currentFrame = new->animations[new->currentAnimation]->head; + new->currentType = 0; + new->currentDirection = 0; + new->currentFrame = new->animations[new->currentType][new->currentDirection]->head; + new->spriteTexture = spriteTexture; new->forward = 1; new->deltaElapsed = 0; + + return new; } void AnimationUpdate(AnimationHandler *animationHandler){ animationHandler->deltaElapsed += GetFrameTime(); - + if(animationHandler->deltaElapsed >= 0.2){ if(animationHandler->forward == 1){ animationHandler->currentFrame = animationHandler->currentFrame->next; @@ -26,17 +31,27 @@ void AnimationUpdate(AnimationHandler *animationHandler){ animationHandler->deltaElapsed = 0; } + *(animationHandler->spriteTexture) = animationHandler->currentFrame->texture; } void AnimationReset(AnimationHandler *animationHandler){ - animationHandler->currentFrame = animationHandler->animations[animationHandler->currentAnimation]->head; + animationHandler->currentFrame = animationHandler->animations[animationHandler->currentType][animationHandler->currentDirection]->head; + *(animationHandler->spriteTexture) = animationHandler->currentFrame->texture; } -void AnimationChangeAnimation(AnimationHandler *animationHandler, int newAnimation){ - if(animationHandler->currentAnimation != newAnimation){ - animationHandler->currentAnimation = newAnimation; +void AnimationChangeAnimation(AnimationHandler *animationHandler, int animationType, int direction){ + if(animationHandler->currentType != animationType || animationHandler->currentDirection != direction){ + animationHandler->currentType = animationType; + animationHandler->currentDirection = direction; AnimationReset(animationHandler); } - -} \ No newline at end of file +} + + +void AnimationChangeDirection(AnimationHandler *animationHandler, int direction){ + if(animationHandler->currentDirection != direction){ + animationHandler->currentDirection = direction; + AnimationReset(animationHandler); + } +} diff --git a/Textures/animationHandler.h b/Textures/animationHandler.h index 739b868..742f876 100644 --- a/Textures/animationHandler.h +++ b/Textures/animationHandler.h @@ -7,16 +7,19 @@ typedef struct AnimationHandler AnimationHandler; typedef struct AnimationHandler{ - Animation **animations; + Animation ***animations; AnimationFrame *currentFrame; - int currentAnimation; + Texture2D **spriteTexture; + int currentType; + int currentDirection; int forward; float deltaElapsed; } AnimationHandler; -AnimationHandler * AnimationHandlerInit(Animation **animations); +AnimationHandler * AnimationHandlerInit(Animation ***animations, Texture2D **spriteTexture); void AnimationUpdate(AnimationHandler *animationHandler); void AnimationReset(AnimationHandler *animationHandler); -void AnimationChangeAnimation(AnimationHandler *animationHandler, int newAnimation); +void AnimationChangeAnimation(AnimationHandler *animationHandler, int animationType, int direction); +void AnimationChangeDirection(AnimationHandler *animationHandler, int direction); -#endif \ No newline at end of file +#endif diff --git a/Textures/textureIDs.h b/Textures/textureIDs.h deleted file mode 100644 index 1cb932c..0000000 --- a/Textures/textureIDs.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef TEXTUREIDS_H_ -#define TEXTUREIDS_H_ - -#define N 0 -#define NE 1 -#define E 3 -#define SE 5 -#define S 7 -#define SW 6 -#define W 4 -#define NW 2 - -#define cursor 0 -#define worker 1 - -#endif \ No newline at end of file diff --git a/Textures/textureatlas.c b/Textures/textureatlas.c index 353cdcf..22cf718 100644 --- a/Textures/textureatlas.c +++ b/Textures/textureatlas.c @@ -5,28 +5,50 @@ #include "stdio.h" TextureAtlas * TextureAtlasInit(){ - TextureAtlas *textures = malloc(sizeof(TextureAtlas)); - - LoadCursorTextures(textures->cursorTextures, textures->cursorAnimation); - LoadWorkerTextures(textures->workerTextures); - LoadWorkerAnimations(textures->workerAnimations, textures->workerTextures); + TextureAtlas *new = malloc(sizeof(TextureAtlas)); + + TextureAtlasLoadTextures(new->textures); + //LoadWorkerAnimations(textures->workerAnimations, textures->workerTextures); + TextureAtlasLoadAnimations(new->animations, new->textures); - return textures; + return new; } -void LoadCursorTextures(Texture2D *cursorTextures, Animation **cursorAnimation){ - *cursorTextures = LoadTexture("assets/cursor.gif"); - *(cursorTextures + 1) = LoadTexture("assets/cursor_down.gif"); - - Animation *new = AnimationInit(); - AnimationInsertBack(new, cursorTextures); - cursorAnimation[0] = new; +void TextureAtlasLoadTextures(Texture2D **textures){ + int i; + for(i = 0; i < TE_AMOUNT; i++){ + switch(i){ + case TE_CURSOR: + 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: + printf("WARNING: TEXTUREATLAS TRIED LOADING NON DEFINED TEXTUREID!!\n"); + } + } } -void LoadWorkerTextures(Texture2D *workerTextures){ +void LoadEntityTextures(Texture2D *atlasrow, char *directoryPrefix){ - char beginning[30] = "assets/worker/walk-"; - char filename[30] = ""; + // 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"; @@ -34,10 +56,12 @@ void LoadWorkerTextures(Texture2D *workerTextures){ // file counts the filename and is incremented manually when needed int i; int file = 0; - for(i = 0; i < 104; i++){ - // Concatenate the correct string for the filename (beginning + i + ending) + 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, beginning); + strcat(filename, pathToFile); + strcat(filename, animation); + strcat(filename, "-"); strcat(filename, number); strcat(filename, ending); @@ -46,41 +70,39 @@ void LoadWorkerTextures(Texture2D *workerTextures){ // Set correct values for next iteration int lol = i % 8; - - // TODO: walk und umackern läuft nicht bis 24 sondern nur 23 if(lol == 0){ - *(workerTextures + i) = LoadTexture(filename); + atlasrow[i] = LoadTexture(filename); printf("\n"); file++; } else if(lol == 2){ Image tmp = LoadImage(filename); ImageFlipHorizontal(&tmp); - *(workerTextures + i) = LoadTextureFromImage(tmp); + atlasrow[i] = LoadTextureFromImage(tmp); printf("flipped\n"); file++; } else if(lol == 4){ Image tmp = LoadImage(filename); ImageFlipHorizontal(&tmp); - *(workerTextures + i) = LoadTextureFromImage(tmp); + atlasrow[i] = LoadTextureFromImage(tmp); printf("flipped\n"); file++; } else if(lol == 6){ Image tmp = LoadImage(filename); ImageFlipHorizontal(&tmp); - *(workerTextures + i) = LoadTextureFromImage(tmp); + atlasrow[i] = LoadTextureFromImage(tmp); printf("flipped\n"); file++; } else if(lol == 7){ - *(workerTextures + i) = LoadTexture(filename); + atlasrow[i] = LoadTexture(filename); printf("\n"); file++; } else{ - *(workerTextures + i) = LoadTexture(filename); + atlasrow[i] = LoadTexture(filename); printf("\n"); } @@ -88,14 +110,86 @@ void LoadWorkerTextures(Texture2D *workerTextures){ strcpy(number, ""); if(i == 39){ - strcpy(beginning, "assets/worker/umackern-"); + strcpy(animation, "arbeiten"); file = 0; } else if(i == 79){ - strcpy(beginning, "assets/worker/die-"); + strcpy(animation, "die"); file = 0; } } + +} + +void LoadMapObjectTextures(Texture2D *atlasrow, char *directoryPrefix){ + + // 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){ + + cursorTextures[0] = LoadTexture("assets/cursor.gif"); + cursorTextures[1] = LoadTexture("assets/cursor_down.gif"); +} + +void TextureAtlasLoadAnimations(Animation ****animations, Texture2D **textures){ + int i; + 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)); + + int obergrenze; + if(i == AN_ENTITY_DIE){ + obergrenze = 3; + } + else{ + obergrenze = 5; + } + + for(j = 0; j < DIRECTIONS_AMOUNT; j++){ + Animation *newAnimation = AnimationInit(); + frame = i * DIRECTIONS_AMOUNT * 5 + j; + + int frameCounter; + for(frameCounter = 0; frameCounter < obergrenze; frameCounter++){ + AnimationInsertBack(newAnimation, (atlasrow + frame)); + frame += 8; + } + + animationsrow[i][j] = newAnimation; + } + } } void LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTextures){ diff --git a/Textures/textureatlas.h b/Textures/textureatlas.h index 1199d77..90c8960 100644 --- a/Textures/textureatlas.h +++ b/Textures/textureatlas.h @@ -2,23 +2,28 @@ #define TEXTUREATLAS_H_ #include "raylib.h" #include "animation.h" +#include "../definitions.h" typedef struct TextureAtlas TextureAtlas; typedef struct TextureAtlas{ - Texture2D cursorTextures[2]; - Animation *cursorAnimation[1]; + + Texture2D *textures[TE_AMOUNT]; + Animation ***animations[AN_AMOUNT]; - Texture2D workerTextures[104]; Animation *workerAnimations[24]; - //Texture2D[] mapTextures; } TextureAtlas; // Initialize the full TextureAtlas struct with all Textures used in the game TextureAtlas * TextureAtlasInit(); -void LoadCursorTextures(Texture2D *cursorTextures, Animation **cursorAnimation); -void LoadWorkerTextures(Texture2D *workerTextures); +void TextureAtlasLoadTextures(Texture2D **textures); +void LoadCursorTextures(Texture2D *cursorTextures); +void LoadEntityTextures(Texture2D *atlasrow, char *directoryPrefix); +void LoadMapObjectTextures(Texture2D *atlasrow, char *directoryPrefix); + void LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTextures); +void TextureAtlasLoadAnimations(Animation ****animations, Texture2D **textures); +void LoadEntityAnimations(Animation ***animationsrow, Texture2D *atlasrow, int id); -#endif \ No newline at end of file +#endif diff --git a/assets/worker/umackern-0.png b/assets/entities/worker/arbeiten-0.png similarity index 100% rename from assets/worker/umackern-0.png rename to assets/entities/worker/arbeiten-0.png diff --git a/assets/worker/umackern-1.png b/assets/entities/worker/arbeiten-1.png similarity index 100% rename from assets/worker/umackern-1.png rename to assets/entities/worker/arbeiten-1.png diff --git a/assets/worker/umackern-10.png b/assets/entities/worker/arbeiten-10.png similarity index 100% rename from assets/worker/umackern-10.png rename to assets/entities/worker/arbeiten-10.png diff --git a/assets/worker/umackern-11.png b/assets/entities/worker/arbeiten-11.png similarity index 100% rename from assets/worker/umackern-11.png rename to assets/entities/worker/arbeiten-11.png diff --git a/assets/worker/umackern-12.png b/assets/entities/worker/arbeiten-12.png similarity index 100% rename from assets/worker/umackern-12.png rename to assets/entities/worker/arbeiten-12.png diff --git a/assets/worker/umackern-13.png b/assets/entities/worker/arbeiten-13.png similarity index 100% rename from assets/worker/umackern-13.png rename to assets/entities/worker/arbeiten-13.png diff --git a/assets/worker/umackern-14.png b/assets/entities/worker/arbeiten-14.png similarity index 100% rename from assets/worker/umackern-14.png rename to assets/entities/worker/arbeiten-14.png diff --git a/assets/worker/umackern-15.png b/assets/entities/worker/arbeiten-15.png similarity index 100% rename from assets/worker/umackern-15.png rename to assets/entities/worker/arbeiten-15.png diff --git a/assets/worker/umackern-16.png b/assets/entities/worker/arbeiten-16.png similarity index 100% rename from assets/worker/umackern-16.png rename to assets/entities/worker/arbeiten-16.png diff --git a/assets/worker/umackern-17.png b/assets/entities/worker/arbeiten-17.png similarity index 100% rename from assets/worker/umackern-17.png rename to assets/entities/worker/arbeiten-17.png diff --git a/assets/worker/umackern-18.png b/assets/entities/worker/arbeiten-18.png similarity index 100% rename from assets/worker/umackern-18.png rename to assets/entities/worker/arbeiten-18.png diff --git a/assets/worker/umackern-19.png b/assets/entities/worker/arbeiten-19.png similarity index 100% rename from assets/worker/umackern-19.png rename to assets/entities/worker/arbeiten-19.png diff --git a/assets/worker/umackern-2.png b/assets/entities/worker/arbeiten-2.png similarity index 100% rename from assets/worker/umackern-2.png rename to assets/entities/worker/arbeiten-2.png diff --git a/assets/worker/umackern-20.png b/assets/entities/worker/arbeiten-20.png similarity index 100% rename from assets/worker/umackern-20.png rename to assets/entities/worker/arbeiten-20.png diff --git a/assets/worker/umackern-21.png b/assets/entities/worker/arbeiten-21.png similarity index 100% rename from assets/worker/umackern-21.png rename to assets/entities/worker/arbeiten-21.png diff --git a/assets/worker/umackern-22.png b/assets/entities/worker/arbeiten-22.png similarity index 100% rename from assets/worker/umackern-22.png rename to assets/entities/worker/arbeiten-22.png diff --git a/assets/worker/umackern-23.png b/assets/entities/worker/arbeiten-23.png similarity index 100% rename from assets/worker/umackern-23.png rename to assets/entities/worker/arbeiten-23.png diff --git a/assets/worker/umackern-24.png b/assets/entities/worker/arbeiten-24.png similarity index 100% rename from assets/worker/umackern-24.png rename to assets/entities/worker/arbeiten-24.png diff --git a/assets/worker/umackern-3.png b/assets/entities/worker/arbeiten-3.png similarity index 100% rename from assets/worker/umackern-3.png rename to assets/entities/worker/arbeiten-3.png diff --git a/assets/worker/umackern-4.png b/assets/entities/worker/arbeiten-4.png similarity index 100% rename from assets/worker/umackern-4.png rename to assets/entities/worker/arbeiten-4.png diff --git a/assets/worker/umackern-5.png b/assets/entities/worker/arbeiten-5.png similarity index 100% rename from assets/worker/umackern-5.png rename to assets/entities/worker/arbeiten-5.png diff --git a/assets/worker/umackern-6.png b/assets/entities/worker/arbeiten-6.png similarity index 100% rename from assets/worker/umackern-6.png rename to assets/entities/worker/arbeiten-6.png diff --git a/assets/worker/umackern-7.png b/assets/entities/worker/arbeiten-7.png similarity index 100% rename from assets/worker/umackern-7.png rename to assets/entities/worker/arbeiten-7.png diff --git a/assets/worker/umackern-8.png b/assets/entities/worker/arbeiten-8.png similarity index 100% rename from assets/worker/umackern-8.png rename to assets/entities/worker/arbeiten-8.png diff --git a/assets/worker/umackern-9.png b/assets/entities/worker/arbeiten-9.png similarity index 100% rename from assets/worker/umackern-9.png rename to assets/entities/worker/arbeiten-9.png diff --git a/assets/worker/umackern.png b/assets/entities/worker/arbeiten.png similarity index 100% rename from assets/worker/umackern.png rename to assets/entities/worker/arbeiten.png diff --git a/assets/worker/die-0.png b/assets/entities/worker/die-0.png similarity index 100% rename from assets/worker/die-0.png rename to assets/entities/worker/die-0.png diff --git a/assets/worker/die-1.png b/assets/entities/worker/die-1.png similarity index 100% rename from assets/worker/die-1.png rename to assets/entities/worker/die-1.png diff --git a/assets/worker/die-10.png b/assets/entities/worker/die-10.png similarity index 100% rename from assets/worker/die-10.png rename to assets/entities/worker/die-10.png diff --git a/assets/worker/die-11.png b/assets/entities/worker/die-11.png similarity index 100% rename from assets/worker/die-11.png rename to assets/entities/worker/die-11.png diff --git a/assets/worker/die-12.png b/assets/entities/worker/die-12.png similarity index 100% rename from assets/worker/die-12.png rename to assets/entities/worker/die-12.png diff --git a/assets/worker/die-13.png b/assets/entities/worker/die-13.png similarity index 100% rename from assets/worker/die-13.png rename to assets/entities/worker/die-13.png diff --git a/assets/worker/die-14.png b/assets/entities/worker/die-14.png similarity index 100% rename from assets/worker/die-14.png rename to assets/entities/worker/die-14.png diff --git a/assets/worker/die-2.png b/assets/entities/worker/die-2.png similarity index 100% rename from assets/worker/die-2.png rename to assets/entities/worker/die-2.png diff --git a/assets/worker/die-3.png b/assets/entities/worker/die-3.png similarity index 100% rename from assets/worker/die-3.png rename to assets/entities/worker/die-3.png diff --git a/assets/worker/die-4.png b/assets/entities/worker/die-4.png similarity index 100% rename from assets/worker/die-4.png rename to assets/entities/worker/die-4.png diff --git a/assets/worker/die-5.png b/assets/entities/worker/die-5.png similarity index 100% rename from assets/worker/die-5.png rename to assets/entities/worker/die-5.png diff --git a/assets/worker/die-6.png b/assets/entities/worker/die-6.png similarity index 100% rename from assets/worker/die-6.png rename to assets/entities/worker/die-6.png diff --git a/assets/worker/die-7.png b/assets/entities/worker/die-7.png similarity index 100% rename from assets/worker/die-7.png rename to assets/entities/worker/die-7.png diff --git a/assets/worker/die-8.png b/assets/entities/worker/die-8.png similarity index 100% rename from assets/worker/die-8.png rename to assets/entities/worker/die-8.png diff --git a/assets/worker/die-9.png b/assets/entities/worker/die-9.png similarity index 100% rename from assets/worker/die-9.png rename to assets/entities/worker/die-9.png diff --git a/assets/worker/die.png b/assets/entities/worker/die.png similarity index 100% rename from assets/worker/die.png rename to assets/entities/worker/die.png diff --git a/assets/worker/walk-0.png b/assets/entities/worker/walk-0.png similarity index 100% rename from assets/worker/walk-0.png rename to assets/entities/worker/walk-0.png diff --git a/assets/worker/walk-1.png b/assets/entities/worker/walk-1.png similarity index 100% rename from assets/worker/walk-1.png rename to assets/entities/worker/walk-1.png diff --git a/assets/worker/walk-10.png b/assets/entities/worker/walk-10.png similarity index 100% rename from assets/worker/walk-10.png rename to assets/entities/worker/walk-10.png diff --git a/assets/worker/walk-11.png b/assets/entities/worker/walk-11.png similarity index 100% rename from assets/worker/walk-11.png rename to assets/entities/worker/walk-11.png diff --git a/assets/worker/walk-12.png b/assets/entities/worker/walk-12.png similarity index 100% rename from assets/worker/walk-12.png rename to assets/entities/worker/walk-12.png diff --git a/assets/worker/walk-13.png b/assets/entities/worker/walk-13.png similarity index 100% rename from assets/worker/walk-13.png rename to assets/entities/worker/walk-13.png diff --git a/assets/worker/walk-14.png b/assets/entities/worker/walk-14.png similarity index 100% rename from assets/worker/walk-14.png rename to assets/entities/worker/walk-14.png diff --git a/assets/worker/walk-15.png b/assets/entities/worker/walk-15.png similarity index 100% rename from assets/worker/walk-15.png rename to assets/entities/worker/walk-15.png diff --git a/assets/worker/walk-16.png b/assets/entities/worker/walk-16.png similarity index 100% rename from assets/worker/walk-16.png rename to assets/entities/worker/walk-16.png diff --git a/assets/worker/walk-17.png b/assets/entities/worker/walk-17.png similarity index 100% rename from assets/worker/walk-17.png rename to assets/entities/worker/walk-17.png diff --git a/assets/worker/walk-18.png b/assets/entities/worker/walk-18.png similarity index 100% rename from assets/worker/walk-18.png rename to assets/entities/worker/walk-18.png diff --git a/assets/worker/walk-19.png b/assets/entities/worker/walk-19.png similarity index 100% rename from assets/worker/walk-19.png rename to assets/entities/worker/walk-19.png diff --git a/assets/worker/walk-2.png b/assets/entities/worker/walk-2.png similarity index 100% rename from assets/worker/walk-2.png rename to assets/entities/worker/walk-2.png diff --git a/assets/worker/walk-20.png b/assets/entities/worker/walk-20.png similarity index 100% rename from assets/worker/walk-20.png rename to assets/entities/worker/walk-20.png diff --git a/assets/worker/walk-21.png b/assets/entities/worker/walk-21.png similarity index 100% rename from assets/worker/walk-21.png rename to assets/entities/worker/walk-21.png diff --git a/assets/worker/walk-22.png b/assets/entities/worker/walk-22.png similarity index 100% rename from assets/worker/walk-22.png rename to assets/entities/worker/walk-22.png diff --git a/assets/worker/walk-23.png b/assets/entities/worker/walk-23.png similarity index 100% rename from assets/worker/walk-23.png rename to assets/entities/worker/walk-23.png diff --git a/assets/worker/walk-24.png b/assets/entities/worker/walk-24.png similarity index 100% rename from assets/worker/walk-24.png rename to assets/entities/worker/walk-24.png diff --git a/assets/worker/walk-3.png b/assets/entities/worker/walk-3.png similarity index 100% rename from assets/worker/walk-3.png rename to assets/entities/worker/walk-3.png diff --git a/assets/worker/walk-4.png b/assets/entities/worker/walk-4.png similarity index 100% rename from assets/worker/walk-4.png rename to assets/entities/worker/walk-4.png diff --git a/assets/worker/walk-5.png b/assets/entities/worker/walk-5.png similarity index 100% rename from assets/worker/walk-5.png rename to assets/entities/worker/walk-5.png diff --git a/assets/worker/walk-6.png b/assets/entities/worker/walk-6.png similarity index 100% rename from assets/worker/walk-6.png rename to assets/entities/worker/walk-6.png diff --git a/assets/worker/walk-7.png b/assets/entities/worker/walk-7.png similarity index 100% rename from assets/worker/walk-7.png rename to assets/entities/worker/walk-7.png diff --git a/assets/worker/walk-8.png b/assets/entities/worker/walk-8.png similarity index 100% rename from assets/worker/walk-8.png rename to assets/entities/worker/walk-8.png diff --git a/assets/worker/walk-9.png b/assets/entities/worker/walk-9.png similarity index 100% rename from assets/worker/walk-9.png rename to assets/entities/worker/walk-9.png diff --git a/assets/worker/walk.png b/assets/entities/worker/walk.png similarity index 100% rename from assets/worker/walk.png rename to assets/entities/worker/walk.png diff --git a/assets/worker/worker.png b/assets/entities/worker/worker.png similarity index 100% rename from assets/worker/worker.png rename to assets/entities/worker/worker.png diff --git a/assets/construction.png b/assets/mapobjects/baustelle/idle.png similarity index 100% rename from assets/construction.png rename to assets/mapobjects/baustelle/idle.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 diff --git a/definitions.h b/definitions.h new file mode 100644 index 0000000..b6f4bc4 --- /dev/null +++ b/definitions.h @@ -0,0 +1,36 @@ +#ifndef DEFINITIONS_H_ +#define DEFINITIONS_H_ + +#define N 0 +#define NE 1 +#define E 3 +#define SE 5 +#define S 7 +#define SW 6 +#define W 4 +#define NW 2 +#define DIRECTIONS_AMOUNT 8 + +// Texture definitions +#define TE_CURSOR 0 +#define TE_WORKER 1 +#define TE_BUILDING 2 +#define TE_BAUSTELLE 3 + +#define TE_AMOUNT 4 +#define TE_ENTITY_LENGTH 104 +#define TE_MAPOBJECT_LENGTH 1 + + +// Definitions for animations +#define AN_WORKER 0 +#define AN_AMOUNT 1 + +#define AN_ENTITY_AMOUNT 3 +#define AN_ENTITY_IDLE 0 +#define AN_ENTITY_ARBEITEN 1 +#define AN_ENTITY_DIE 2 + + + +#endif diff --git a/game.c b/game.c index a28b5d0..e3e7c0d 100644 --- a/game.c +++ b/game.c @@ -18,7 +18,7 @@ Game *GameInit() game->textures = TextureAtlasInit(); - game->cursorSprite = SpriteCreate(game->textures, 0, 450, 225); + game->cursorSprite = SpriteCreate(game->textures, TE_CURSOR, 450, 225); game->inputHandler = malloc(sizeof(InputHandler)); game->inputHandler->pressed = 0; game->inputHandler->rectStart.x = 0; @@ -30,9 +30,6 @@ Game *GameInit() game->inputHandler->cursorWorldTile.x = 0; game->inputHandler->cursorWorldTile.y = 0; game->inputHandler->selectedLayer = -1; - game->inputHandler->cursorTextures = game->textures->cursorTextures; - game->inputHandler->cursorSprite = game->cursorSprite; - game->screen = SCREEN_MAINMENU; game->camera = malloc(sizeof(Camera2D)); diff --git a/main.c b/main.c index b1de90e..790dde1 100644 --- a/main.c +++ b/main.c @@ -50,12 +50,14 @@ int main(){ return 0; case SCREEN_GAME: - // Updating Sprites + // Updating Entities EntityListActAllEntities(game); // Drawing IsometricMap BeginMode2D(*(game->camera)); // Sorgt dafür, dass die Kameraposition beachtet wird IsometricMapDraw(game); + + SpriteListDrawAllSprites(game->sprites, game->map, game->camera); EndMode2D(); // User Input Handling