Will net beschreiben, geht aber

main
Jonathan Hager 3 years ago
parent efa37825db
commit be7665d5c5
Signed by: JonathanHager
GPG Key ID: 34881E488569708C

@ -3,7 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "../Sprite/sprite.h"
#include "../MapObject/mapobject.h"
#include "../MapObject/building.h"
#include "../definitions.h"
#include "../Textures/textureatlas.h"
@ -18,12 +18,12 @@ Entity * EntityInit(Sprite *sprite, int profession, TextureAtlas *atlas){
new->selected = 0;
new->next = 0;
new->prev = 0;
new->task = TaskInit();
new->task = TaskInit(profession);
new->profession = profession;
Animation ***animations = 0;
if(profession == TE_WORKER){
if(profession == PR_BUILDER){
animations = atlas->animations[AN_WORKER];
}
else{
@ -150,40 +150,43 @@ 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){
Building *currentBU = game->buildings->head;
while(currentBU != 0){
if(currentBU->isBaustelle){
current->hasDestination = 1;
current->destX = currentMO->sprite->x;
current->destY = currentMO->sprite->y;
current->task->target = currentMO;
current->destX = currentBU->sprite->x;
current->destY = currentBU->sprite->y;
current->task->target = currentBU;
current->task->progress = 0;
break;
}
currentMO = currentMO->next;
currentBU = currentBU->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);
*/
//}
if(current->task->progress == 0){
// Angekommen, noch nicht mit arbeiten begonnen
AnimationChangeType(current->animationHandler, AN_ENTITY_ARBEITEN);
current->task->progress += 0.01;
}
else if(current->task->progress >= 1.0){
// Fertig mit arbeiten, Animation zu Idle zurück
AnimationChangeType(current->animationHandler, AN_ENTITY_IDLE);
BuildingFinishConstruction(game, (Building *) current->task->target);
current->task->target = 0;
}
else{
current->task->progress += 0.2 * GetFrameTime();
printf("%f\n", current->task->progress);
}
}
//}
}
}

@ -1,8 +1,22 @@
#include <stdlib.h>
#include "task.h"
#include "../definitions.h"
Task * TaskInit(){
Task * TaskInit(int workerid){
Task *new = malloc(sizeof(Task));
new->target = 0;
new->progress = 0;
int repeat = 0;
switch(workerid){
case PR_BUILDER:
repeat = 0;
break;
default:
repeat = 0;
}
new->repeat = repeat;
return new;
}
}

@ -1,12 +1,12 @@
#ifndef TASK_H_
#define TASK_H_
typedef struct Task Task;
typedef struct Task{
void *target;
float progress;
int repeat;
} Task;
Task * TaskInit();
Task * TaskInit(int workerid);
#endif
#endif

@ -3,7 +3,6 @@
#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>
@ -71,16 +70,6 @@ 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, TE_BAUSTELLE, 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;
@ -138,7 +127,7 @@ void mouseInput(Game *game){
else if(inputHandler->cursorWorldPos.y > maxHeight){ printf("OutOfBoundsDestination Spawn\n");}
else {
Sprite *newSprite = SpriteCreate(game->textures, TE_WORKER, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y);
Entity *entity = EntityInit(newSprite, TE_WORKER, game->textures);
Entity *entity = EntityInit(newSprite, PR_BUILDER, game->textures);
EntityListInsert(game->entities, entity);
SpriteListInsert(game->sprites, newSprite);
//ListPrintForward(sprites);

@ -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 selectable.o task.o
OBJS = main.o sprite.o inputHandler.o isometricMap.o game.o textureatlas.o animation.o animationHandler.o button.o uiContainer.o debug.o building.o entity.o selectable.o task.o
spiel: $(OBJS)
$(CC) -o spiel $(OBJS) $(FLAGS)
@ -41,8 +41,8 @@ debug.o: Ui/debug.c
entity.o: Entity/entity.c
$(CC) -c Entity/entity.c $(FLAGS)
mapobject.o: MapObject/mapobject.c
$(CC) -c MapObject/mapobject.c $(FLAGS)
building.o: MapObject/building.c
$(CC) -c MapObject/building.c $(FLAGS)
selectable.o: Ui/selectable.c
$(CC) -c Ui/selectable.c $(FLAGS)

@ -0,0 +1,86 @@
#include "building.h"
#include <stdlib.h>
#include "../game.h"
Building * BuildingInit(Game *game, int id, int x, int y){
Sprite *newSprite = SpriteCreate(game->textures, TE_BAUSTELLE, x, y);
SpriteListInsert(game->sprites, newSprite);
Building *new = malloc(sizeof(Building));
new->sprite = newSprite;
new->id = id;
new->isBaustelle = 1;
new->next = 0;
new->prev = 0;
return new;
}
BuildingList * BuildingListInit(){
BuildingList *new = malloc(sizeof(BuildingList));
new->head = 0;
new->tail = 0;
return new;
}
void BuildingFinishConstruction(Game *game, Building *building){
building->isBaustelle = 0;
int textureId = 0;
switch(building->id){
case BU_HOUSE:
textureId = TE_BUILDING;
break;
default:
printf("WARNING: BUILDINGFINDISHEDCONSTRADJFALKDF AUFGERUFEN MIT UNBEKANNTER ID111!!\n");
}
building->sprite->texture = game->textures->textures[textureId];
// Zur Sicherheit. Sollte eigentlich nix ändern, weil texture hmmpf früher bescheid wisse
SpriteListSpriteChanged(game->sprites, building->sprite);
}
void BuildingListPrintForward(BuildingList *buildings){
}
void BuildingListInsert(BuildingList *buildings, Building *data){
if(buildings->head == 0){
buildings->head = data;
buildings->tail = data;
}
else{
buildings->tail->next = data;
data->prev = buildings->tail;
buildings->tail = data;
}
}
void BuildingListRemove(BuildingList *buildings, Building *remove){
if(remove == 0){
printf("WARNING: TRIED TO REMOVE NULLPOINTER\n");
}
else if(buildings->head == remove && buildings->tail == remove){
buildings->head = 0;
buildings->tail = 0;
}
else if(buildings->head == remove){
remove->next->prev = 0;
buildings->head = remove->next;
}
else if(buildings->tail == remove){
remove->prev->next = 0;
buildings->tail = remove->prev;
}
else{
remove->prev->next = remove->next;
remove->next->prev = remove->prev;
}
remove->next = 0;
remove->prev = 0;
}

@ -0,0 +1,28 @@
#ifndef BUILDING_H_
#define BUILDING_H_
#include "../Sprite/sprite.h"
#include "../game.h"
typedef struct Building{
Sprite *sprite;
int id;
int isBaustelle;
struct Building *next;
struct Building *prev;
} Building;
typedef struct BuildingList {
Building *head;
Building *tail;
} BuildingList;
Building * BuildingInit(Game *game, int id, int x, int y);
BuildingList * BuildingListInit();
void BuildingFinishConstruction(Game *game, Building *building);
void BuildingListPrintForward(BuildingList *buildings);
void BuildingListInsert(BuildingList *buildings, Building *data);
void BuildingListRemove(BuildingList *buildings, Building *remove);
#endif

@ -1,60 +0,0 @@
#include "mapobject.h"
#include <stdlib.h>
MapObject * MapObjectInit(Sprite *sprite, int id){
MapObject *new = malloc(sizeof(MapObject));
new->sprite = sprite;
new->id = id;
new->next = 0;
new->prev = 0;
return new;
}
MapObjectList * MapObjectListInit(){
MapObjectList *new = malloc(sizeof(MapObjectList));
new->head = 0;
new->tail = 0;
return new;
}
void MapObjectListPrintForward(MapObjectList *mapObjects){
}
void MapObjectListInsert(MapObjectList *mapObjects, MapObject *data){
if(mapObjects->head == 0){
mapObjects->head = data;
mapObjects->tail = data;
}
else{
mapObjects->tail->next = data;
data->prev = mapObjects->tail;
mapObjects->tail = data;
}
}
void MapObjectListRemove(MapObjectList *mapObjects, MapObject *remove){
if(remove == 0){
printf("WARNING: TRIED TO REMOVE NULLPOINTER\n");
}
else if(mapObjects->head == remove && mapObjects->tail == remove){
mapObjects->head = 0;
mapObjects->tail = 0;
}
else if(mapObjects->head == remove){
remove->next->prev = 0;
mapObjects->head = remove->next;
}
else if(mapObjects->tail == remove){
remove->prev->next = 0;
mapObjects->tail = remove->prev;
}
else{
remove->prev->next = remove->next;
remove->next->prev = remove->prev;
}
remove->next = 0;
remove->prev = 0;
}

@ -1,28 +0,0 @@
#ifndef MAPOBJECT_H_
#define MAPOBJECT_H_
#include "../Sprite/sprite.h"
typedef struct MapObject MapObject;
typedef struct MapObjectList MapObjectList;
typedef struct MapObject{
Sprite *sprite;
int id;
MapObject *next;
MapObject *prev;
} MapObject;
typedef struct MapObjectList{
MapObject *head;
MapObject *tail;
} MapObjectList;
MapObject * MapObjectInit(Sprite *sprite, int id);
MapObjectList * MapObjectListInit();
void MapObjectListPrintForward(MapObjectList *mapObjects);
void MapObjectListInsert(MapObjectList *mapObjects, MapObject *data);
void MapObjectListRemove(MapObjectList *mapObjects, MapObject *remove);
#endif

@ -48,6 +48,12 @@ void AnimationChangeAnimation(AnimationHandler *animationHandler, int animationT
}
}
void AnimationChangeType(AnimationHandler *animationHandler, int animationType){
if(animationHandler->currentType != animationType){
animationHandler->currentType = animationType;
AnimationReset(animationHandler);
}
}
void AnimationChangeDirection(AnimationHandler *animationHandler, int direction){
if(animationHandler->currentDirection != direction){

@ -20,6 +20,7 @@ AnimationHandler * AnimationHandlerInit(Animation ***animations, Texture2D **spr
void AnimationUpdate(AnimationHandler *animationHandler);
void AnimationReset(AnimationHandler *animationHandler);
void AnimationChangeAnimation(AnimationHandler *animationHandler, int animationType, int direction);
void AnimationChangeType(AnimationHandler *animationHandler, int animationType);
void AnimationChangeDirection(AnimationHandler *animationHandler, int direction);
#endif

@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include "../definitions.h"
#include "../MapObject/mapobject.h"
#include "../MapObject/building.h"
#include "../Sprite/sprite.h"
#include "../Input/inputHandler.h"
@ -44,10 +44,8 @@ void SelectableExecuteSelectable(Selectable *selectable, Game * game){
// Oder das selectable wird abgewählt indem seine ID auf default zurückgesetzt wird
// Sonst kann das hier jeden Frame passieren. ID wird nicht automatisch zurückgesetzt
if(IsMouseButtonDown(MOUSE_BUTTON_LEFT)){
Sprite *new = SpriteCreate(game->textures, TE_BAUSTELLE, game->inputHandler->cursorWorldPos.x, game->inputHandler->cursorWorldPos.y);
MapObject *newObject = MapObjectInit(new, MO_BAUSTELLE);
SpriteListInsert(game->sprites, new);
MapObjectListInsert(game->mapObjects, newObject);
Building *newObject = BuildingInit(game, BU_HOUSE, game->inputHandler->cursorWorldPos.x, game->inputHandler->cursorWorldPos.y);
BuildingListInsert(game->buildings, newObject);
selectable->state = SELECTABLE_STATE_DEFAULT;
}

@ -31,9 +31,11 @@
#define AN_ENTITY_ARBEITEN 1
#define AN_ENTITY_DIE 2
// Definitions for mapobjects
#define MO_BAUSTELLE 0
#define MO_BUILDING 1
// Definitions for buildings
#define BU_HOUSE 0
// Defintions for professions
#define PR_BUILDER 0
// Definitions for Screen / View / Ui Stuff

@ -7,7 +7,7 @@
#include "Textures/textureatlas.h"
#include "stdio.h"
#include "Entity/entity.h"
#include "MapObject/mapobject.h"
#include "MapObject/building.h"
#include "Ui/uiContainer.h"
// returns pointer to new Game instance
@ -42,7 +42,7 @@ Game *GameInit()
game->sprites = SpriteListInit();
game->entities = EntityListInit();
game->mapObjects = MapObjectListInit();
game->buildings = BuildingListInit();
game->map = IsometricMapInit();
//das du es weißt man kann wenn du nicht auf hört was machen und dann bist du leise es gibt was das nett sich rufmord

@ -13,7 +13,7 @@ typedef struct Game{
struct InputHandler *inputHandler;
struct Camera2D *camera;
struct IsometricMap *map;
struct MapObjectList *mapObjects;
struct BuildingList *buildings;
struct EntityList *entities;
struct UiContainer *UiContainers[SCREEN_AMOUNT];
int screen;

Loading…
Cancel
Save