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 "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);
}
}
}

@ -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);
}
}

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

@ -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

@ -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;

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;
printf("Sprites: %d\n", c);
*/
EndMode2D();
// 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