static Point2i winPos;
static Point2i winSize;
static int layer = 0;
+static Point2i drawPos;
void draw_board()
{
err_output("cannot draw boar, window is null!");
return;
}
+ // Ensuring that the canvas is clear to prevent ghosting
+ for(int y = 1; y < winSize.y - 1; ++y){
+ mvwhline(win, y, 1, ' ', winSize.x - 2);
+ }
+ // Drawing the board itself
Point2i bsize = board_get_size(b);
for(int y = 0; y < bsize.y; ++y){
for(int x = 0; x < bsize.x; ++x){
Tile *t = board_tile_at(b, point2i(x,y));
- mvwaddch(win, 1+y, 1+x, trndr_repr(t, layer));
+ mvwaddch(win, drawPos.y+y, drawPos.x+x, trndr_repr(t, layer));
}
}
}
Point2i termsize;
winPos = point2i(0,0);
+ drawPos = point2i(1,1);
getmaxyx(stdscr, termsize.y, termsize.x);
winSize = termsize;
winSize.y -= 2;
{
layer = l;
}
+
+void brndr_move_draw_pos(Point2i p)
+{
+ drawPos.x += p.x;
+ drawPos.y += p.y;
+}
void brndr_cleanup();
void brndr_set_board(Board *board);
void brndr_set_rendered_layer(int l);
+void brndr_move_draw_pos(Point2i p);
#endif//BOARD_RENDERER_H
#include "stdio.h"
#include "err.h"
-static char keys[] = {'q', 'K', 'J', 'c'};
+static char keys[] = {'q','K','J','c','h','j','k','l'};
enum Action input_update()
{
LAYER_UP,
LAYER_DOWN,
ERR_CLEAR,
+ MAP_LEFT,
+ MAP_DOWN,
+ MAP_UP,
+ MAP_RIGHT,
ACTION_LAST
};
case ERR_CLEAR:
err_clear();
break;
+ case MAP_LEFT:
+ brndr_move_draw_pos(point2i(-1,0));
+ brndr_render();
+ break;
+ case MAP_RIGHT:
+ brndr_move_draw_pos(point2i(1,0));
+ brndr_render();
+ break;
+ case MAP_UP:
+ brndr_move_draw_pos(point2i(0,-1));
+ brndr_render();
+ break;
+ case MAP_DOWN:
+ brndr_move_draw_pos(point2i(0,1));
+ brndr_render();
+ break;
}
}
static Board *b = NULL;
static const char repr[] = {'X', '.', '^', '\'', '~', '*', '|', '0'};
const static char col_repr = '#';
-const static char air_repr = 'A';
+const static char air_repr = ' ';
const static char unk_repr = '?';
char trndr_repr(Tile *t, int dlayer)