|
|
|
|
@ -6,6 +6,7 @@
|
|
|
|
|
#include "../MapObject/building.h"
|
|
|
|
|
#include "../definitions.h"
|
|
|
|
|
#include "../Textures/textureatlas.h"
|
|
|
|
|
#include "entityacts.h"
|
|
|
|
|
|
|
|
|
|
Entity * EntityInit(Sprite *sprite, int profession, TextureAtlas *atlas){
|
|
|
|
|
Entity *new = malloc(sizeof(Entity));
|
|
|
|
|
@ -21,6 +22,14 @@ Entity * EntityInit(Sprite *sprite, int profession, TextureAtlas *atlas){
|
|
|
|
|
new->task = TaskInit(profession);
|
|
|
|
|
new->profession = profession;
|
|
|
|
|
|
|
|
|
|
switch(profession){
|
|
|
|
|
case PR_BUILDER:
|
|
|
|
|
new->act = BuilderAct;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("WARNING: ENTITYINIT MIT FALSCHER ID AUFGERUFEN!\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Animation ***animations = 0;
|
|
|
|
|
|
|
|
|
|
if(profession == PR_BUILDER){
|
|
|
|
|
@ -42,71 +51,24 @@ EntityList * EntityListInit(){
|
|
|
|
|
return new;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EntityListPrintForward(EntityList *entities){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EntityListInsert(EntityList *entities, Entity *data){
|
|
|
|
|
if(entities->head == 0){
|
|
|
|
|
entities->head = data;
|
|
|
|
|
entities->tail = data;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
entities->tail->next = data;
|
|
|
|
|
data->prev = entities->tail;
|
|
|
|
|
entities->tail = data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void EntityListRemove(EntityList *entities, Entity *remove){
|
|
|
|
|
if(remove == 0){
|
|
|
|
|
printf("WARNING: TRIED TO REMOVE NULLPOINTER\n");
|
|
|
|
|
}
|
|
|
|
|
else if(entities->head == remove && entities->tail == remove){
|
|
|
|
|
entities->head = 0;
|
|
|
|
|
entities->tail = 0;
|
|
|
|
|
}
|
|
|
|
|
else if(entities->head == remove){
|
|
|
|
|
remove->next->prev = 0;
|
|
|
|
|
entities->head = remove->next;
|
|
|
|
|
}
|
|
|
|
|
else if(entities->tail == remove){
|
|
|
|
|
remove->prev->next = 0;
|
|
|
|
|
entities->tail = remove->prev;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
remove->prev->next = remove->next;
|
|
|
|
|
remove->next->prev = remove->prev;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
remove->next = 0;
|
|
|
|
|
remove->prev = 0;
|
|
|
|
|
}
|
|
|
|
|
void EntityListActAllEntities(Game *game){
|
|
|
|
|
|
|
|
|
|
EntityList *entities = game->entities;
|
|
|
|
|
//SpriteListPrintForward(game->sprites);
|
|
|
|
|
// Sprites move towards their destination
|
|
|
|
|
void EntityMoveToDestination(Entity *entity){
|
|
|
|
|
float movementSpeed = 150.0f * GetFrameTime();
|
|
|
|
|
Entity *current = entities->head;
|
|
|
|
|
|
|
|
|
|
int counter = 0;
|
|
|
|
|
while (current != 0){
|
|
|
|
|
counter ++;
|
|
|
|
|
if(current->hasDestination == 1){
|
|
|
|
|
if(entity->hasDestination == 1){
|
|
|
|
|
Vector2 movement = {
|
|
|
|
|
current->destX - current->sprite->x,
|
|
|
|
|
current->destY - current->sprite->y
|
|
|
|
|
entity->destX - entity->sprite->x,
|
|
|
|
|
entity->destY - entity->sprite->y
|
|
|
|
|
};
|
|
|
|
|
if(Vector2Length(movement) < movementSpeed){
|
|
|
|
|
current->hasDestination = 0;
|
|
|
|
|
current->sprite->x = current->destX;
|
|
|
|
|
current->sprite->y = current->destY;
|
|
|
|
|
entity->hasDestination = 0;
|
|
|
|
|
entity->sprite->x = entity->destX;
|
|
|
|
|
entity->sprite->y = entity->destY;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
movement = Vector2Normalize(movement);
|
|
|
|
|
movement = Vector2Scale(movement, movementSpeed);
|
|
|
|
|
current->sprite->x += movement.x;
|
|
|
|
|
current->sprite->y += movement.y;
|
|
|
|
|
entity->sprite->x += movement.x;
|
|
|
|
|
entity->sprite->y += movement.y;
|
|
|
|
|
|
|
|
|
|
// Change sprite according to direction
|
|
|
|
|
Vector2 nullvektor = {0,0};
|
|
|
|
|
@ -116,79 +78,85 @@ void EntityListActAllEntities(Game *game){
|
|
|
|
|
|
|
|
|
|
if(angle <= 22.5 && angle >= -22.5){
|
|
|
|
|
// E
|
|
|
|
|
AnimationChangeDirection(current->animationHandler, E);
|
|
|
|
|
AnimationChangeDirection(entity->animationHandler, E);
|
|
|
|
|
}
|
|
|
|
|
else if(angle > 0 && angle <= 67.5){
|
|
|
|
|
// NE
|
|
|
|
|
AnimationChangeDirection(current->animationHandler, NE);
|
|
|
|
|
AnimationChangeDirection(entity->animationHandler, NE);
|
|
|
|
|
}
|
|
|
|
|
else if(angle > 0 && angle <= 112.5){
|
|
|
|
|
// N
|
|
|
|
|
AnimationChangeDirection(current->animationHandler, N);
|
|
|
|
|
AnimationChangeDirection(entity->animationHandler, N);
|
|
|
|
|
}
|
|
|
|
|
else if(angle > 0 && angle <= 157.5){
|
|
|
|
|
// NW
|
|
|
|
|
AnimationChangeDirection(current->animationHandler, NW);
|
|
|
|
|
AnimationChangeDirection(entity->animationHandler, NW);
|
|
|
|
|
}
|
|
|
|
|
else if(angle < 0 && angle >= -67.5){
|
|
|
|
|
// SE
|
|
|
|
|
AnimationChangeDirection(current->animationHandler, SE);
|
|
|
|
|
AnimationChangeDirection(entity->animationHandler, SE);
|
|
|
|
|
}
|
|
|
|
|
else if(angle < 0 && angle >= -112.5){
|
|
|
|
|
// S
|
|
|
|
|
AnimationChangeDirection(current->animationHandler, S);
|
|
|
|
|
AnimationChangeDirection(entity->animationHandler, S);
|
|
|
|
|
}
|
|
|
|
|
else if(angle < 0 && angle >= -157.5){
|
|
|
|
|
// SW
|
|
|
|
|
AnimationChangeDirection(current->animationHandler, SW);
|
|
|
|
|
AnimationChangeDirection(entity->animationHandler, SW);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
// W
|
|
|
|
|
AnimationChangeDirection(current->animationHandler, W);
|
|
|
|
|
AnimationChangeDirection(entity->animationHandler, W);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EntityListPrintForward(EntityList *entities){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EntityListInsert(EntityList *entities, Entity *data){
|
|
|
|
|
if(entities->head == 0){
|
|
|
|
|
entities->head = data;
|
|
|
|
|
entities->tail = data;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
if(current->profession == PR_BUILDER){
|
|
|
|
|
if(current->task->target == 0){
|
|
|
|
|
// Prüft, ob eine Baustelle existiert
|
|
|
|
|
Building *currentBU = game->buildings->head;
|
|
|
|
|
while(currentBU != 0){
|
|
|
|
|
if(currentBU->isBaustelle){
|
|
|
|
|
current->hasDestination = 1;
|
|
|
|
|
current->destX = currentBU->sprite->x;
|
|
|
|
|
current->destY = currentBU->sprite->y;
|
|
|
|
|
|
|
|
|
|
current->task->target = currentBU;
|
|
|
|
|
current->task->progress = 0;
|
|
|
|
|
break;
|
|
|
|
|
entities->tail->next = data;
|
|
|
|
|
data->prev = entities->tail;
|
|
|
|
|
entities->tail = data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void EntityListRemove(EntityList *entities, Entity *remove){
|
|
|
|
|
if(remove == 0){
|
|
|
|
|
printf("WARNING: TRIED TO REMOVE NULLPOINTER\n");
|
|
|
|
|
}
|
|
|
|
|
currentBU = currentBU->next;
|
|
|
|
|
else if(entities->head == remove && entities->tail == remove){
|
|
|
|
|
entities->head = 0;
|
|
|
|
|
entities->tail = 0;
|
|
|
|
|
}
|
|
|
|
|
else if(entities->head == remove){
|
|
|
|
|
remove->next->prev = 0;
|
|
|
|
|
entities->head = remove->next;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
// Is beim target angekommen
|
|
|
|
|
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 if(entities->tail == remove){
|
|
|
|
|
remove->prev->next = 0;
|
|
|
|
|
entities->tail = remove->prev;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
current->task->progress += 0.2 * GetFrameTime();
|
|
|
|
|
printf("%f\n", current->task->progress);
|
|
|
|
|
}
|
|
|
|
|
remove->prev->next = remove->next;
|
|
|
|
|
remove->next->prev = remove->prev;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
remove->next = 0;
|
|
|
|
|
remove->prev = 0;
|
|
|
|
|
}
|
|
|
|
|
void EntityListActAllEntities(Game *game){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Entity *current = game->entities->head;
|
|
|
|
|
|
|
|
|
|
while (current != 0){
|
|
|
|
|
current->act(game, current);
|
|
|
|
|
|
|
|
|
|
AnimationUpdate(current->animationHandler);
|
|
|
|
|
|
|
|
|
|
|