implemented drawing of a single z-level
authormatthew <matthew@owens.tech>
Tue, 7 Aug 2018 18:30:58 +0000 (18:30 +0000)
committermatthew <matthew@owens.tech>
Tue, 7 Aug 2018 18:30:58 +0000 (18:30 +0000)
common/tile.c
nogl/board_renderer.c
nogl/board_renderer.h
nogl/main.c
nogl/tile_renderer.c
nogl/tile_renderer.h

index 1e2a950..6f08a37 100644 (file)
@@ -52,12 +52,3 @@ enum Terrain tile_terrain(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];
-       }
-}
index 6debf3c..dedaec6 100644 (file)
@@ -1,4 +1,5 @@
 #include "board_renderer.h"
+#include "tile_renderer.h"
 #include "point.h"
 #include "err.h"
 
@@ -6,6 +7,7 @@ static Board *b = NULL;
 static WINDOW *win = NULL;
 static Point2i winPos;
 static Point2i winSize;
+static int layer = 0;
 
 void draw_board()
 {
@@ -22,7 +24,8 @@ 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));
                }
        }
 }
@@ -49,6 +52,7 @@ void brndr_render()
 void brndr_set_board(Board *board)
 {
        b = board;
+       trndr_set_board(board);
 }
 
 void brndr_cleanup()
@@ -58,3 +62,8 @@ void brndr_cleanup()
        b = NULL;
        delwin(win);
 }
+
+void brndr_set_rendered_layer(int l)
+{
+       layer = l;
+}
index 439e640..1ae0b53 100644 (file)
@@ -7,5 +7,6 @@ void brndr_init();
 void brndr_render();
 void brndr_cleanup();
 void brndr_set_board(Board *board);
+void brndr_set_rendered_layer(int l);
 
 #endif//BOARD_RENDERER_H
index da47fb0..0fb34d0 100644 (file)
@@ -52,11 +52,10 @@ int main()
                return -1;
        }
        brndr_set_board(board);
+       brndr_set_rendered_layer(5);    //TODO: implement way to change layer
 
        brndr_render();
        getchar();
-       err_enable_logging("test");
-       getchar();
        err_clear();
        brndr_render();
        getchar();
index 19fcdfe..17589aa 100644 (file)
@@ -1,27 +1,31 @@
+#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; }
index 3d685e8..862b719 100644 (file)
@@ -1,7 +1,8 @@
 #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