diff --git a/List/list.c b/List/list.c index 1e0b6d9..5f0ca4e 100644 --- a/List/list.c +++ b/List/list.c @@ -4,6 +4,7 @@ #include "../sprite.h" #include "raylib.h" #include "raymath.h" +#include "../Textures/textureIDs.h" Node * ListCreateNode(Sprite *data){ Node *new = (Node *) malloc(sizeof(Node)); @@ -105,13 +106,44 @@ void ListActAllSprites(Game *game){ // Change sprite according to direction Vector2 nullvektor = {0,0}; - float f = Vector2Angle(movement, nullvektor); - //printf("Angle: %f\n", f); - f /= 3.14; - f *= 3.5; - f += 3.5; - int index = (int) f; - current->data.texture = game->worker + index; + float angle = Vector2Angle(movement, nullvektor); + angle = angle * RAD2DEG; + angle -= 35.26; + + if(angle <= 22.5 && angle >= -22.5){ + // E + AnimationChangeAnimation(current->data.animationHandler, E); + } + else if(angle > 0 && angle <= 67.5){ + // NE + AnimationChangeAnimation(current->data.animationHandler, NE); + } + else if(angle > 0 && angle <= 112.5){ + // N + AnimationChangeAnimation(current->data.animationHandler, N); + } + else if(angle > 0 && angle <= 157.5){ + // NW + AnimationChangeAnimation(current->data.animationHandler, NW); + } + else if(angle < 0 && angle >= -67.5){ + // SE + AnimationChangeAnimation(current->data.animationHandler, SE); + } + else if(angle < 0 && angle >= -112.5){ + // S + AnimationChangeAnimation(current->data.animationHandler, S); + } + else if(angle < 0 && angle >= -157.5){ + // SW + AnimationChangeAnimation(current->data.animationHandler, SW); + } + else{ + // W + AnimationChangeAnimation(current->data.animationHandler, W); + } + + } } diff --git a/Textures/animationHandler.c b/Textures/animationHandler.c index c0d04df..fad7700 100644 --- a/Textures/animationHandler.c +++ b/Textures/animationHandler.c @@ -10,15 +10,23 @@ AnimationHandler * AnimationHandlerInit(Animation **animations){ new->currentAnimation = 0; new->currentFrame = new->animations[new->currentAnimation]->head; new->forward = 1; + new->deltaElapsed = 0; } void AnimationUpdate(AnimationHandler *animationHandler){ - if(animationHandler->forward == 1){ - animationHandler->currentFrame = animationHandler->currentFrame->next; - } - else{ - animationHandler->currentFrame = animationHandler->currentFrame->prev; + animationHandler->deltaElapsed += GetFrameTime(); + + if(animationHandler->deltaElapsed >= 0.2){ + if(animationHandler->forward == 1){ + animationHandler->currentFrame = animationHandler->currentFrame->next; + } + else{ + animationHandler->currentFrame = animationHandler->currentFrame->prev; + } + animationHandler->deltaElapsed = 0; } + + } void AnimationReset(AnimationHandler *animationHandler){ @@ -26,6 +34,9 @@ void AnimationReset(AnimationHandler *animationHandler){ } void AnimationChangeAnimation(AnimationHandler *animationHandler, int newAnimation){ - animationHandler->currentAnimation = newAnimation; - AnimationReset(animationHandler); + if(animationHandler->currentAnimation != newAnimation){ + animationHandler->currentAnimation = newAnimation; + AnimationReset(animationHandler); + } + } \ No newline at end of file diff --git a/Textures/animationHandler.h b/Textures/animationHandler.h index 3ab1e10..739b868 100644 --- a/Textures/animationHandler.h +++ b/Textures/animationHandler.h @@ -11,6 +11,7 @@ typedef struct AnimationHandler{ AnimationFrame *currentFrame; int currentAnimation; int forward; + float deltaElapsed; } AnimationHandler; AnimationHandler * AnimationHandlerInit(Animation **animations); diff --git a/Textures/textureIDs.h b/Textures/textureIDs.h index bf421e2..1cb932c 100644 --- a/Textures/textureIDs.h +++ b/Textures/textureIDs.h @@ -1,6 +1,15 @@ #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 diff --git a/Textures/textureatlas.c b/Textures/textureatlas.c index 58a9a6d..00ffb43 100644 --- a/Textures/textureatlas.c +++ b/Textures/textureatlas.c @@ -121,6 +121,7 @@ void LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTexture int frame = 0; for(i=0; i < 24; i++){ + frame = i; Animation *newAnimation = AnimationInit(); int obergrenze; @@ -133,7 +134,7 @@ void LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTexture for(j = 0; j < obergrenze; j++){ AnimationInsertBack(newAnimation, (workerTextures+frame)); - frame++; + frame += 8; } workerAnimations[i] = newAnimation; diff --git a/animation.o b/animation.o new file mode 100644 index 0000000..ad026d7 Binary files /dev/null and b/animation.o differ diff --git a/animationHandler.o b/animationHandler.o new file mode 100644 index 0000000..e67c079 Binary files /dev/null and b/animationHandler.o differ diff --git a/game.o b/game.o new file mode 100644 index 0000000..f29972f Binary files /dev/null and b/game.o differ diff --git a/inputHandler.o b/inputHandler.o new file mode 100644 index 0000000..ae05d6c Binary files /dev/null and b/inputHandler.o differ diff --git a/isometricMap.o b/isometricMap.o new file mode 100644 index 0000000..c1456e4 Binary files /dev/null and b/isometricMap.o differ diff --git a/isometricRenderer.o b/isometricRenderer.o new file mode 100644 index 0000000..12508ca Binary files /dev/null and b/isometricRenderer.o differ diff --git a/list.o b/list.o new file mode 100644 index 0000000..7533f36 Binary files /dev/null and b/list.o differ diff --git a/main.c b/main.c index a081f46..ba59fd8 100644 --- a/main.c +++ b/main.c @@ -49,6 +49,7 @@ int main(){ c+=10; printf("Sprites: %d\n", c); */ + EndMode2D(); // Moving cursor Sprite to Mouse Pos and drawing it diff --git a/main.o b/main.o new file mode 100644 index 0000000..cf7d598 Binary files /dev/null and b/main.o differ diff --git a/spiel b/spiel new file mode 100755 index 0000000..5875750 Binary files /dev/null and b/spiel differ diff --git a/sprite.o b/sprite.o new file mode 100644 index 0000000..b1b46fc Binary files /dev/null and b/sprite.o differ diff --git a/textureatlas.o b/textureatlas.o new file mode 100644 index 0000000..9e80d1e Binary files /dev/null and b/textureatlas.o differ diff --git a/tile.o b/tile.o new file mode 100644 index 0000000..b7873fa Binary files /dev/null and b/tile.o differ