diff --git a/Entity/entity.c b/Entity/entity.c index 62db4e5..bc49c37 100644 --- a/Entity/entity.c +++ b/Entity/entity.c @@ -3,8 +3,12 @@ #include #include #include "../Sprite/sprite.h" +#include "../MapObject/mapobject.h" +#include "../MapObject/mapobjectIDs.h" +#include "../Entity/professions.h" +#include "../Textures/textureIDs.h" -Entity * EntityInit(Sprite *sprite){ +Entity * EntityInit(Sprite *sprite, int profession){ Entity *new = malloc(sizeof(Entity)); new->sprite = sprite; @@ -14,6 +18,8 @@ Entity * EntityInit(Sprite *sprite){ new->selected = 0; new->next = 0; new->prev = 0; + new->task = TaskInit(); + new->profession = profession; return new; } @@ -101,6 +107,40 @@ void EntityListActAllEntities(Game *game){ } } + else{ + if(current->profession == PR_BUILDER){ + if(current->task->target == 0){ + // Prüft, ob eine Baustelle existiert + MapObject *currentMO = game->mapObjects->head; + while(currentMO != 0){ + if(currentMO->id == MO_Baustelle){ + current->hasDestination = 1; + current->destX = currentMO->sprite->x; + current->destY = currentMO->sprite->y; + current->task->target = currentMO; + break; + } + currentMO = currentMO->next; + } + } + else{ + // Is beim target angekommen + MapObject *obj = current->task->target; + printf("Hier\n"); + Sprite *new = SpriteCreate(game->textures, 2, obj->sprite->x, obj->sprite->y); + SpriteListRemove(game->sprites, obj->sprite); + SpriteListInsert(game->sprites, new); + free(obj->sprite); + MapObject *newObject = MapObjectInit(new, MO_Building); + MapObjectListRemove(game->mapObjects, obj); + MapObjectListInsert(game->mapObjects, newObject); + current->task->target = 0; + free(obj); + } + + } + + } SpriteUpdate(current->sprite); diff --git a/Entity/entity.h b/Entity/entity.h index 672bfc4..4390565 100644 --- a/Entity/entity.h +++ b/Entity/entity.h @@ -2,6 +2,7 @@ #define ENTITY_H_ #include "../Sprite/sprite.h" #include "../game.h" +#include "task.h" typedef struct Entity Entity; @@ -11,6 +12,8 @@ typedef struct Entity{ float destY; int hasDestination; int selected; + Task *task; + int profession; Entity *next; Entity *prev; @@ -21,7 +24,7 @@ typedef struct EntityList{ Entity *tail; } EntityList; -Entity * EntityInit(Sprite *sprite); +Entity * EntityInit(Sprite *sprite, int profession); EntityList * EntityListInit(); void EntityListPrintForward(EntityList *entities); diff --git a/Entity/professions.h b/Entity/professions.h new file mode 100644 index 0000000..a46a3e6 --- /dev/null +++ b/Entity/professions.h @@ -0,0 +1,7 @@ +#ifndef PROFESSIONS_H_ +#define PROFESSIONS_H_ + +#define PR_NOWORK 0 +#define PR_BUILDER 1 + +#endif \ No newline at end of file diff --git a/Entity/task.c b/Entity/task.c new file mode 100644 index 0000000..b2f3db4 --- /dev/null +++ b/Entity/task.c @@ -0,0 +1,8 @@ +#include +#include "task.h" + +Task * TaskInit(){ + Task *new = malloc(sizeof(Task)); + new->target = 0; + return new; +} \ No newline at end of file diff --git a/Entity/task.h b/Entity/task.h new file mode 100644 index 0000000..3c99985 --- /dev/null +++ b/Entity/task.h @@ -0,0 +1,12 @@ +#ifndef TASK_H_ +#define TASK_H_ + +typedef struct Task Task; + +typedef struct Task{ + void *target; +} Task; + +Task * TaskInit(); + +#endif \ No newline at end of file diff --git a/Input/inputHandler.c b/Input/inputHandler.c index 2beba3c..5ac3098 100644 --- a/Input/inputHandler.c +++ b/Input/inputHandler.c @@ -3,11 +3,15 @@ #include "../Sprite/sprite.h" #include "../IsometricMap/isometricMap.h" #include "../Entity/entity.h" +#include "../MapObject/mapobject.h" #include #include #include #include "../IsometricMap/tile.h" #include "../game.h" +#include "../MapObject/mapobjectIDs.h" +#include "../Entity/professions.h" +//#include "../Textures/textureIDs.h" void DrawRect(Vector2 rectStart, Vector2 *mousePosition){ float width = GetMousePosition().x - rectStart.x; @@ -69,6 +73,14 @@ void mouseInput(Game *game){ IsometricMapChangeTextureIdOfTile(map, (int) inputHandler->cursorWorldTile.x, (int) inputHandler->cursorWorldTile.y, 0); } + if(IsKeyPressed(KEY_G)){ + // Baustelle adden + Sprite *new = SpriteCreate(game->textures, 3, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y); + MapObject *newObject = MapObjectInit(new, MO_Baustelle); + SpriteListInsert(game->sprites, new); + MapObjectListInsert(game->mapObjects, newObject); + } + // hardcoded layer amount float tileWidthHalf = map->tileTextures[0].width / 2; float tileHeightQuarter = map->tileTextures[0].height / 4; @@ -126,7 +138,7 @@ void mouseInput(Game *game){ else if(inputHandler->cursorWorldPos.y > maxHeight){ printf("OutOfBoundsDestination Spawn\n");} else { Sprite *newSprite = SpriteCreate(game->textures, 1, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y); - Entity *entity = EntityInit(newSprite); + Entity *entity = EntityInit(newSprite, PR_BUILDER); EntityListInsert(game->entities, entity); SpriteListInsert(game->sprites, newSprite); //ListPrintForward(sprites); diff --git a/IsometricMap/isometricMap.c b/IsometricMap/isometricMap.c index cc92c2f..aa151fb 100644 --- a/IsometricMap/isometricMap.c +++ b/IsometricMap/isometricMap.c @@ -165,5 +165,4 @@ void IsometricMapDraw(Game *game){ } } - SpriteListDrawAllSprites(game->sprites, game->map, game->camera); } diff --git a/Makefile b/Makefile index 2cd745e..289daa3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC = gcc FLAGS = -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -OBJS = main.o sprite.o inputHandler.o isometricMap.o game.o textureatlas.o animation.o animationHandler.o button.o uiContainer.o debug.o mapobject.o entity.o +OBJS = main.o sprite.o inputHandler.o isometricMap.o game.o textureatlas.o animation.o animationHandler.o button.o uiContainer.o debug.o mapobject.o entity.o task.o spiel: $(OBJS) $(CC) -o spiel $(OBJS) $(FLAGS) @@ -44,5 +44,8 @@ entity.o: Entity/entity.c mapobject.o: MapObject/mapobject.c $(CC) -c MapObject/mapobject.c $(FLAGS) +task.o: Entity/task.c + $(CC) -c Entity/task.c $(FLAGS) + clean: rm *.o spiel diff --git a/MapObject/mapobject.c b/MapObject/mapobject.c index b30e3d6..7a1b124 100644 --- a/MapObject/mapobject.c +++ b/MapObject/mapobject.c @@ -1,10 +1,11 @@ #include "mapobject.h" #include -MapObject * MapObjectInit(Sprite *sprite){ +MapObject * MapObjectInit(Sprite *sprite, int id){ MapObject *new = malloc(sizeof(MapObject)); new->sprite = sprite; + new->id = id; new->next = 0; new->prev = 0; diff --git a/MapObject/mapobject.h b/MapObject/mapobject.h index 44a570c..68fd140 100644 --- a/MapObject/mapobject.h +++ b/MapObject/mapobject.h @@ -7,6 +7,7 @@ typedef struct MapObjectList MapObjectList; typedef struct MapObject{ Sprite *sprite; + int id; MapObject *next; MapObject *prev; @@ -17,7 +18,7 @@ typedef struct MapObjectList{ MapObject *tail; } MapObjectList; -MapObject * MapObjectInit(Sprite *sprite); +MapObject * MapObjectInit(Sprite *sprite, int id); MapObjectList * MapObjectListInit(); void MapObjectListPrintForward(MapObjectList *mapObjects); diff --git a/MapObject/mapobjectIDs.h b/MapObject/mapobjectIDs.h new file mode 100644 index 0000000..8bc91d7 --- /dev/null +++ b/MapObject/mapobjectIDs.h @@ -0,0 +1,16 @@ +#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 MO_Baustelle 0 +#define MO_Building 1 + +#endif \ No newline at end of file diff --git a/Sprite/sprite.c b/Sprite/sprite.c index 865d55a..e6466ef 100644 --- a/Sprite/sprite.c +++ b/Sprite/sprite.c @@ -86,12 +86,18 @@ Sprite * SpriteCreate(TextureAtlas *atlas, int textureID, int x, int y){ //AnimationHandler create Animation **animations = 0; - if(textureID == worker){ + if(textureID == TE_worker){ animations = atlas->workerAnimations; } - else if(textureID == cursor){ + else if(textureID == TE_cursor){ animations = atlas->cursorAnimation; } + else if(textureID == TE_building){ + animations = atlas->buildingAnimation; + } + else if(textureID == TE_baustelle){ + animations = atlas->baustelleAnimation; + } else{ printf("\n\n\n\n\n\n\n\nSpriteCreate mit falscher ID (%d) aufgerufen oder ID nicht bekannt!!!\n\n\n\n\n\n\n\n", textureID); } diff --git a/Textures/animationHandler.c b/Textures/animationHandler.c index 968dd4a..11e88cd 100644 --- a/Textures/animationHandler.c +++ b/Textures/animationHandler.c @@ -11,6 +11,8 @@ AnimationHandler * AnimationHandlerInit(Animation **animations){ new->currentFrame = new->animations[new->currentAnimation]->head; new->forward = 1; new->deltaElapsed = 0; + + return new; } void AnimationUpdate(AnimationHandler *animationHandler){ @@ -39,4 +41,4 @@ void AnimationChangeAnimation(AnimationHandler *animationHandler, int newAnimati AnimationReset(animationHandler); } -} \ No newline at end of file +} diff --git a/Textures/textureIDs.h b/Textures/textureIDs.h index 1cb932c..5a60e99 100644 --- a/Textures/textureIDs.h +++ b/Textures/textureIDs.h @@ -10,7 +10,9 @@ #define W 4 #define NW 2 -#define cursor 0 -#define worker 1 +#define TE_cursor 0 +#define TE_worker 1 +#define TE_building 2 +#define TE_baustelle 3 -#endif \ No newline at end of file +#endif diff --git a/Textures/textureatlas.c b/Textures/textureatlas.c index 353cdcf..d35e157 100644 --- a/Textures/textureatlas.c +++ b/Textures/textureatlas.c @@ -6,10 +6,37 @@ TextureAtlas * TextureAtlasInit(){ TextureAtlas *textures = malloc(sizeof(TextureAtlas)); + LoadCursorTextures(textures->cursorTextures, textures->cursorAnimation); LoadWorkerTextures(textures->workerTextures); LoadWorkerAnimations(textures->workerAnimations, textures->workerTextures); + + //Das soll nicht hier hin, bin aber zu faul :| + textures->building = LoadTexture("assets/building.png"); + Animation *buildingAnimation = AnimationInit(); + AnimationInsertBack(buildingAnimation, &textures->building); + textures->buildingAnimation[0] = buildingAnimation; + textures->buildingAnimation[1] = buildingAnimation; + textures->buildingAnimation[2] = buildingAnimation; + textures->buildingAnimation[3] = buildingAnimation; + textures->buildingAnimation[4] = buildingAnimation; + textures->buildingAnimation[5] = buildingAnimation; + textures->buildingAnimation[6] = buildingAnimation; + textures->buildingAnimation[7] = buildingAnimation; + + //Das soll nicht hier hin, bin aber zu faul :| + textures->baustelle = LoadTexture("assets/construction.png"); + Animation *baustelleAnimation = AnimationInit(); + AnimationInsertBack(baustelleAnimation, &textures->baustelle); + textures->baustelleAnimation[0] = baustelleAnimation; + textures->baustelleAnimation[1] = baustelleAnimation; + textures->baustelleAnimation[2] = baustelleAnimation; + textures->baustelleAnimation[3] = baustelleAnimation; + textures->baustelleAnimation[4] = baustelleAnimation; + textures->baustelleAnimation[5] = baustelleAnimation; + textures->baustelleAnimation[6] = baustelleAnimation; + textures->baustelleAnimation[7] = baustelleAnimation; return textures; } diff --git a/Textures/textureatlas.h b/Textures/textureatlas.h index 1199d77..abecee1 100644 --- a/Textures/textureatlas.h +++ b/Textures/textureatlas.h @@ -12,6 +12,12 @@ typedef struct TextureAtlas{ Texture2D workerTextures[104]; Animation *workerAnimations[24]; + Texture2D building; + Animation *buildingAnimation[8]; + + Texture2D baustelle; + Animation *baustelleAnimation[8]; + //Texture2D[] mapTextures; } TextureAtlas; @@ -21,4 +27,4 @@ void LoadCursorTextures(Texture2D *cursorTextures, Animation **cursorAnimation); void LoadWorkerTextures(Texture2D *workerTextures); void LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTextures); -#endif \ No newline at end of file +#endif diff --git a/main.c b/main.c index 5388ce6..d7a3bdf 100644 --- a/main.c +++ b/main.c @@ -52,12 +52,14 @@ int main(){ return 0; case SCREEN_GAME: - // Updating Sprites + // Updating Entities EntityListActAllEntities(game); // Drawing IsometricMap BeginMode2D(*(game->camera)); // Sorgt dafür, dass die Kameraposition beachtet wird IsometricMapDraw(game); + + SpriteListDrawAllSprites(game->sprites, game->map, game->camera); EndMode2D(); // User Input Handling