#include "list.h" #include #include #include "../sprite.h" #include "raylib.h" #include "raymath.h" Node * ListCreateNode(Sprite *data){ Node *new = (Node *) malloc(sizeof(Node)); new->data = *data; new->next = 0; new->prev = 0; return new; } void ListPrintForward(List *list){ Node *current = list->head; printf("\n[\n"); while(current != 0){ printf("(%f | %f),\n", current->data.x, current->data.y); current = current->next; } printf("]\n"); } void ListInsertFront(List *list, Sprite *data){ Node *new = ListCreateNode(data); if(list->head == 0){ list->head = new; list->tail = new; } else if(list->head == list->tail){ list->head = new; list->head->next = list->tail; list->tail->prev = list->head; } else{ list->head->prev = new; new->next = list->head; list->head = new; } } void ListInsertBack(List *list, Sprite *data){ Node *new = ListCreateNode(data); if(list->head == 0){ list->head = new; list->tail = new; } else if(list->head == list->tail){ list->tail = new; list->head->next = list->tail; list->tail->prev = list->head; } else{ list->tail->next = new; new->prev = list->tail; list->tail = new; } } List * ListInit(){ List *newList = (List *) malloc(sizeof(List)); newList->head = 0; newList->tail = 0; return newList; } void ListDrawAllSprites(List *list, IsometricMap *map, Camera2D *camera){ Node *current = list->head; while(current != 0){ DrawSpriteToWorld(¤t->data, map, camera); current = current->next; } } void ListActAllSprites(Game *game){ // Sprites move towards their destination float movementSpeed = 150.0f * GetFrameTime(); Node *current = game->sprites->head; while (current != 0){ if(current->data.hasDestination == 1){ Vector2 movement = { current->data.destX - current->data.x, current->data.destY - current->data.y }; if(Vector2Length(movement) < movementSpeed){ current->data.hasDestination = 0; current->data.x = current->data.destX; current->data.y = current->data.destY; } else{ movement = Vector2Normalize(movement); movement = Vector2Scale(movement, movementSpeed); current->data.x += movement.x; current->data.y += movement.y; // Change sprite according to direction Vector2 nullvektor = {0,0}; float f = Vector2Angle(movement, nullvektor); printf("Angle: %f\n", f); f /= 3.14; f *= 3.5; f += 3.5; int index = (int) f; current->data.texture = game->worker + index; } } SpriteUpdateAnimation(¤t->data); current = current->next; } }