@ -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
|
||||
|
Before Width: | Height: | Size: 732 B After Width: | Height: | Size: 704 B |
|
Before Width: | Height: | Size: 732 B After Width: | Height: | Size: 704 B |
|
Before Width: | Height: | Size: 842 B After Width: | Height: | Size: 814 B |
|
Before Width: | Height: | Size: 842 B After Width: | Height: | Size: 814 B |
|
Before Width: | Height: | Size: 842 B After Width: | Height: | Size: 814 B |
|
After Width: | Height: | Size: 820 B |
|
After Width: | Height: | Size: 820 B |
|
Before Width: | Height: | Size: 732 B After Width: | Height: | Size: 704 B |
|
After Width: | Height: | Size: 757 B |
|
After Width: | Height: | Size: 757 B |
|
After Width: | Height: | Size: 676 B |
|
After Width: | Height: | Size: 676 B |
|
After Width: | Height: | Size: 676 B |
|
After Width: | Height: | Size: 771 B |
|
After Width: | Height: | Size: 771 B |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 760 B |
|
After Width: | Height: | Size: 753 B |
|
Before Width: | Height: | Size: 799 B After Width: | Height: | Size: 771 B |
|
After Width: | Height: | Size: 775 B |
|
After Width: | Height: | Size: 728 B |
|
After Width: | Height: | Size: 771 B |
|
After Width: | Height: | Size: 817 B |
|
Before Width: | Height: | Size: 782 B After Width: | Height: | Size: 754 B |
|
After Width: | Height: | Size: 790 B |
|
Before Width: | Height: | Size: 782 B After Width: | Height: | Size: 754 B |
|
Before Width: | Height: | Size: 783 B After Width: | Height: | Size: 755 B |
|
After Width: | Height: | Size: 809 B |
|
After Width: | Height: | Size: 733 B |
|
After Width: | Height: | Size: 749 B |
|
After Width: | Height: | Size: 765 B |
|
After Width: | Height: | Size: 756 B |
|
Before Width: | Height: | Size: 766 B After Width: | Height: | Size: 738 B |
|
After Width: | Height: | Size: 767 B |
|
After Width: | Height: | Size: 758 B |
|
After Width: | Height: | Size: 816 B |
|
After Width: | Height: | Size: 772 B |
|
After Width: | Height: | Size: 736 B |
|
After Width: | Height: | Size: 700 B |
|
After Width: | Height: | Size: 777 B |
|
Before Width: | Height: | Size: 840 B After Width: | Height: | Size: 812 B |
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 692 B |
|
Before Width: | Height: | Size: 728 B After Width: | Height: | Size: 700 B |
|
Before Width: | Height: | Size: 724 B After Width: | Height: | Size: 696 B |
|
Before Width: | Height: | Size: 716 B After Width: | Height: | Size: 688 B |
|
After Width: | Height: | Size: 675 B |
|
After Width: | Height: | Size: 712 B |
|
After Width: | Height: | Size: 764 B |
|
After Width: | Height: | Size: 689 B |
|
After Width: | Height: | Size: 670 B |
|
After Width: | Height: | Size: 695 B |
|
After Width: | Height: | Size: 713 B |
|
After Width: | Height: | Size: 756 B |
|
After Width: | Height: | Size: 664 B |
|
After Width: | Height: | Size: 688 B |
|
After Width: | Height: | Size: 679 B |
|
After Width: | Height: | Size: 682 B |
|
After Width: | Height: | Size: 715 B |
|
Before Width: | Height: | Size: 798 B After Width: | Height: | Size: 770 B |
|
After Width: | Height: | Size: 721 B |
|
After Width: | Height: | Size: 761 B |
|
Before Width: | Height: | Size: 720 B After Width: | Height: | Size: 692 B |
|
Before Width: | Height: | Size: 719 B After Width: | Height: | Size: 691 B |
|
Before Width: | Height: | Size: 726 B After Width: | Height: | Size: 698 B |
|
After Width: | Height: | Size: 701 B |
|
After Width: | Height: | Size: 753 B |
|
After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 720 B |
|
Before Width: | Height: | Size: 703 B |
|
Before Width: | Height: | Size: 740 B |
|
Before Width: | Height: | Size: 792 B |
|
Before Width: | Height: | Size: 717 B |
|
Before Width: | Height: | Size: 698 B |
|
Before Width: | Height: | Size: 723 B |
|
Before Width: | Height: | Size: 741 B |
|
Before Width: | Height: | Size: 784 B |
|
Before Width: | Height: | Size: 692 B |
|
Before Width: | Height: | Size: 716 B |
|
Before Width: | Height: | Size: 707 B |
|
Before Width: | Height: | Size: 710 B |
|
Before Width: | Height: | Size: 743 B |
|
Before Width: | Height: | Size: 788 B |
|
Before Width: | Height: | Size: 781 B |
|
Before Width: | Height: | Size: 761 B |
|
Before Width: | Height: | Size: 786 B |
|
Before Width: | Height: | Size: 844 B |
|
Before Width: | Height: | Size: 749 B |
|
Before Width: | Height: | Size: 800 B |