Funktioniert halb

main
Jonathan Hager 3 years ago
parent 4d99781ea1
commit 9397431d41
Signed by: JonathanHager
GPG Key ID: 34881E488569708C

@ -3,8 +3,12 @@
#include <stdio.h>
#include <stdlib.h>
#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);

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

@ -0,0 +1,7 @@
#ifndef PROFESSIONS_H_
#define PROFESSIONS_H_
#define PR_NOWORK 0
#define PR_BUILDER 1
#endif

@ -0,0 +1,8 @@
#include <stdlib.h>
#include "task.h"
Task * TaskInit(){
Task *new = malloc(sizeof(Task));
new->target = 0;
return new;
}

@ -0,0 +1,12 @@
#ifndef TASK_H_
#define TASK_H_
typedef struct Task Task;
typedef struct Task{
void *target;
} Task;
Task * TaskInit();
#endif

@ -3,11 +3,15 @@
#include "../Sprite/sprite.h"
#include "../IsometricMap/isometricMap.h"
#include "../Entity/entity.h"
#include "../MapObject/mapobject.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#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);

@ -165,5 +165,4 @@ void IsometricMapDraw(Game *game){
}
}
SpriteListDrawAllSprites(game->sprites, game->map, game->camera);
}

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

@ -1,10 +1,11 @@
#include "mapobject.h"
#include <stdlib.h>
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;

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

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

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

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

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

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

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

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

Loading…
Cancel
Save