parent
c526c257cc
commit
2a9feb24e2
@ -0,0 +1,77 @@
|
|||||||
|
#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(StaticObjectList *objects, StaticObject *remove){
|
||||||
|
if(remove == 0){
|
||||||
|
printf("WARNING: TRIED TO REMOVE NULLPOINTER\n");
|
||||||
|
}
|
||||||
|
else if(objects->head == remove && objects->tail == remove){
|
||||||
|
objects->head = 0;
|
||||||
|
objects->tail = 0;
|
||||||
|
}
|
||||||
|
else if(objects->head == remove){
|
||||||
|
remove->next->prev = 0;
|
||||||
|
objects->head = remove->next;
|
||||||
|
}
|
||||||
|
else if(objects->tail == remove){
|
||||||
|
remove->prev->next = 0;
|
||||||
|
objects->tail = remove->prev;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
remove->prev->next = remove->next;
|
||||||
|
remove->next->prev = remove->prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
remove->next = 0;
|
||||||
|
remove->prev = 0;
|
||||||
|
}
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef STATICOBJECTS_H_
|
||||||
|
#define STATICOBJECTS_H_
|
||||||
|
#include "../Sprite/sprite.h"
|
||||||
|
#include "../game.h"
|
||||||
|
|
||||||
|
typedef struct StaticObject{
|
||||||
|
Sprite *sprite;
|
||||||
|
int id;
|
||||||
|
|
||||||
|
struct StaticObject *next;
|
||||||
|
struct StaticObject *prev;
|
||||||
|
} StaticObject;
|
||||||
|
|
||||||
|
typedef struct StaticObjectList {
|
||||||
|
StaticObject *head;
|
||||||
|
StaticObject *tail;
|
||||||
|
} StaticObjectList;
|
||||||
|
|
||||||
|
StaticObject * StaticObjectInit(Game *game, int id, int x, int y);
|
||||||
|
StaticObjectList * StaticObjectListInit();
|
||||||
|
|
||||||
|
void StaticObjectListPrintForward(StaticObjectList *objects);
|
||||||
|
void StaticObjectListInsert(StaticObjectList *objects, StaticObject *data);
|
||||||
|
void StaticObjectListRemove(StaticObjectList *objects, StaticObject *remove);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
After Width: | Height: | Size: 2.1 KiB |
Loading…
Reference in new issue