You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.5 KiB

#include "entityacts.h"
#include "../Textures/animationHandler.h"
#include "../MapObject/building.h"
#include "../MapObject/staticobjects.h"
void BuilderAct(Game *game, Entity *entity){
Building *target = (Building *) entity->task->target;
// Hat noch keine Baustelle oder die Baustelle wurde fertiggestellt
if(entity->task->target == 0 || !target->isBaustelle){
AnimationChangeType(entity->animationHandler, AN_ENTITY_IDLE);
if(entity->hasDestination == 1){
entity->hasDestination = 0;
}
// Prüft, ob eine Baustelle existiert
Building *current = game->buildings->head;
while(current != 0){
if(current->isBaustelle){
entity->hasDestination = 1;
entity->destX = current->sprite->x;
entity->destY = current->sprite->y;
entity->task->target = current;
entity->task->progress = 0;
break;
}
current = current->next;
}
}
else if(entity->hasDestination == 1){
EntityMoveToDestination(entity);
}
else{
// Is beim target angekommen
if(entity->task->progress == 0){
// Angekommen, noch nicht mit arbeiten begonnen
AnimationChangeType(entity->animationHandler, AN_ENTITY_ARBEITEN);
entity->task->progress = 1;
}
else if(target->progress >= 1.0){
// Fertig mit arbeiten, Animation zu Idle zurück
AnimationChangeType(entity->animationHandler, AN_ENTITY_IDLE);
BuildingFinishConstruction(game, (Building *) entity->task->target);
entity->task->target = 0;
entity->task->progress = 0;
}
else{
target->progress += 0.2 * GetFrameTime();
}
}
}
void LumberjackAct(Game *game, Entity *entity){
StaticObject *target = (StaticObject *) entity->task->target;
// Hat noch keinen Baum
if(entity->task->target == 0){
AnimationChangeType(entity->animationHandler, AN_ENTITY_IDLE);
if(entity->hasDestination == 1){
entity->hasDestination = 0;
}
// Prüft, ob einen Baum existiert
StaticObject *current = game->objects->head;
while(current != 0){
if(current->id == SO_PINETREE){
entity->hasDestination = 1;
entity->destX = current->sprite->x;
entity->destY = current->sprite->y;
entity->task->target = current;
entity->task->progress = 0;
break;
}
current = current->next;
}
}
else if(entity->hasDestination == 1){
EntityMoveToDestination(entity);
}
else{
printf("%f\n", entity->task->progress);
// Is beim target angekommen
if(entity->task->progress == 0){
// Angekommen, noch nicht mit arbeiten begonnen
AnimationChangeType(entity->animationHandler, AN_ENTITY_ARBEITEN);
entity->task->progress = 0.01;
}
else if(entity->task->progress >= 1.0){
// Fertig mit arbeiten, Animation zu Idle zurück
AnimationChangeType(entity->animationHandler, AN_ENTITY_IDLE);
printf("Fertig\n");
StaticObjectListRemove(game, entity->task->target);
entity->task->target = 0;
entity->task->progress = 0;
}
else{
entity->task->progress += 0.2 * GetFrameTime();
}
}
}