Point2i dimensions;
} Board_t;
+int flatten(Point2i coord, Point2i size)
+{
+ return coord.x + (size.x * coord.y);
+}
+
Board *board_init(Point2i size)
{
Board *ret = NULL;
Board_t *b = malloc(sizeof(Board_t));
- int sizet = size.x * size.y;
+ int itr;
b->dimensions.x = size.x;
b->dimensions.y = size.y;
- b->tiles = malloc(sizet * sizeof(Tile));
-
- for(int x = 0; x < size.x; ++x){
- for(int y = 0; y < size.y; ++y){
+ b->tiles = malloc(size.x * size.y * sizeof(Tile));
- b->tiles[y * size.x + x] =
- tile_init(point3i(x,y,1), PLAINS);
+ for(int y = 0; y < size.y; ++y){
+ for(int x = 0; x < size.x; ++x){
+ itr = flatten(point2i(x, y), size);
+ printf("%d\t", itr);
+ b->tiles[itr] = tile_init(point3i(x, y, itr), PLAIN);
}
+ printf("\n");
}
ret = (Board *) b;
enum Terrain board_terrain_at(Board* b, Point2i point);
int board_elevation_at(Board* b, Point2i point);
+Tile* board_tile_at(Board* b, Point2i point);
#endif//BOARD_H
enum Terrain terrain;
} Tile_t;
+static const char repr[] = {'X', '.', '^', '\'', '~', '#', '*', '|', '0'};
+
Tile *tile_init(Point3i pos, enum Terrain ter)
{
Tile_t *t = malloc(sizeof(Tile_t));
Tile_t *tt = (Tile_t *) t;
return tt->terrain;
}
+
+char tile_repr(enum Terrain t)
+{
+ if(t < 0 || t > LAST){
+ return '?';
+ } else {
+ return repr[t];
+ }
+}
#include "point.h"
enum Terrain{
- IMPASSABLE = -1,
- PLAINS,
+ IMPASSABLE = 0,
+ PLAIN,
MOUNTAIN,
S_WATER,
D_WATER,
WALL,
FLOOR,
- ROAD
+ ROAD,
+ LAST
};
+
typedef struct {} Tile;
Tile *tile_init(Point3i pos, enum Terrain ter);
void tile_cleanup(Tile *t);
Point3i tile_position(Tile *t);
enum Terrain tile_terrain(Tile *t);
+
+// TODO: move to nogl output c file
+char tile_repr(enum Terrain t);
#endif//TILE_H
Uint32 ctime = 0;
Point2i loc;
Point2i bsize = board_get_size(board, "storing size");
- char *terrain = malloc(bsize.x * bsize.y);
- char *elevation = malloc(bsize.x * bsize.y);
- char **sel = &terrain;
Uint32 cclock = SDL_GetTicks();
Uint32 pclock = 0;
- for(int y = 0; y < bsize.y; ++y){
- for(int x = 0; x < bsize.x; ++x){
- loc = point2i(x,y);
- //if(elevation[y * bsize.x + x] != 1){
- if(board_elevation_at(board, loc) != 1){
- printf("elevation error at (%d,%d)\n", loc.x, loc.y);
- elevation[y * bsize.x + x] = '?';
- } else {
- elevation[y * bsize.x + x] = board_elevation_at(board, loc) + '0';
- }
- if(board_terrain_at(board, loc) == IMPASSABLE){
- terrain[y * bsize.x + x] = 'X';
- } else {
- terrain[y * bsize.x + x] = '.';
- }
- }
- }
- printf("\n");
-
- // 'game' loop, only stays open for 2 seconds
- while(ctime < itime + 2000){
- // checking if the display should change
- if(cclock - pclock > 200){
- if(sel == &terrain){
- sel = &elevation;
- } else {
- sel = &terrain;
- }
- pclock = cclock;
-
- printf("elevation? %s", (sel == &elevation) ? "true\n" : "false\n");
-
- for(int y = 0; y < bsize.y; ++y){
- for(int x = 0; x < bsize.x; ++x){
- printf("%c", (*sel)[y * bsize.x + x]);
- }
- printf("\n");
- }
- }
-
+ // 'game' loop, only stays open for .5 seconds
+ while(ctime < itime + 500){
ctime = SDL_GetTicks();
- cclock = SDL_GetTicks();
}
- free(terrain);
- free(elevation);
SDL_Quit();
//endwin();