#include "board_renderer.h"
+#include "tile_renderer.h"
 #include "point.h"
 #include "err.h"
 
 static WINDOW *win = NULL;
 static Point2i winPos;
 static Point2i winSize;
+static int layer = 0;
 
 void draw_board()
 {
        Point2i bsize = board_get_size(b);
        for(int y = 0; y < bsize.y; ++y){
                for(int x = 0; x < bsize.x; ++x){
-                       mvwaddch(win, 1+y, 1+x, '#');
+                       Tile *t = board_tile_at(b, point2i(x,y));
+                       mvwaddch(win, 1+y, 1+x, trndr_repr(t, layer));
                }
        }
 }
 void brndr_set_board(Board *board)
 {
        b = board;
+       trndr_set_board(board);
 }
 
 void brndr_cleanup()
        b = NULL;
        delwin(win);
 }
+
+void brndr_set_rendered_layer(int l)
+{
+       layer = l;
+}
 
+#include <stdlib.h>
+#include "err.h"
 #include "tile_renderer.h"
-#include "board.h"
 
 static Board *b = NULL;
 static const char repr[] = {'X', '.', '^', '\'', '~', '*', '|', '0'};
 const static char col_repr = '#';
-const static char air_repr = ' ';
+const static char air_repr = 'A';
 const static char unk_repr = '?';
 
 char trndr_repr(Tile *t, int dlayer)
 {
-       if(b == NULL || t == NULL)
+       if(b == NULL || t == NULL){
+               err_output("trndr_repr error, tile or board NULL");
                return unk_repr;
+       }
 
        int tlayer = tile_position(t).z;
-       int terrain;
+       int terrain = tile_terrain(t);
 
-       if(t < 0; || t > LAST){
+       if(terrain < 0 || terrain > LAST){
+               err_output("trndr_repr error, terrain < 0 or terrain > LAST");
                return unk_repr;
        } else {
-               if(tlayer < dlayer) { return col_repr; }
-               else if(tlayer > dlayer) { return air_repr; }
+               if(tlayer > dlayer) { return col_repr; }
+               else if(tlayer < dlayer) { return air_repr; }
                else return repr[tile_terrain(t)];
        }
 }
 
-void trendr_set_board(Board *board) { b = board; }
+void trndr_set_board(Board *board) { b = board; }
 
 #ifndef TILE_RENDERER
 #define TILE_RENDERER
 #include "tile.h"
+#include "board.h"
 
-char trndr_repr(enum Terrain t, int layer);
-void trenr_set_board(Board *board);
+char trndr_repr(Tile *t, int layer);
+void trndr_set_board(Board *board);
 #endif//TILE_RENDERER