83 lines
1.5 KiB
C
83 lines
1.5 KiB
C
//
|
|
// Created by tony on 11/28/2024.
|
|
//
|
|
|
|
#include "entities.h"
|
|
|
|
Entity* entity_INIT(int id, char avatar, char type, COORD position) {
|
|
Entity* e = (Entity *)malloc(sizeof(Entity));
|
|
|
|
e->id = id;
|
|
e->avatar = avatar;
|
|
e->type = type;
|
|
e->position = position;
|
|
|
|
e->next = NULL;
|
|
return e;
|
|
}
|
|
|
|
void append(Entity **head, int id, char avatar, char type, COORD position)
|
|
{
|
|
Entity *e = entity_INIT(id, avatar, type, position);
|
|
if (*head == NULL) {
|
|
*head = e;
|
|
} else {
|
|
Entity* temp = *head;
|
|
while (temp->next != NULL) {
|
|
temp = temp->next;
|
|
}
|
|
temp->next = e;
|
|
}
|
|
}
|
|
|
|
void freeList(Entity **e)
|
|
{
|
|
Entity *current = *e;
|
|
Entity *next;
|
|
|
|
while (current != NULL)
|
|
{
|
|
free(current);
|
|
current = next;
|
|
}
|
|
|
|
*e = NULL;
|
|
}
|
|
void updateEntityPostition(struct Entity *pEntity, int direction)
|
|
{
|
|
switch (direction)
|
|
{
|
|
case (1):
|
|
pEntity->position.Y--;
|
|
break;
|
|
case (2):
|
|
pEntity->position.Y++;
|
|
break;
|
|
case (3):
|
|
pEntity->position.X--;
|
|
break;
|
|
case (4):
|
|
pEntity->position.X++;
|
|
break;
|
|
default:
|
|
0;
|
|
}
|
|
};
|
|
|
|
struct Entity **createEntity(int id, char avatar, char type, COORD position)
|
|
{
|
|
struct Entity *e = (Entity *)malloc(sizeof(Entity));
|
|
|
|
e->id = id;
|
|
e->avatar = avatar;
|
|
e->type = type;
|
|
e->position = position;
|
|
|
|
return (Entity **)e;
|
|
}
|
|
|
|
void freeEntities(struct Entity *pEntity)
|
|
{
|
|
free(pEntity);
|
|
}
|