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.
83 lines
2.0 KiB
83 lines
2.0 KiB
#include "staticobjects.h"
|
|
#include <stdlib.h>
|
|
#include "../game.h"
|
|
#include "../Sprite/sprite.h"
|
|
|
|
StaticObject * StaticObjectInit(Game *game, int id, int x, int y){
|
|
int textureId = 0;
|
|
|
|
switch(id){
|
|
case SO_PINETREE:
|
|
textureId = TE_PINETREE;
|
|
break;
|
|
default:
|
|
printf("WARNING: STATICOBJECTINIT MIT FALSCHER ID AUFGERUFEN\n");
|
|
}
|
|
|
|
Sprite *newSprite = SpriteCreate(game->textures, textureId, x, y);
|
|
SpriteListInsert(game->sprites, newSprite);
|
|
|
|
StaticObject *new = malloc(sizeof(StaticObject));
|
|
|
|
new->sprite = newSprite;
|
|
new->id = id;
|
|
|
|
new->next = 0;
|
|
new->prev = 0;
|
|
|
|
return new;
|
|
}
|
|
|
|
StaticObjectList * StaticObjectListInit(){
|
|
StaticObjectList *new = malloc(sizeof(StaticObjectList));
|
|
new->head = 0;
|
|
new->tail = 0;
|
|
return new;
|
|
}
|
|
|
|
void StaticObjectListPrintForward(StaticObjectList *objects){
|
|
|
|
}
|
|
|
|
void StaticObjectListInsert(StaticObjectList *objects, StaticObject *data){
|
|
if(objects->head == 0){
|
|
objects->head = data;
|
|
objects->tail = data;
|
|
}
|
|
else{
|
|
objects->tail->next = data;
|
|
data->prev = objects->tail;
|
|
objects->tail = data;
|
|
}
|
|
}
|
|
|
|
void StaticObjectListRemove(Game *game, StaticObject *remove){
|
|
if(remove == 0){
|
|
printf("WARNING: TRIED TO REMOVE NULLPOINTER\n");
|
|
return;
|
|
}
|
|
else if(game->objects->head == remove && game->objects->tail == remove){
|
|
game->objects->head = 0;
|
|
game->objects->tail = 0;
|
|
}
|
|
else if(game->objects->head == remove){
|
|
remove->next->prev = 0;
|
|
game->objects->head = remove->next;
|
|
}
|
|
else if(game->objects->tail == remove){
|
|
remove->prev->next = 0;
|
|
game->objects->tail = remove->prev;
|
|
}
|
|
else{
|
|
remove->prev->next = remove->next;
|
|
remove->next->prev = remove->prev;
|
|
}
|
|
|
|
remove->next = 0;
|
|
remove->prev = 0;
|
|
|
|
SpriteListRemove(game->sprites, remove->sprite);
|
|
free(remove->sprite);
|
|
free(remove);
|
|
}
|