Animation fertig und drehen passt

main
Jonathan Hager 3 years ago
parent b9f0e7962f
commit 0732ddedeb
Signed by: JonathanHager
GPG Key ID: 34881E488569708C

@ -4,6 +4,7 @@
#include "../sprite.h" #include "../sprite.h"
#include "raylib.h" #include "raylib.h"
#include "raymath.h" #include "raymath.h"
#include "../Textures/textureIDs.h"
Node * ListCreateNode(Sprite *data){ Node * ListCreateNode(Sprite *data){
Node *new = (Node *) malloc(sizeof(Node)); Node *new = (Node *) malloc(sizeof(Node));
@ -105,13 +106,44 @@ void ListActAllSprites(Game *game){
// Change sprite according to direction // Change sprite according to direction
Vector2 nullvektor = {0,0}; Vector2 nullvektor = {0,0};
float f = Vector2Angle(movement, nullvektor); float angle = Vector2Angle(movement, nullvektor);
//printf("Angle: %f\n", f); angle = angle * RAD2DEG;
f /= 3.14; angle -= 35.26;
f *= 3.5;
f += 3.5; if(angle <= 22.5 && angle >= -22.5){
int index = (int) f; // E
current->data.texture = game->worker + index; 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);
}
} }
} }

@ -10,15 +10,23 @@ AnimationHandler * AnimationHandlerInit(Animation **animations){
new->currentAnimation = 0; new->currentAnimation = 0;
new->currentFrame = new->animations[new->currentAnimation]->head; new->currentFrame = new->animations[new->currentAnimation]->head;
new->forward = 1; new->forward = 1;
new->deltaElapsed = 0;
} }
void AnimationUpdate(AnimationHandler *animationHandler){ void AnimationUpdate(AnimationHandler *animationHandler){
if(animationHandler->forward == 1){ animationHandler->deltaElapsed += GetFrameTime();
animationHandler->currentFrame = animationHandler->currentFrame->next;
} if(animationHandler->deltaElapsed >= 0.2){
else{ if(animationHandler->forward == 1){
animationHandler->currentFrame = animationHandler->currentFrame->prev; animationHandler->currentFrame = animationHandler->currentFrame->next;
}
else{
animationHandler->currentFrame = animationHandler->currentFrame->prev;
}
animationHandler->deltaElapsed = 0;
} }
} }
void AnimationReset(AnimationHandler *animationHandler){ void AnimationReset(AnimationHandler *animationHandler){
@ -26,6 +34,9 @@ void AnimationReset(AnimationHandler *animationHandler){
} }
void AnimationChangeAnimation(AnimationHandler *animationHandler, int newAnimation){ void AnimationChangeAnimation(AnimationHandler *animationHandler, int newAnimation){
animationHandler->currentAnimation = newAnimation; if(animationHandler->currentAnimation != newAnimation){
AnimationReset(animationHandler); animationHandler->currentAnimation = newAnimation;
AnimationReset(animationHandler);
}
} }

@ -11,6 +11,7 @@ typedef struct AnimationHandler{
AnimationFrame *currentFrame; AnimationFrame *currentFrame;
int currentAnimation; int currentAnimation;
int forward; int forward;
float deltaElapsed;
} AnimationHandler; } AnimationHandler;
AnimationHandler * AnimationHandlerInit(Animation **animations); AnimationHandler * AnimationHandlerInit(Animation **animations);

@ -1,6 +1,15 @@
#ifndef TEXTUREIDS_H_ #ifndef TEXTUREIDS_H_
#define 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 cursor 0
#define worker 1 #define worker 1

@ -121,6 +121,7 @@ void LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTexture
int frame = 0; int frame = 0;
for(i=0; i < 24; i++){ for(i=0; i < 24; i++){
frame = i;
Animation *newAnimation = AnimationInit(); Animation *newAnimation = AnimationInit();
int obergrenze; int obergrenze;
@ -133,7 +134,7 @@ void LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTexture
for(j = 0; j < obergrenze; j++){ for(j = 0; j < obergrenze; j++){
AnimationInsertBack(newAnimation, (workerTextures+frame)); AnimationInsertBack(newAnimation, (workerTextures+frame));
frame++; frame += 8;
} }
workerAnimations[i] = newAnimation; workerAnimations[i] = newAnimation;

Binary file not shown.

Binary file not shown.

BIN
game.o

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
list.o

Binary file not shown.

@ -49,6 +49,7 @@ int main(){
c+=10; c+=10;
printf("Sprites: %d\n", c); printf("Sprites: %d\n", c);
*/ */
EndMode2D(); EndMode2D();
// Moving cursor Sprite to Mouse Pos and drawing it // Moving cursor Sprite to Mouse Pos and drawing it

BIN
main.o

Binary file not shown.

BIN
spiel

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
tile.o

Binary file not shown.
Loading…
Cancel
Save