Skip to content

Instantly share code, notes, and snippets.

@t-mart
Created November 6, 2011 15:43
Show Gist options
  • Save t-mart/1343047 to your computer and use it in GitHub Desktop.
Save t-mart/1343047 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include "grid.h"
#include "gbalib.h"
#include "game.h"
tile* tile_init(void){
tile* t = (tile*) malloc(sizeof(tile));
t->ge = CLEAR;
t->gep = NULL;
return t;
}
void tile_destroy(tile* t){
free(t);
}
grid* grid_init(){
grid* g = (grid*) malloc(sizeof(grid));
int rows = SCREEN_HEIGHT / TILE_SIZE;
int cols = SCREEN_WIDTH / TILE_SIZE;
tile *tiles[cols][rows];
int i, j;
for (i = 0; i < cols; i++){
for (j = 0; j < rows; j++){
tiles[i][j] = tile_init();
}
}
g->tiles = tiles;
return g;
}
#ifndef GRID_H
#define GRID_H
typedef enum _game_element {
CLEAR,
SNAKE,
WALL,
FOOD
} game_element;
typedef struct _tile {
game_element ge;
void* gep;
} tile;
typedef struct _grid {
tile ***tiles; //is this right? for each column, for each rol, theres a pointer to a tile
} grid;
grid* grid_init();
void tile_destroy(tile* t);
tile* tile_init(void);
#endif /* end of include guard: GRID_H */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment