Being able to explote all_green example map.

Movement implemented.
This commit is contained in:
sergiotarxz 2021-12-08 17:55:51 +01:00
parent 1b01682f7c
commit 89809bd0fb

View File

@ -18,29 +18,70 @@ l3tde_game_render_game_get_start_node (size_t current_pos,
static void
l3tde_game_render_game_get_start_nodes (L3TDEGamePtr game,
int max_x, int max_y, size_t *x, size_t *y);
void
l3tde_game_loop (L3TDEGamePtr game);
void
l3tde_game_init (void) {
L3TDEGamePtr game = l3tde_game_create_default_game ();
initscr ();
start_color ();
raw ();;
curs_set (0);
raw ();
keypad (stdscr, TRUE);
noecho ();
l3tde_game_render_game (game);;
getch ();
refresh ();
l3tde_game_loop (game);
endwin ();
}
void
l3tde_game_loop (L3TDEGamePtr game) {
int input;
while (1) {
clear ();
l3tde_game_render_game (game);
input = getch ();
bool end_game = 0;
switch (input) {
case KEY_UP:
if (game->y_pos) {
(game->y_pos)--;
}
break;
case KEY_DOWN:
if (game->current_map
->nodes_y_len -1
> game->y_pos) {
(game->y_pos)++;
}
break;
case KEY_RIGHT:
if (game->current_map
->nodes_x_len -1
> game->x_pos) {
(game->x_pos)++;
}
break;
case KEY_LEFT:
if (game->x_pos) {
(game->x_pos)--;
}
break;
case 'q':
end_game = 1;
}
if (end_game) break;
}
}
void
l3tde_game_render_game (L3TDEGamePtr game) {
size_t start_node_x, start_node_y;
size_t max_node_x, max_node_y;
size_t nodes_x_len, nodes_y_len;
int max_x, max_y;
int current_pos_map_x, current_pos_map_y;
getmaxyx(stdscr, max_y, max_x);
@ -51,10 +92,11 @@ l3tde_game_render_game (L3TDEGamePtr game) {
l3tde_game_render_game_get_start_nodes (game,
max_x, max_y, &start_node_x, &start_node_y);
fprintf (stderr, "%ld %ld\n", start_node_x, start_node_y);
max_node_x = start_node_x + max_x;
max_node_y = start_node_y + max_y;
if (max_node_x > nodes_x_len) {
max_node_x = nodes_x_len;
}
@ -75,6 +117,11 @@ l3tde_game_render_game (L3TDEGamePtr game) {
attroff (COLOR_PAIR (1));
}
}
current_pos_map_x = game->x_pos - start_node_x;
current_pos_map_y = game->y_pos - start_node_y;
attron (A_BOLD);
mvprintw (current_pos_map_y, current_pos_map_x, "@");
attroff (A_BOLD);
}
static void
@ -107,8 +154,8 @@ l3tde_game_render_game_get_start_node (size_t current_pos,
if (current_pos < center) {
draw_center = center;
} else if (nodes_len - current_pos >= center ) {
draw_center = nodes_len - center;
} else if (nodes_len - current_pos < center) {
draw_center = nodes_len - center - 1;
} else {
draw_center = current_pos;
}
@ -139,7 +186,7 @@ l3tde_game_create_default_map (void) {
const char *header_name = "all_green";
const char *header_description = "This is dummy map where all is green.";
size_t nodes_len = 80;
size_t nodes_len = 200;
size_t terrain_name_len = strlen (terrain_name);
size_t header_name_len = strlen (header_name);
size_t header_descrition_len = strlen (header_description);