implement stairs

This commit is contained in:
Jacob Janzen 2024-02-12 13:11:18 -06:00
parent f534c8d2c4
commit 7309765a00

64
main.c
View file

@ -102,6 +102,27 @@ void display_map(
wrefresh(win);
}
void display_instructions(WINDOW *win)
{
mvwprintw(win, 1, 2, "h - move left");
mvwprintw(win, 2, 2, "j - move down");
mvwprintw(win, 3, 2, "k - move up");
mvwprintw(win, 4, 2, "l - move right");
mvwprintw(win, 5, 2, "> - move down staircase");
mvwprintw(win, 6, 2, "< - exit via staircase");
wrefresh(win);
}
void display_message(WINDOW *win, char *msg)
{
for (int i = 1; i < MESSAGE_PANEL_WIDTH - 1; ++i) {
mvwaddch(win, 1, i, ' ');
}
mvwprintw(win, 1, 1, msg);
wrefresh(win);
}
int main(void)
{
initialize();
@ -125,18 +146,7 @@ int main(void)
(COLS - MAIN_PANEL_WIDTH - INSTRUCTION_PANEL_WIDTH) / 2
);
mvwprintw(inst, 1, 2, "h - move left");
mvwprintw(inst, 2, 2, "j - move down");
mvwprintw(inst, 3, 2, "k - move up");
mvwprintw(inst, 4, 2, "l - move right");
wrefresh(inst);
mvwprintw(msgs, 1, 1, "TODO: put messages here");
wrefresh(msgs);
wattron(main_win, COLOR_PAIR(1));
wrefresh(main_win);
// create the map
enum tile_type *map;
struct point *open_tiles;
int num_open_tiles;
@ -144,6 +154,7 @@ int main(void)
struct point down;
create_cave(&map, &open_tiles, &num_open_tiles, &up, &down);
// create the camera and player at the up stairs
struct entity *entities = malloc(sizeof(struct entity) * MAX_ENTITIES);
entities[0].disp_ch = "";
entities[0].name = "camera";
@ -155,10 +166,14 @@ int main(void)
entities[1].ypos = up.y;
int num_entities = 2;
// start displaying things
display_map(main_win, map, entities, num_entities);
display_instructions(inst);
display_message(msgs, "TODO: put a message here");
int ch;
while ((ch = getch()) != KEY_F(1)) {
int ch;
bool done = false;
while (!done && (ch = getch()) != KEY_F(1)) {
switch (ch) {
case 'k' :
if (entities[1].ypos > 0) {
@ -192,10 +207,31 @@ int main(void)
}
}
break;
case '>' :
if (map[entities[1].ypos * WIDTH + entities[1].xpos] ==
DOWN_STAIR) {
free(map);
free(open_tiles);
create_cave(&map, &open_tiles, &num_open_tiles, &up, &down);
entities[0].xpos = up.x - MAIN_PANEL_WIDTH / 2 + 1;
entities[0].ypos = up.y - MAIN_PANEL_HEIGHT / 2 + 1;
entities[1].xpos = up.x;
entities[1].ypos = up.y;
}
break;
case '<' :
if (map[entities[1].ypos * WIDTH + entities[1].xpos] == UP_STAIR) {
done = true;
}
break;
}
display_map(main_win, map, entities, num_entities);
}
free(map);
free(open_tiles);
free(entities);
endwin();
return 0;