AST/arenaEngine.c

94 lines
1.9 KiB
C

#include "arenaEngine.h"
#include <stdlib.h>
#include <stdio.h>
#include "fileHandler.h"
int initResources() {
//resOpen();
return 0;
}
ARENA_H_TILE* createHTile(ARENA_H_TILE* prevHTile) {
ARENA_H_TILE* tile_h = NULL;
if (prevHTile == NULL) {
tile_h = calloc(1,sizeof(ARENA_H_TILE)); //Using calloc because of resetting all memory allocated to 0
tile_h->type_id = 0;
tile_h->isGround = 1;
tile_h->canBeMined = 0;
tile_h->nextRow = NULL;
tile_h->nextColumn = NULL;
return tile_h;
} else if (prevHTile != NULL) {
tile_h = calloc(1,sizeof(ARENA_H_TILE));
prevHTile->nextRow = tile_h;
tile_h->type_id = 0;
tile_h->isGround = 1;
tile_h->canBeMined = 0;
tile_h->nextRow = NULL;
tile_h->nextColumn = NULL;
}
return NULL;
}
ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) {
ARENA_W_TILE* tile_w = NULL;
if (prevHTile != NULL && prevWTile == NULL) {
tile_w = calloc(1,sizeof(ARENA_W_TILE));
prevHTile->nextColumn = tile_w;
tile_w->type_id = 0;
tile_w->isGround = 1;
tile_w->canBeMined = 0;
tile_w->nextColumn = NULL;
return tile_w;
} else if (prevHTile == NULL && prevWTile != NULL) {
tile_w = calloc(1,sizeof(ARENA_W_TILE));
prevWTile->nextColumn = tile_w;
tile_w->type_id = 0;
tile_w->isGround = 1;
tile_w->canBeMined = 0;
tile_w->nextColumn = NULL;
}
return NULL;
}
ARENA_H_TILE* genNewArena(int w, int h) {
ARENA_H_TILE* arenaOrigin = NULL;
ARENA_H_TILE* TmpCursor_h = NULL;
ARENA_W_TILE* TmpCursor_w = NULL;
int i,j;
for(i=0;i<h;i++){
if (i==0) {
arenaOrigin = createHTile(NULL);
TmpCursor_h = arenaOrigin;
} else {
createHTile(TmpCursor_h);
}
for(j=0;j<w;j++){
if (j==0) {
TmpCursor_w = createWTile(TmpCursor_h, NULL);
} else {
createWTile(NULL, TmpCursor_w);
}
if (j!=0) TmpCursor_w = TmpCursor_w->nextColumn;
}
if (i!=0) TmpCursor_h = TmpCursor_h->nextRow;
}
return arenaOrigin;
}
int deleteArena(ARENA_H_TILE* genNewArena) {
}