Merge branch 'Animation'

main
JanEhehalt 3 years ago
commit 472c3f1778

@ -4,6 +4,7 @@
"isometricrenderer.h": "c",
"sprite.h": "c",
"map": "c",
"isometricmap.h": "c"
"isometricmap.h": "c",
"animationhandler.h": "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

@ -114,6 +114,8 @@ void ListActAllSprites(Game *game){
}
}
SpriteUpdateAnimation(&current->data);
current = current->next;
}

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

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

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

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

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

@ -0,0 +1,7 @@
#ifndef TEXTUREIDS_H_
#define TEXTUREIDS_H_
#define cursor 0
#define worker 1
#endif

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

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 732 B

After

Width:  |  Height:  |  Size: 704 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 732 B

After

Width:  |  Height:  |  Size: 704 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 842 B

After

Width:  |  Height:  |  Size: 814 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 842 B

After

Width:  |  Height:  |  Size: 814 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 842 B

After

Width:  |  Height:  |  Size: 814 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 820 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 820 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 732 B

After

Width:  |  Height:  |  Size: 704 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 757 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 757 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 771 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 771 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 760 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 753 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 799 B

After

Width:  |  Height:  |  Size: 771 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 775 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 771 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 817 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 782 B

After

Width:  |  Height:  |  Size: 754 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 782 B

After

Width:  |  Height:  |  Size: 754 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 783 B

After

Width:  |  Height:  |  Size: 755 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 733 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 749 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 765 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 766 B

After

Width:  |  Height:  |  Size: 738 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 767 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 758 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 816 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 772 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 736 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 700 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 777 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 840 B

After

Width:  |  Height:  |  Size: 812 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 728 B

After

Width:  |  Height:  |  Size: 700 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 724 B

After

Width:  |  Height:  |  Size: 696 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 716 B

After

Width:  |  Height:  |  Size: 688 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 764 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 689 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 670 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 695 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 713 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 664 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 688 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 679 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 682 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 715 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 798 B

After

Width:  |  Height:  |  Size: 770 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 721 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 761 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 720 B

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 719 B

After

Width:  |  Height:  |  Size: 691 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 726 B

After

Width:  |  Height:  |  Size: 698 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 701 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 753 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 720 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 703 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 740 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 792 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 698 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 723 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 741 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 784 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 716 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 707 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 710 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 743 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 788 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 761 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 786 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 844 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 749 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 800 B

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save