diff --git a/.vscode/settings.json b/.vscode/settings.json index 6c2e911..66e1870 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,7 @@ "isometricrenderer.h": "c", "sprite.h": "c", "map": "c", - "isometricmap.h": "c" + "isometricmap.h": "c", + "animationhandler.h": "c" } } \ No newline at end of file diff --git a/Input/inputHandler.c b/Input/inputHandler.c index 02720f3..0a49b35 100644 --- a/Input/inputHandler.c +++ b/Input/inputHandler.c @@ -123,7 +123,7 @@ void mouseInput(Game *game){ // Add Sprite if(width + height <= 1){ - ListInsertBack(sprites, SpriteCreate(texture, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y)); + ListInsertBack(sprites, SpriteCreate(game->textures, 1, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y)); } // Berechnung, welche Sprites ausgewählt wurden, scuffed diff --git a/List/list.c b/List/list.c index 3e480e9..d4ab057 100644 --- a/List/list.c +++ b/List/list.c @@ -114,6 +114,8 @@ void ListActAllSprites(Game *game){ } } + SpriteUpdateAnimation(¤t->data); + current = current->next; } diff --git a/Makefile b/Makefile index 9a013e4..05a12fa 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ CC = gcc FLAGS = -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -spiel: main.o sprite.o inputHandler.o isometricRenderer.o isometricMap.o tile.o list.o game.o - $(CC) -o spiel main.o sprite.o inputHandler.o isometricRenderer.o isometricMap.o tile.o list.o game.o $(FLAGS) +spiel: main.o sprite.o inputHandler.o isometricRenderer.o isometricMap.o tile.o list.o game.o textureatlas.o animation.o animationHandler.o + $(CC) -o spiel main.o sprite.o inputHandler.o isometricRenderer.o isometricMap.o tile.o list.o game.o textureatlas.o animation.o animationHandler.o $(FLAGS) main.o: main.c $(CC) -c main.c $(FLAGS) @@ -28,5 +28,14 @@ tile.o: IsometricMap/tile.c game.o: game.c $(CC) -c game.c $(FLAGS) +textureatlas.o: Textures/textureatlas.c + $(CC) -c Textures/textureatlas.c $(FLAGS) + +animation.o: Textures/animation.c + $(CC) -c Textures/animation.c $(FLAGS) + +animationHandler.o: Textures/animationHandler.c + $(CC) -c Textures/animationHandler.c $(FLAGS) + clean: rm *.o spiel diff --git a/Textures/animation.c b/Textures/animation.c new file mode 100644 index 0000000..61f9eed --- /dev/null +++ b/Textures/animation.c @@ -0,0 +1,80 @@ +#include "animation.h" +#include "stdlib.h" + +Animation * AnimationInit(){ + Animation *animation = (Animation *) malloc(sizeof(Animation)); + + animation->head = 0; + animation->tail = 0; + + return animation; +} + +AnimationFrame * AnimationFrameCreate(Texture2D *texture){ + AnimationFrame *frame = (AnimationFrame *) malloc(sizeof(AnimationFrame)); + + frame->texture = texture; + frame->next = 0; + frame->prev = 0; + + return frame; +} + +void AnimationInsertFront(Animation *animation, Texture2D *texture){ + AnimationFrame *new = AnimationFrameCreate(texture); + + if(animation->head == 0){ + animation->head = new; + animation->tail = new; + + animation->head->prev = animation->tail; + animation->tail->next = animation->head->prev; + + } + else if(animation->head == animation->tail){ + animation->head = new; + + animation->head->next = animation->tail; + animation->head->prev = animation->tail; + + animation->tail->prev = animation->head; + animation->tail->next = animation->head; + } + else{ + animation->head->prev = new; + + new->next = animation->head; + new->prev = animation->tail; + + animation->tail->next = new; + animation->head = new; + } +} + +void AnimationInsertBack(Animation *animation, Texture2D *texture){ + AnimationFrame *new = AnimationFrameCreate(texture); + + if(animation->head == 0){ + animation->head = new; + animation->tail = new; + + animation->head->prev = animation->tail; + animation->tail->next = animation->head->prev; + } + else if(animation->head == animation->tail){ + animation->tail = new; + + animation->head->next = animation->tail; + animation->head->prev = animation->tail; + + animation->tail->prev = animation->head; + animation->tail->next = animation->head; + } + else{ + animation->tail->next = new; + new->prev = animation->tail; + new->next = animation->head; + animation->head->prev = new; + animation->tail = new; + } +} diff --git a/Textures/animation.h b/Textures/animation.h new file mode 100644 index 0000000..d2354c0 --- /dev/null +++ b/Textures/animation.h @@ -0,0 +1,27 @@ +#ifndef ANIMATION_H_ +#define ANIMATION_H_ +#include "raylib.h" + +typedef struct Animation Animation; +typedef struct AnimationFrame AnimationFrame; + +typedef struct Animation { + AnimationFrame *head; + AnimationFrame *tail; +} Animation; + +typedef struct AnimationFrame { + Texture2D *texture; + + AnimationFrame *next; + AnimationFrame *prev; +} AnimationFrame; + +Animation * AnimationInit(); + +AnimationFrame * AnimationFrameCreate(Texture2D *texture); + +void AnimationInsertFront(Animation *animation, Texture2D *texture); +void AnimationInsertBack(Animation *animation, Texture2D *texture); + +#endif \ No newline at end of file diff --git a/Textures/animationHandler.c b/Textures/animationHandler.c new file mode 100644 index 0000000..c0d04df --- /dev/null +++ b/Textures/animationHandler.c @@ -0,0 +1,31 @@ +#include "animationHandler.h" +#include "animation.h" +#include "stdlib.h" +#include "stdio.h" + +AnimationHandler * AnimationHandlerInit(Animation **animations){ + AnimationHandler *new = (AnimationHandler *) malloc(sizeof(AnimationHandler)); + + new->animations = animations; + new->currentAnimation = 0; + new->currentFrame = new->animations[new->currentAnimation]->head; + new->forward = 1; +} + +void AnimationUpdate(AnimationHandler *animationHandler){ + if(animationHandler->forward == 1){ + animationHandler->currentFrame = animationHandler->currentFrame->next; + } + else{ + animationHandler->currentFrame = animationHandler->currentFrame->prev; + } +} + +void AnimationReset(AnimationHandler *animationHandler){ + animationHandler->currentFrame = animationHandler->animations[animationHandler->currentAnimation]->head; +} + +void AnimationChangeAnimation(AnimationHandler *animationHandler, int newAnimation){ + animationHandler->currentAnimation = newAnimation; + AnimationReset(animationHandler); +} \ No newline at end of file diff --git a/Textures/animationHandler.h b/Textures/animationHandler.h new file mode 100644 index 0000000..3ab1e10 --- /dev/null +++ b/Textures/animationHandler.h @@ -0,0 +1,21 @@ +#ifndef ANIMATIONHANDLER_H_ +#define ANIMATIONHANDLER_H_ +#include "raylib.h" +#include "animation.h" +#include "stdio.h" + +typedef struct AnimationHandler AnimationHandler; + +typedef struct AnimationHandler{ + Animation **animations; + AnimationFrame *currentFrame; + int currentAnimation; + int forward; +} AnimationHandler; + +AnimationHandler * AnimationHandlerInit(Animation **animations); +void AnimationUpdate(AnimationHandler *animationHandler); +void AnimationReset(AnimationHandler *animationHandler); +void AnimationChangeAnimation(AnimationHandler *animationHandler, int newAnimation); + +#endif \ No newline at end of file diff --git a/Textures/textureIDs.h b/Textures/textureIDs.h new file mode 100644 index 0000000..bf421e2 --- /dev/null +++ b/Textures/textureIDs.h @@ -0,0 +1,7 @@ +#ifndef TEXTUREIDS_H_ +#define TEXTUREIDS_H_ + +#define cursor 0 +#define worker 1 + +#endif \ No newline at end of file diff --git a/Textures/textureatlas.c b/Textures/textureatlas.c new file mode 100644 index 0000000..58a9a6d --- /dev/null +++ b/Textures/textureatlas.c @@ -0,0 +1,141 @@ +#include "textureatlas.h" +#include "stdlib.h" +#include "raylib.h" +#include "string.h" +#include "stdio.h" + +TextureAtlas * TextureAtlasInit(){ + TextureAtlas *textures = (TextureAtlas *) malloc(sizeof(TextureAtlas)); + + LoadCursorTextures(textures->cursorTextures, textures->cursorAnimation); + LoadWorkerTextures(textures->workerTextures); + LoadWorkerAnimations(textures->workerAnimations, textures->workerTextures); + + return textures; +} + +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 LoadWorkerTextures(Texture2D *workerTextures){ + /* + Image worker1flip = LoadImage("assets/worker/worker-1.png"); + ImageFlipHorizontal(&worker1flip); + Image worker2flip = LoadImage("assets/worker/worker-2.png"); + ImageFlipHorizontal(&worker2flip); + Image worker3flip = LoadImage("assets/worker/worker-3.png"); + ImageFlipHorizontal(&worker3flip); + textures->workerTextures[6] = LoadTexture("assets/worker/worker-0.png"); + textures->workerTextures[5] = LoadTexture("assets/worker/worker-1.png"); + textures->workerTextures[7] = LoadTextureFromImage(worker1flip); + textures->workerTextures[4] = LoadTexture("assets/worker/worker-2.png"); + textures->workerTextures[0] = LoadTextureFromImage(worker2flip); + textures->workerTextures[3] = LoadTexture("assets/worker/worker-3.png"); + textures->workerTextures[1] = LoadTextureFromImage(worker3flip); + textures->workerTextures[2] = LoadTexture("assets/worker/worker-4.png"); + assets/worker/umackern-20.png + */ + + 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 + 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; + + + // 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++; + } + else{ + *(workerTextures + i) = LoadTexture(filename); + printf("\n"); + } + + strcpy(filename, ""); + strcpy(number, ""); + + if(i == 39){ + strcpy(beginning, "assets/worker/umackern-"); + file = 0; + } + else if(i == 79){ + strcpy(beginning, "assets/worker/die-"); + file = 0; + } + } +} + +void LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTextures){ + int i; + int j; + int frame = 0; + + for(i=0; i < 24; i++){ + Animation *newAnimation = AnimationInit(); + + int obergrenze; + if(frame <= 79){ + obergrenze = 5; + } + else{ + obergrenze = 3; + } + + for(j = 0; j < obergrenze; j++){ + AnimationInsertBack(newAnimation, (workerTextures+frame)); + frame++; + } + + workerAnimations[i] = newAnimation; + } +} diff --git a/Textures/textureatlas.h b/Textures/textureatlas.h index 9c843ea..1199d77 100644 --- a/Textures/textureatlas.h +++ b/Textures/textureatlas.h @@ -1,11 +1,24 @@ #ifndef TEXTUREATLAS_H_ #define TEXTUREATLAS_H_ #include "raylib.h" +#include "animation.h" + +typedef struct TextureAtlas TextureAtlas; typedef struct TextureAtlas{ Texture2D cursorTextures[2]; - Texture2D workerTextures[7]; + Animation *cursorAnimation[1]; + + 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 LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTextures); + #endif \ No newline at end of file diff --git a/assets/worker/worker-52.png b/assets/worker/die-0.png similarity index 60% rename from assets/worker/worker-52.png rename to assets/worker/die-0.png index eee1e53..cff86d5 100644 Binary files a/assets/worker/worker-52.png and b/assets/worker/die-0.png differ diff --git a/assets/worker/worker-50.png b/assets/worker/die-1.png similarity index 60% rename from assets/worker/worker-50.png rename to assets/worker/die-1.png index 037583b..cff86d5 100644 Binary files a/assets/worker/worker-50.png and b/assets/worker/die-1.png differ diff --git a/assets/worker/worker-60.png b/assets/worker/die-10.png similarity index 52% rename from assets/worker/worker-60.png rename to assets/worker/die-10.png index 89f48b3..f22e487 100644 Binary files a/assets/worker/worker-60.png and b/assets/worker/die-10.png differ diff --git a/assets/worker/worker-61.png b/assets/worker/die-11.png similarity index 52% rename from assets/worker/worker-61.png rename to assets/worker/die-11.png index 5871ed2..f22e487 100644 Binary files a/assets/worker/worker-61.png and b/assets/worker/die-11.png differ diff --git a/assets/worker/worker-62.png b/assets/worker/die-12.png similarity index 52% rename from assets/worker/worker-62.png rename to assets/worker/die-12.png index 72c11c1..f22e487 100644 Binary files a/assets/worker/worker-62.png and b/assets/worker/die-12.png differ diff --git a/assets/worker/die-13.png b/assets/worker/die-13.png new file mode 100644 index 0000000..cccee80 Binary files /dev/null and b/assets/worker/die-13.png differ diff --git a/assets/worker/die-14.png b/assets/worker/die-14.png new file mode 100644 index 0000000..cccee80 Binary files /dev/null and b/assets/worker/die-14.png differ diff --git a/assets/worker/worker-51.png b/assets/worker/die-2.png similarity index 60% rename from assets/worker/worker-51.png rename to assets/worker/die-2.png index 28fa49f..cff86d5 100644 Binary files a/assets/worker/worker-51.png and b/assets/worker/die-2.png differ diff --git a/assets/worker/die-3.png b/assets/worker/die-3.png new file mode 100644 index 0000000..e17de60 Binary files /dev/null and b/assets/worker/die-3.png differ diff --git a/assets/worker/die-4.png b/assets/worker/die-4.png new file mode 100644 index 0000000..e17de60 Binary files /dev/null and b/assets/worker/die-4.png differ diff --git a/assets/worker/die-5.png b/assets/worker/die-5.png new file mode 100644 index 0000000..1c979aa Binary files /dev/null and b/assets/worker/die-5.png differ diff --git a/assets/worker/die-6.png b/assets/worker/die-6.png new file mode 100644 index 0000000..1c979aa Binary files /dev/null and b/assets/worker/die-6.png differ diff --git a/assets/worker/die-7.png b/assets/worker/die-7.png new file mode 100644 index 0000000..1c979aa Binary files /dev/null and b/assets/worker/die-7.png differ diff --git a/assets/worker/die-8.png b/assets/worker/die-8.png new file mode 100644 index 0000000..821d277 Binary files /dev/null and b/assets/worker/die-8.png differ diff --git a/assets/worker/die-9.png b/assets/worker/die-9.png new file mode 100644 index 0000000..821d277 Binary files /dev/null and b/assets/worker/die-9.png differ diff --git a/assets/worker/die.png b/assets/worker/die.png new file mode 100644 index 0000000..d0d79a3 Binary files /dev/null and b/assets/worker/die.png differ diff --git a/assets/worker/umackern-0.png b/assets/worker/umackern-0.png new file mode 100644 index 0000000..2fcc708 Binary files /dev/null and b/assets/worker/umackern-0.png differ diff --git a/assets/worker/umackern-1.png b/assets/worker/umackern-1.png new file mode 100644 index 0000000..704799c Binary files /dev/null and b/assets/worker/umackern-1.png differ diff --git a/assets/worker/worker-35.png b/assets/worker/umackern-10.png similarity index 59% rename from assets/worker/worker-35.png rename to assets/worker/umackern-10.png index 04fa0ea..281dcad 100644 Binary files a/assets/worker/worker-35.png and b/assets/worker/umackern-10.png differ diff --git a/assets/worker/umackern-11.png b/assets/worker/umackern-11.png new file mode 100644 index 0000000..1f3f449 Binary files /dev/null and b/assets/worker/umackern-11.png differ diff --git a/assets/worker/umackern-12.png b/assets/worker/umackern-12.png new file mode 100644 index 0000000..72c8d1c Binary files /dev/null and b/assets/worker/umackern-12.png differ diff --git a/assets/worker/umackern-13.png b/assets/worker/umackern-13.png new file mode 100644 index 0000000..be6e7f3 Binary files /dev/null and b/assets/worker/umackern-13.png differ diff --git a/assets/worker/umackern-14.png b/assets/worker/umackern-14.png new file mode 100644 index 0000000..3843b7c Binary files /dev/null and b/assets/worker/umackern-14.png differ diff --git a/assets/worker/worker-40.png b/assets/worker/umackern-15.png similarity index 52% rename from assets/worker/worker-40.png rename to assets/worker/umackern-15.png index 50028fc..33a4551 100644 Binary files a/assets/worker/worker-40.png and b/assets/worker/umackern-15.png differ diff --git a/assets/worker/umackern-16.png b/assets/worker/umackern-16.png new file mode 100644 index 0000000..73b5d1f Binary files /dev/null and b/assets/worker/umackern-16.png differ diff --git a/assets/worker/worker-42.png b/assets/worker/umackern-17.png similarity index 50% rename from assets/worker/worker-42.png rename to assets/worker/umackern-17.png index ff266e4..59f1850 100644 Binary files a/assets/worker/worker-42.png and b/assets/worker/umackern-17.png differ diff --git a/assets/worker/worker-43.png b/assets/worker/umackern-18.png similarity index 58% rename from assets/worker/worker-43.png rename to assets/worker/umackern-18.png index aeea36a..f11f8cf 100644 Binary files a/assets/worker/worker-43.png and b/assets/worker/umackern-18.png differ diff --git a/assets/worker/umackern-19.png b/assets/worker/umackern-19.png new file mode 100644 index 0000000..af9f8ec Binary files /dev/null and b/assets/worker/umackern-19.png differ diff --git a/assets/worker/umackern-2.png b/assets/worker/umackern-2.png new file mode 100644 index 0000000..db16f66 Binary files /dev/null and b/assets/worker/umackern-2.png differ diff --git a/assets/worker/umackern-20.png b/assets/worker/umackern-20.png new file mode 100644 index 0000000..ab5db73 Binary files /dev/null and b/assets/worker/umackern-20.png differ diff --git a/assets/worker/umackern-21.png b/assets/worker/umackern-21.png new file mode 100644 index 0000000..b32fd05 Binary files /dev/null and b/assets/worker/umackern-21.png differ diff --git a/assets/worker/umackern-22.png b/assets/worker/umackern-22.png new file mode 100644 index 0000000..9d7e22e Binary files /dev/null and b/assets/worker/umackern-22.png differ diff --git a/assets/worker/worker-48.png b/assets/worker/umackern-23.png similarity index 59% rename from assets/worker/worker-48.png rename to assets/worker/umackern-23.png index 436f8d9..f9f50b4 100644 Binary files a/assets/worker/worker-48.png and b/assets/worker/umackern-23.png differ diff --git a/assets/worker/umackern-24.png b/assets/worker/umackern-24.png new file mode 100644 index 0000000..c9730fc Binary files /dev/null and b/assets/worker/umackern-24.png differ diff --git a/assets/worker/umackern-3.png b/assets/worker/umackern-3.png new file mode 100644 index 0000000..974ba72 Binary files /dev/null and b/assets/worker/umackern-3.png differ diff --git a/assets/worker/umackern-4.png b/assets/worker/umackern-4.png new file mode 100644 index 0000000..02d6728 Binary files /dev/null and b/assets/worker/umackern-4.png differ diff --git a/assets/worker/umackern-5.png b/assets/worker/umackern-5.png new file mode 100644 index 0000000..81fc67e Binary files /dev/null and b/assets/worker/umackern-5.png differ diff --git a/assets/worker/umackern-6.png b/assets/worker/umackern-6.png new file mode 100644 index 0000000..01a8c8f Binary files /dev/null and b/assets/worker/umackern-6.png differ diff --git a/assets/worker/umackern-7.png b/assets/worker/umackern-7.png new file mode 100644 index 0000000..0f8dd95 Binary files /dev/null and b/assets/worker/umackern-7.png differ diff --git a/assets/worker/umackern-8.png b/assets/worker/umackern-8.png new file mode 100644 index 0000000..e982415 Binary files /dev/null and b/assets/worker/umackern-8.png differ diff --git a/assets/worker/worker-34.png b/assets/worker/umackern-9.png similarity index 59% rename from assets/worker/worker-34.png rename to assets/worker/umackern-9.png index 3c1c102..c0a3003 100644 Binary files a/assets/worker/worker-34.png and b/assets/worker/umackern-9.png differ diff --git a/assets/worker/umackern.png b/assets/worker/umackern.png new file mode 100644 index 0000000..4a67f87 Binary files /dev/null and b/assets/worker/umackern.png differ diff --git a/assets/worker/walk-0.png b/assets/worker/walk-0.png new file mode 100644 index 0000000..9ad4457 Binary files /dev/null and b/assets/worker/walk-0.png differ diff --git a/assets/worker/worker-1.png b/assets/worker/walk-1.png similarity index 62% rename from assets/worker/worker-1.png rename to assets/worker/walk-1.png index 633fb2c..19d9fdf 100644 Binary files a/assets/worker/worker-1.png and b/assets/worker/walk-1.png differ diff --git a/assets/worker/worker-10.png b/assets/worker/walk-10.png similarity index 54% rename from assets/worker/worker-10.png rename to assets/worker/walk-10.png index a0364cf..4027bad 100644 Binary files a/assets/worker/worker-10.png and b/assets/worker/walk-10.png differ diff --git a/assets/worker/worker-11.png b/assets/worker/walk-11.png similarity index 54% rename from assets/worker/worker-11.png rename to assets/worker/walk-11.png index fb7829f..9a0603d 100644 Binary files a/assets/worker/worker-11.png and b/assets/worker/walk-11.png differ diff --git a/assets/worker/walk-12.png b/assets/worker/walk-12.png new file mode 100644 index 0000000..a867c78 Binary files /dev/null and b/assets/worker/walk-12.png differ diff --git a/assets/worker/walk-13.png b/assets/worker/walk-13.png new file mode 100644 index 0000000..dc2d7b3 Binary files /dev/null and b/assets/worker/walk-13.png differ diff --git a/assets/worker/walk-14.png b/assets/worker/walk-14.png new file mode 100644 index 0000000..0c2fd59 Binary files /dev/null and b/assets/worker/walk-14.png differ diff --git a/assets/worker/walk-15.png b/assets/worker/walk-15.png new file mode 100644 index 0000000..18a1bd5 Binary files /dev/null and b/assets/worker/walk-15.png differ diff --git a/assets/worker/walk-16.png b/assets/worker/walk-16.png new file mode 100644 index 0000000..bec1d42 Binary files /dev/null and b/assets/worker/walk-16.png differ diff --git a/assets/worker/walk-17.png b/assets/worker/walk-17.png new file mode 100644 index 0000000..cc2ce19 Binary files /dev/null and b/assets/worker/walk-17.png differ diff --git a/assets/worker/walk-18.png b/assets/worker/walk-18.png new file mode 100644 index 0000000..f77eb06 Binary files /dev/null and b/assets/worker/walk-18.png differ diff --git a/assets/worker/walk-19.png b/assets/worker/walk-19.png new file mode 100644 index 0000000..d842639 Binary files /dev/null and b/assets/worker/walk-19.png differ diff --git a/assets/worker/walk-2.png b/assets/worker/walk-2.png new file mode 100644 index 0000000..f0dcc5d Binary files /dev/null and b/assets/worker/walk-2.png differ diff --git a/assets/worker/walk-20.png b/assets/worker/walk-20.png new file mode 100644 index 0000000..9eb7dbf Binary files /dev/null and b/assets/worker/walk-20.png differ diff --git a/assets/worker/walk-21.png b/assets/worker/walk-21.png new file mode 100644 index 0000000..255d340 Binary files /dev/null and b/assets/worker/walk-21.png differ diff --git a/assets/worker/walk-22.png b/assets/worker/walk-22.png new file mode 100644 index 0000000..a456407 Binary files /dev/null and b/assets/worker/walk-22.png differ diff --git a/assets/worker/walk-23.png b/assets/worker/walk-23.png new file mode 100644 index 0000000..44e85b5 Binary files /dev/null and b/assets/worker/walk-23.png differ diff --git a/assets/worker/worker-24.png b/assets/worker/walk-24.png similarity index 64% rename from assets/worker/worker-24.png rename to assets/worker/walk-24.png index 93cdfbf..d039607 100644 Binary files a/assets/worker/worker-24.png and b/assets/worker/walk-24.png differ diff --git a/assets/worker/walk-3.png b/assets/worker/walk-3.png new file mode 100644 index 0000000..8daa831 Binary files /dev/null and b/assets/worker/walk-3.png differ diff --git a/assets/worker/walk-4.png b/assets/worker/walk-4.png new file mode 100644 index 0000000..b0e245d Binary files /dev/null and b/assets/worker/walk-4.png differ diff --git a/assets/worker/worker-5.png b/assets/worker/walk-5.png similarity index 54% rename from assets/worker/worker-5.png rename to assets/worker/walk-5.png index d69bc7a..6fefd33 100644 Binary files a/assets/worker/worker-5.png and b/assets/worker/walk-5.png differ diff --git a/assets/worker/worker-6.png b/assets/worker/walk-6.png similarity index 65% rename from assets/worker/worker-6.png rename to assets/worker/walk-6.png index 71299f7..2dfadb9 100644 Binary files a/assets/worker/worker-6.png and b/assets/worker/walk-6.png differ diff --git a/assets/worker/worker-7.png b/assets/worker/walk-7.png similarity index 56% rename from assets/worker/worker-7.png rename to assets/worker/walk-7.png index 5a738a7..432121a 100644 Binary files a/assets/worker/worker-7.png and b/assets/worker/walk-7.png differ diff --git a/assets/worker/walk-8.png b/assets/worker/walk-8.png new file mode 100644 index 0000000..36a3e54 Binary files /dev/null and b/assets/worker/walk-8.png differ diff --git a/assets/worker/walk-9.png b/assets/worker/walk-9.png new file mode 100644 index 0000000..8f7f302 Binary files /dev/null and b/assets/worker/walk-9.png differ diff --git a/assets/worker/walk.png b/assets/worker/walk.png new file mode 100644 index 0000000..058a1db Binary files /dev/null and b/assets/worker/walk.png differ diff --git a/assets/worker/worker-0.png b/assets/worker/worker-0.png deleted file mode 100644 index bdb2e07..0000000 Binary files a/assets/worker/worker-0.png and /dev/null differ diff --git a/assets/worker/worker-12.png b/assets/worker/worker-12.png deleted file mode 100644 index 942e61f..0000000 Binary files a/assets/worker/worker-12.png and /dev/null differ diff --git a/assets/worker/worker-13.png b/assets/worker/worker-13.png deleted file mode 100644 index dd3c9ba..0000000 Binary files a/assets/worker/worker-13.png and /dev/null differ diff --git a/assets/worker/worker-14.png b/assets/worker/worker-14.png deleted file mode 100644 index cf1f9fb..0000000 Binary files a/assets/worker/worker-14.png and /dev/null differ diff --git a/assets/worker/worker-15.png b/assets/worker/worker-15.png deleted file mode 100644 index 4f6846f..0000000 Binary files a/assets/worker/worker-15.png and /dev/null differ diff --git a/assets/worker/worker-16.png b/assets/worker/worker-16.png deleted file mode 100644 index 1e9e0cb..0000000 Binary files a/assets/worker/worker-16.png and /dev/null differ diff --git a/assets/worker/worker-17.png b/assets/worker/worker-17.png deleted file mode 100644 index b16dc07..0000000 Binary files a/assets/worker/worker-17.png and /dev/null differ diff --git a/assets/worker/worker-18.png b/assets/worker/worker-18.png deleted file mode 100644 index bc8e758..0000000 Binary files a/assets/worker/worker-18.png and /dev/null differ diff --git a/assets/worker/worker-19.png b/assets/worker/worker-19.png deleted file mode 100644 index 566ecb9..0000000 Binary files a/assets/worker/worker-19.png and /dev/null differ diff --git a/assets/worker/worker-2.png b/assets/worker/worker-2.png deleted file mode 100644 index 0f8c280..0000000 Binary files a/assets/worker/worker-2.png and /dev/null differ diff --git a/assets/worker/worker-20.png b/assets/worker/worker-20.png deleted file mode 100644 index 3a3755b..0000000 Binary files a/assets/worker/worker-20.png and /dev/null differ diff --git a/assets/worker/worker-21.png b/assets/worker/worker-21.png deleted file mode 100644 index cdceaf8..0000000 Binary files a/assets/worker/worker-21.png and /dev/null differ diff --git a/assets/worker/worker-22.png b/assets/worker/worker-22.png deleted file mode 100644 index 3be0fda..0000000 Binary files a/assets/worker/worker-22.png and /dev/null differ diff --git a/assets/worker/worker-23.png b/assets/worker/worker-23.png deleted file mode 100644 index 2a1740d..0000000 Binary files a/assets/worker/worker-23.png and /dev/null differ diff --git a/assets/worker/worker-25.png b/assets/worker/worker-25.png deleted file mode 100644 index 5a3edfc..0000000 Binary files a/assets/worker/worker-25.png and /dev/null differ diff --git a/assets/worker/worker-26.png b/assets/worker/worker-26.png deleted file mode 100644 index 3d713c4..0000000 Binary files a/assets/worker/worker-26.png and /dev/null differ diff --git a/assets/worker/worker-27.png b/assets/worker/worker-27.png deleted file mode 100644 index 5dce7b8..0000000 Binary files a/assets/worker/worker-27.png and /dev/null differ diff --git a/assets/worker/worker-28.png b/assets/worker/worker-28.png deleted file mode 100644 index acaef65..0000000 Binary files a/assets/worker/worker-28.png and /dev/null differ diff --git a/assets/worker/worker-29.png b/assets/worker/worker-29.png deleted file mode 100644 index 2ee4e93..0000000 Binary files a/assets/worker/worker-29.png and /dev/null differ diff --git a/assets/worker/worker-3.png b/assets/worker/worker-3.png deleted file mode 100644 index 8fb1ff9..0000000 Binary files a/assets/worker/worker-3.png and /dev/null differ diff --git a/assets/worker/worker-30.png b/assets/worker/worker-30.png deleted file mode 100644 index b371e86..0000000 Binary files a/assets/worker/worker-30.png and /dev/null differ diff --git a/assets/worker/worker-31.png b/assets/worker/worker-31.png deleted file mode 100644 index ec61a53..0000000 Binary files a/assets/worker/worker-31.png and /dev/null differ diff --git a/assets/worker/worker-32.png b/assets/worker/worker-32.png deleted file mode 100644 index 030e1f4..0000000 Binary files a/assets/worker/worker-32.png and /dev/null differ diff --git a/assets/worker/worker-33.png b/assets/worker/worker-33.png deleted file mode 100644 index 65fdeba..0000000 Binary files a/assets/worker/worker-33.png and /dev/null differ diff --git a/assets/worker/worker-36.png b/assets/worker/worker-36.png deleted file mode 100644 index 90e9253..0000000 Binary files a/assets/worker/worker-36.png and /dev/null differ diff --git a/assets/worker/worker-37.png b/assets/worker/worker-37.png deleted file mode 100644 index 85f21e9..0000000 Binary files a/assets/worker/worker-37.png and /dev/null differ diff --git a/assets/worker/worker-38.png b/assets/worker/worker-38.png deleted file mode 100644 index 8fe108f..0000000 Binary files a/assets/worker/worker-38.png and /dev/null differ diff --git a/assets/worker/worker-39.png b/assets/worker/worker-39.png deleted file mode 100644 index 3e94341..0000000 Binary files a/assets/worker/worker-39.png and /dev/null differ diff --git a/assets/worker/worker-4.png b/assets/worker/worker-4.png deleted file mode 100644 index ef2285c..0000000 Binary files a/assets/worker/worker-4.png and /dev/null differ diff --git a/assets/worker/worker-41.png b/assets/worker/worker-41.png deleted file mode 100644 index 8fd22de..0000000 Binary files a/assets/worker/worker-41.png and /dev/null differ diff --git a/assets/worker/worker-44.png b/assets/worker/worker-44.png deleted file mode 100644 index 9d9376f..0000000 Binary files a/assets/worker/worker-44.png and /dev/null differ diff --git a/assets/worker/worker-45.png b/assets/worker/worker-45.png deleted file mode 100644 index e9c9c65..0000000 Binary files a/assets/worker/worker-45.png and /dev/null differ diff --git a/assets/worker/worker-46.png b/assets/worker/worker-46.png deleted file mode 100644 index 6f367a2..0000000 Binary files a/assets/worker/worker-46.png and /dev/null differ diff --git a/assets/worker/worker-47.png b/assets/worker/worker-47.png deleted file mode 100644 index a80970a..0000000 Binary files a/assets/worker/worker-47.png and /dev/null differ diff --git a/assets/worker/worker-49.png b/assets/worker/worker-49.png deleted file mode 100644 index 8d927a0..0000000 Binary files a/assets/worker/worker-49.png and /dev/null differ diff --git a/assets/worker/worker-53.png b/assets/worker/worker-53.png deleted file mode 100644 index 39187c2..0000000 Binary files a/assets/worker/worker-53.png and /dev/null differ diff --git a/assets/worker/worker-54.png b/assets/worker/worker-54.png deleted file mode 100644 index 2f6e414..0000000 Binary files a/assets/worker/worker-54.png and /dev/null differ diff --git a/assets/worker/worker-55.png b/assets/worker/worker-55.png deleted file mode 100644 index 7212332..0000000 Binary files a/assets/worker/worker-55.png and /dev/null differ diff --git a/assets/worker/worker-56.png b/assets/worker/worker-56.png deleted file mode 100644 index 6fdb1c9..0000000 Binary files a/assets/worker/worker-56.png and /dev/null differ diff --git a/assets/worker/worker-57.png b/assets/worker/worker-57.png deleted file mode 100644 index 3f99196..0000000 Binary files a/assets/worker/worker-57.png and /dev/null differ diff --git a/assets/worker/worker-58.png b/assets/worker/worker-58.png deleted file mode 100644 index 7b0a857..0000000 Binary files a/assets/worker/worker-58.png and /dev/null differ diff --git a/assets/worker/worker-59.png b/assets/worker/worker-59.png deleted file mode 100644 index 628ad78..0000000 Binary files a/assets/worker/worker-59.png and /dev/null differ diff --git a/assets/worker/worker-63.png b/assets/worker/worker-63.png deleted file mode 100644 index ec28ce1..0000000 Binary files a/assets/worker/worker-63.png and /dev/null differ diff --git a/assets/worker/worker-64.png b/assets/worker/worker-64.png deleted file mode 100644 index e0d8d1e..0000000 Binary files a/assets/worker/worker-64.png and /dev/null differ diff --git a/assets/worker/worker-8.png b/assets/worker/worker-8.png deleted file mode 100644 index 8904e98..0000000 Binary files a/assets/worker/worker-8.png and /dev/null differ diff --git a/assets/worker/worker-9.png b/assets/worker/worker-9.png deleted file mode 100644 index 3cf523d..0000000 Binary files a/assets/worker/worker-9.png and /dev/null differ diff --git a/game.c b/game.c index edf1d14..9136727 100644 --- a/game.c +++ b/game.c @@ -5,19 +5,17 @@ #include "List/list.h" #include "Input/inputHandler.h" #include "IsometricMap/isometricMap.h" +#include "Textures/textureatlas.h" #include "stdio.h" Game *GameInit() { Game *game = (Game *)malloc(sizeof(Game)); - game->cursorTextures[0] = LoadTexture("assets/cursor.gif"); - game->cursorTextures[1] = LoadTexture("assets/cursor_down.gif"); - - // game->cursorSprite = {&(cursorTextures[0]), 450, 225}; - // game->cursorSprite = (Sprite *) malloc(sizeof(Sprite)); - game->cursorSprite = SpriteCreate(game->cursorTextures, 450, 225); - + game->textures = TextureAtlasInit(); + + game->cursorSprite = SpriteCreate(game->textures, 0, 450, 225); +/* Image worker1flip = LoadImage("assets/worker/worker-1.png"); ImageFlipHorizontal(&worker1flip); Image worker2flip = LoadImage("assets/worker/worker-2.png"); @@ -32,7 +30,7 @@ Game *GameInit() game->worker[3] = LoadTexture("assets/worker/worker-3.png"); game->worker[1] = LoadTextureFromImage(worker3flip); game->worker[2] = LoadTexture("assets/worker/worker-4.png"); - +*/ game->inputHandler = (InputHandler *)malloc(sizeof(InputHandler)); game->inputHandler->pressed = 0; game->inputHandler->rectStart.x = 0; @@ -44,7 +42,7 @@ Game *GameInit() game->inputHandler->cursorWorldTile.x = 0; game->inputHandler->cursorWorldTile.y = 0; game->inputHandler->selectedLayer = -1; - game->inputHandler->cursorTextures = game->cursorTextures; + game->inputHandler->cursorTextures = game->textures->cursorTextures; game->inputHandler->cursorSprite = game->cursorSprite; game->camera = (Camera2D *)malloc(sizeof(Camera2D)); diff --git a/game.h b/game.h index 3722fc5..190ac8e 100644 --- a/game.h +++ b/game.h @@ -5,8 +5,8 @@ // So kann man die includes umgehen, also keine Circular dependencies mehr :) typedef struct Game{ - Texture2D cursorTextures[2]; Texture2D worker[8]; + struct TextureAtlas *textures; struct Sprite *cursorSprite; struct List *sprites; struct InputHandler *inputHandler; diff --git a/sprite.c b/sprite.c index 6c31db1..38845b4 100644 --- a/sprite.c +++ b/sprite.c @@ -3,8 +3,13 @@ #include #include #include "IsometricMap/isometricMap.h" +#include "Textures/textureIDs.h" +#include "Textures/animationHandler.h" +#include "Textures/animation.h" +#include "Textures/textureatlas.h" void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, int y){ + /* if(*spriteAmount < 100){ (sprites + *spriteAmount) -> texture = texture; (sprites + *spriteAmount) -> x = x; @@ -18,6 +23,7 @@ void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, in else{ printf("Voll\n"); } + */ } void DrawSpriteToWorld(Sprite *sprite, IsometricMap *map, Camera2D *camera){ @@ -52,12 +58,34 @@ void DrawSpriteToScreen(Sprite *sprite){ } } -Sprite * SpriteCreate(Texture2D *texture, int x, int y){ +void SpriteUpdateAnimation(Sprite *sprite){ + AnimationUpdate(sprite->animationHandler); + sprite->texture = sprite->animationHandler->currentFrame->texture; +} + +Sprite * SpriteCreate(TextureAtlas *atlas, int textureID, int x, int y){ Sprite *newSprite = (Sprite *) malloc(sizeof(Sprite)); - newSprite->texture = texture; - newSprite->x = x - texture->width / 2; - newSprite->y = y - texture->height / 2; + //AnimationHandler create + //Animation **animations = atlas->workerAnimations; + 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 aufgerufen oder ID nicht bekannt!!!\n\n\n\n\n\n\n\n"); + } + + AnimationHandler *newHandler = AnimationHandlerInit(animations); + + newSprite->animationHandler = newHandler; + newSprite->texture = newSprite->animationHandler->currentFrame->texture; + newSprite->x = x - newSprite->texture->width / 2; + newSprite->y = y - newSprite->texture->height / 2; newSprite->destX = x; newSprite->destY = y; newSprite->hasDestination = 0; diff --git a/sprite.h b/sprite.h index ddc0c65..1fb63de 100644 --- a/sprite.h +++ b/sprite.h @@ -2,8 +2,11 @@ #define SPRITE_H_ #include "raylib.h" #include "IsometricMap/isometricMap.h" +#include "Textures/animationHandler.h" +#include "Textures/textureatlas.h" typedef struct Sprite { + AnimationHandler *animationHandler; Texture2D *texture; float x; float y; @@ -17,7 +20,8 @@ void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, in void DrawSpriteToWorld(Sprite *sprite, IsometricMap *map, Camera2D *camera); void DrawSpriteToScreen(Sprite *sprite); +void SpriteUpdateAnimation(Sprite *sprite); -Sprite * SpriteCreate(Texture2D *texture, int x, int y); +Sprite * SpriteCreate(TextureAtlas *atlas, int textureID, int x, int y); #endif