TextureAtlas and some Loader Methods added

main
Jonathan Hager 3 years ago
parent 49848705f7
commit 8a4ac55c90
Signed by: JonathanHager
GPG Key ID: 34881E488569708C

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

@ -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
$(CC) -o spiel main.o sprite.o inputHandler.o isometricRenderer.o isometricMap.o tile.o list.o game.o textureatlas.o $(FLAGS)
main.o: main.c
$(CC) -c main.c $(FLAGS)
@ -28,5 +28,8 @@ 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)
clean:
rm *.o spiel

@ -0,0 +1,34 @@
#include "textureatlas.h"
#include "stdlib.h"
#include "raylib.h"
TextureAtlas * TextureAtlasInit(){
TextureAtlas *textures = (TextureAtlas *) malloc(sizeof(TextureAtlas));
LoadCursorTextures(textures->cursorTextures);
LoadWorkerTextures(textures->workerTextures);
return textures;
}
void LoadCursorTextures(Texture2D *cursorTextures){
*cursorTextures = LoadTexture("assets/cursor.gif");
*(cursorTextures + 1) = LoadTexture("assets/cursor_down.gif");
}
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");
}

@ -4,8 +4,13 @@
typedef struct TextureAtlas{
Texture2D cursorTextures[2];
Texture2D workerTextures[7];
Texture2D workerTextures[8][5];
//Texture2D[] mapTextures;
} TextureAtlas;
// Initialize the full TextureAtlas struct with all Textures used in the game
TextureAtlas * TextureAtlasInit();
void LoadCursorTextures(Texture2D *cursorTextures);
void LoadWorkerTextures(Texture2D *workerTextures);
#endif

@ -5,18 +5,16 @@
#include "List/list.h"
#include "Input/inputHandler.h"
#include "IsometricMap/isometricMap.h"
#include "Textures/textureatlas.h"
#include "stdio.h"
Game *GameInit()
{
Game *game = (Game *)malloc(sizeof(Game));
game->cursorTextures[0] = LoadTexture("assets/cursor.gif");
game->cursorTextures[1] = LoadTexture("assets/cursor_down.gif");
// game->cursorSprite = {&(cursorTextures[0]), 450, 225};
// game->cursorSprite = (Sprite *) malloc(sizeof(Sprite));
game->cursorSprite = SpriteCreate(game->cursorTextures, 450, 225);
game->textures = TextureAtlasInit();
game->cursorSprite = SpriteCreate(game->textures->cursorTextures, 450, 225);
Image worker1flip = LoadImage("assets/worker/worker-1.png");
ImageFlipHorizontal(&worker1flip);
@ -44,7 +42,7 @@ Game *GameInit()
game->inputHandler->cursorWorldTile.x = 0;
game->inputHandler->cursorWorldTile.y = 0;
game->inputHandler->selectedLayer = -1;
game->inputHandler->cursorTextures = game->cursorTextures;
game->inputHandler->cursorTextures = game->textures->cursorTextures;
game->inputHandler->cursorSprite = game->cursorSprite;
game->camera = (Camera2D *)malloc(sizeof(Camera2D));

@ -5,8 +5,8 @@
// So kann man die includes umgehen, also keine Circular dependencies mehr :)
typedef struct Game{
Texture2D cursorTextures[2];
Texture2D worker[8];
struct TextureAtlas *textures;
struct Sprite *cursorSprite;
struct List *sprites;
struct InputHandler *inputHandler;

Loading…
Cancel
Save