Is zu viel für mich

main
Jonathan Hager 3 years ago
parent 92beda7778
commit bc383b3827
Signed by: JonathanHager
GPG Key ID: 34881E488569708C

@ -4,6 +4,7 @@
"isometricrenderer.h": "c", "isometricrenderer.h": "c",
"sprite.h": "c", "sprite.h": "c",
"map": "c", "map": "c",
"isometricmap.h": "c" "isometricmap.h": "c",
"animationhandler.h": "c"
} }
} }

@ -123,7 +123,7 @@ void mouseInput(Game *game){
// Add Sprite // Add Sprite
if(width + height <= 1){ 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 // Berechnung, welche Sprites ausgewählt wurden, scuffed

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

@ -1,8 +1,8 @@
CC = gcc CC = gcc
FLAGS = -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 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 textureatlas.o 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 $(FLAGS) $(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 main.o: main.c
$(CC) -c main.c $(FLAGS) $(CC) -c main.c $(FLAGS)
@ -31,5 +31,11 @@ game.o: game.c
textureatlas.o: Textures/textureatlas.c textureatlas.o: Textures/textureatlas.c
$(CC) -c Textures/textureatlas.c $(FLAGS) $(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: clean:
rm *.o spiel rm *.o spiel

@ -23,37 +23,58 @@ AnimationFrame * AnimationFrameCreate(Texture2D *texture){
void AnimationInsertFront(Animation *animation, Texture2D *texture){ void AnimationInsertFront(Animation *animation, Texture2D *texture){
AnimationFrame *new = AnimationFrameCreate(texture); AnimationFrame *new = AnimationFrameCreate(texture);
if(list->head == 0){ if(animation->head == 0){
list->head = new; animation->head = new;
list->tail = new; animation->tail = new;
animation->head->prev = animation->tail;
animation->tail->next = animation->head->prev;
} }
else if(list->head == list->tail){ else if(animation->head == animation->tail){
list->head = new; animation->head = new;
list->head->next = list->tail;
list->tail->prev = list->head; animation->head->next = animation->tail;
animation->head->prev = animation->tail;
animation->tail->prev = animation->head;
animation->tail->next = animation->head;
} }
else{ else{
list->head->prev = new; animation->head->prev = new;
new->next = list->head;
list->head = new; new->next = animation->head;
new->prev = animation->tail;
animation->tail->next = new;
animation->head = new;
} }
} }
void AnimationInsertBack(Animation *animation, Texture2D *texture){ void AnimationInsertBack(Animation *animation, Texture2D *texture){
AnimationFrame *new = AnimationFrameCreate(texture); AnimationFrame *new = AnimationFrameCreate(texture);
if(list->head == 0){ if(animation->head == 0){
list->head = new; animation->head = new;
list->tail = new; animation->tail = new;
animation->head->prev = animation->tail;
animation->tail->next = animation->head->prev;
} }
else if(list->head == list->tail){ else if(animation->head == animation->tail){
list->tail = new; animation->tail = new;
list->head->next = list->tail;
list->tail->prev = list->head; animation->head->next = animation->tail;
animation->head->prev = animation->tail;
animation->tail->prev = animation->head;
animation->tail->next = animation->head;
} }
else{ else{
list->tail->next = new; animation->tail->next = new;
new->prev = list->tail; new->prev = animation->tail;
list->tail = new; new->next = animation->head;
animation->head->prev = new;
animation->tail = new;
} }
} }

@ -2,8 +2,8 @@
#define ANIMATION_H_ #define ANIMATION_H_
#include "raylib.h" #include "raylib.h"
struct Animation; typedef struct Animation Animation;
struct AnimationFrame; typedef struct AnimationFrame AnimationFrame;
typedef struct Animation { typedef struct Animation {
AnimationFrame *head; AnimationFrame *head;

@ -0,0 +1,33 @@
#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->currentFrame = animations[0]->head;
printf("Hier geht noch\n");
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

@ -9,6 +9,7 @@ TextureAtlas * TextureAtlasInit(){
LoadCursorTextures(textures->cursorTextures); LoadCursorTextures(textures->cursorTextures);
LoadWorkerTextures(textures->workerTextures); LoadWorkerTextures(textures->workerTextures);
LoadWorkerAnimations(textures->workerAnimations, textures->workerTextures);
return textures; return textures;
} }
@ -16,6 +17,9 @@ TextureAtlas * TextureAtlasInit(){
void LoadCursorTextures(Texture2D *cursorTextures){ void LoadCursorTextures(Texture2D *cursorTextures){
*cursorTextures = LoadTexture("assets/cursor.gif"); *cursorTextures = LoadTexture("assets/cursor.gif");
*(cursorTextures + 1) = LoadTexture("assets/cursor_down.gif"); *(cursorTextures + 1) = LoadTexture("assets/cursor_down.gif");
Animation *new = AnimationInit();
AnimationInsertBack(new, cursorTextures);
} }
void LoadWorkerTextures(Texture2D *workerTextures){ void LoadWorkerTextures(Texture2D *workerTextures){
@ -53,35 +57,46 @@ void LoadWorkerTextures(Texture2D *workerTextures){
strcat(filename, number); strcat(filename, number);
strcat(filename, ending); strcat(filename, ending);
//*(workerTextures + i) = LoadTexture(filename);
printf("lol: %s ", filename); printf("lol: %s ", filename);
// Set correct values for next iteration // Set correct values for next iteration
int lol = i % 5; int lol = i % 8;
// TODO: walk und umackern läuft nicht bis 24 sondern nur 23 // TODO: walk und umackern läuft nicht bis 24 sondern nur 23
if(lol == 0){ if(lol == 0){
*(workerTextures + i) = LoadTexture(filename);
printf("\n"); printf("\n");
file++; file++;
} }
else if(lol == 2){ else if(lol == 2){
Image tmp = LoadImage(filename);
ImageFlipHorizontal(&tmp);
*(workerTextures + i) = LoadTextureFromImage(tmp);
printf("flipped\n"); printf("flipped\n");
file++; file++;
} }
else if(lol == 4){ else if(lol == 4){
Image tmp = LoadImage(filename);
ImageFlipHorizontal(&tmp);
*(workerTextures + i) = LoadTextureFromImage(tmp);
printf("flipped\n"); printf("flipped\n");
file++; file++;
} }
else if(lol == 6){ else if(lol == 6){
Image tmp = LoadImage(filename);
ImageFlipHorizontal(&tmp);
*(workerTextures + i) = LoadTextureFromImage(tmp);
printf("flipped\n"); printf("flipped\n");
file++; file++;
} }
else if(lol == 7){ else if(lol == 7){
*(workerTextures + i) = LoadTexture(filename);
printf("\n"); printf("\n");
file++; file++;
} }
else{ else{
*(workerTextures + i) = LoadTexture(filename);
printf("\n"); printf("\n");
} }
@ -98,3 +113,20 @@ void LoadWorkerTextures(Texture2D *workerTextures){
} }
} }
} }
void LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTextures){
int i;
int j;
int frame = 0;
for(i=0; i < 24; i++){
Animation *newAnimation = AnimationInit();
for(j = 0; j < 8; j++){
AnimationInsertBack(newAnimation, (workerTextures+frame));
frame++;
}
workerAnimations[i] = newAnimation;
}
}

@ -1,10 +1,17 @@
#ifndef TEXTUREATLAS_H_ #ifndef TEXTUREATLAS_H_
#define TEXTUREATLAS_H_ #define TEXTUREATLAS_H_
#include "raylib.h" #include "raylib.h"
#include "animation.h"
typedef struct TextureAtlas TextureAtlas;
typedef struct TextureAtlas{ typedef struct TextureAtlas{
Texture2D cursorTextures[2]; Texture2D cursorTextures[2];
Animation cursorAnimation;
Texture2D workerTextures[104]; Texture2D workerTextures[104];
Animation *workerAnimations[24];
//Texture2D[] mapTextures; //Texture2D[] mapTextures;
} TextureAtlas; } TextureAtlas;
@ -12,5 +19,6 @@ typedef struct TextureAtlas{
TextureAtlas * TextureAtlasInit(); TextureAtlas * TextureAtlasInit();
void LoadCursorTextures(Texture2D *cursorTextures); void LoadCursorTextures(Texture2D *cursorTextures);
void LoadWorkerTextures(Texture2D *workerTextures); void LoadWorkerTextures(Texture2D *workerTextures);
void LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTextures);
#endif #endif

Binary file not shown.

@ -1,14 +0,0 @@
#ifndef ANIMATIONHANDLER_H_
#define ANIMATIONHANDLER_H_
#include "raylib.h"
struct AnimationHandler;
typedef struct AnimationHandler{
Texture2D *textures;
} AnimationHandler;
#endif

Binary file not shown.

@ -14,8 +14,8 @@ Game *GameInit()
game->textures = TextureAtlasInit(); game->textures = TextureAtlasInit();
game->cursorSprite = SpriteCreate(game->textures->cursorTextures, 450, 225); game->cursorSprite = SpriteCreate(game->textures, 0, 450, 225);
/*
Image worker1flip = LoadImage("assets/worker/worker-1.png"); Image worker1flip = LoadImage("assets/worker/worker-1.png");
ImageFlipHorizontal(&worker1flip); ImageFlipHorizontal(&worker1flip);
Image worker2flip = LoadImage("assets/worker/worker-2.png"); Image worker2flip = LoadImage("assets/worker/worker-2.png");
@ -30,7 +30,7 @@ Game *GameInit()
game->worker[3] = LoadTexture("assets/worker/worker-3.png"); game->worker[3] = LoadTexture("assets/worker/worker-3.png");
game->worker[1] = LoadTextureFromImage(worker3flip); game->worker[1] = LoadTextureFromImage(worker3flip);
game->worker[2] = LoadTexture("assets/worker/worker-4.png"); game->worker[2] = LoadTexture("assets/worker/worker-4.png");
*/
game->inputHandler = (InputHandler *)malloc(sizeof(InputHandler)); game->inputHandler = (InputHandler *)malloc(sizeof(InputHandler));
game->inputHandler->pressed = 0; game->inputHandler->pressed = 0;
game->inputHandler->rectStart.x = 0; game->inputHandler->rectStart.x = 0;

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.

BIN
main.o

Binary file not shown.

BIN
spiel

Binary file not shown.

@ -3,8 +3,13 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "IsometricMap/isometricMap.h" #include "IsometricMap/isometricMap.h"
#include "Textures/textureIDs.h"
#include "Textures/animationHandler.h"
#include "Textures/animation.h"
#include "Textures/textureatlas.h"
void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, int y){ void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, int y){
/*
if(*spriteAmount < 100){ if(*spriteAmount < 100){
(sprites + *spriteAmount) -> texture = texture; (sprites + *spriteAmount) -> texture = texture;
(sprites + *spriteAmount) -> x = x; (sprites + *spriteAmount) -> x = x;
@ -18,6 +23,7 @@ void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, in
else{ else{
printf("Voll\n"); printf("Voll\n");
} }
*/
} }
void DrawSpriteToWorld(Sprite *sprite, IsometricMap *map, Camera2D *camera){ void DrawSpriteToWorld(Sprite *sprite, IsometricMap *map, Camera2D *camera){
@ -52,12 +58,34 @@ void DrawSpriteToScreen(Sprite *sprite){
} }
} }
Sprite * SpriteCreate(Texture2D *texture, int x, int y){ void SpriteUpdateAnimation(Sprite *sprite){
AnimationUpdate(sprite->animationHandler);
sprite->texture = sprite->animationHandler->currentFrame->texture;
}
Sprite * SpriteCreate(TextureAtlas *atlas, int textureID, int x, int y){
Sprite *newSprite = (Sprite *) malloc(sizeof(Sprite)); Sprite *newSprite = (Sprite *) malloc(sizeof(Sprite));
newSprite->texture = texture; //AnimationHandler create
newSprite->x = x - texture->width / 2; //Animation **animations = atlas->workerAnimations;
newSprite->y = y - texture->height / 2; Animation **animations = 0;
if(textureID == worker){
animations = atlas->workerAnimations;
}
else if(textureID == cursor){
// Nix
}
else{
printf("\n\n\n\n\n\n\n\nSpriteCreate mit falscher ID aufgerufen oder ID nicht bekannt!!!\n\n\n\n\n\n\n\n");
}
AnimationHandler *newHandler = AnimationHandlerInit(animations);
newSprite->animationHandler = newHandler;
newSprite->texture = newSprite->animationHandler->currentFrame->texture;
newSprite->x = x - newSprite->texture->width / 2;
newSprite->y = y - newSprite->texture->height / 2;
newSprite->destX = x; newSprite->destX = x;
newSprite->destY = y; newSprite->destY = y;
newSprite->hasDestination = 0; newSprite->hasDestination = 0;

@ -2,8 +2,11 @@
#define SPRITE_H_ #define SPRITE_H_
#include "raylib.h" #include "raylib.h"
#include "IsometricMap/isometricMap.h" #include "IsometricMap/isometricMap.h"
#include "Textures/animationHandler.h"
#include "Textures/textureatlas.h"
typedef struct Sprite { typedef struct Sprite {
AnimationHandler *animationHandler;
Texture2D *texture; Texture2D *texture;
float x; float x;
float y; float y;
@ -17,7 +20,8 @@ void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, in
void DrawSpriteToWorld(Sprite *sprite, IsometricMap *map, Camera2D *camera); void DrawSpriteToWorld(Sprite *sprite, IsometricMap *map, Camera2D *camera);
void DrawSpriteToScreen(Sprite *sprite); void DrawSpriteToScreen(Sprite *sprite);
void SpriteUpdateAnimation(Sprite *sprite);
Sprite * SpriteCreate(Texture2D *texture, int x, int y); Sprite * SpriteCreate(TextureAtlas *atlas, int textureID, int x, int y);
#endif #endif

Binary file not shown.

Binary file not shown.

BIN
tile.o

Binary file not shown.
Loading…
Cancel
Save