diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 76 |
1 files changed, 35 insertions, 41 deletions
@@ -161,7 +161,8 @@ int main(int argc, char **argv) { draw_map(map, cell_costs, width, height, start_pos, end_pos, NULL, path, visited, NULL); int c = getch(); - /* + /* WARNING: these might change. If something doesn't work, see config.h + * * Keybindings: * [k] \ * [h] [l] } Move the view @@ -175,9 +176,6 @@ int main(int argc, char **argv) { * [y] [o] } Resize the maze * [u] + / * - * [z] - Move the view to the top left corner - * [x] - Move the view to the bottom right corner - * * [g] followed by: * [s] - Move the view to the start * [e] - Move the view to the end @@ -230,35 +228,30 @@ int main(int argc, char **argv) { } break; - case 'h': map_offset_x += 2; break; - case 'l': map_offset_x -= 2; break; - case 'j': map_offset_y -= 1; break; - case 'k': map_offset_y += 1; break; + case KEYBINDING_LEFT: map_offset_x += 2; break; + case KEYBINDING_RIGHT: map_offset_x -= 2; break; + case KEYBINDING_DOWN: map_offset_y -= 1; break; + case KEYBINDING_UP: map_offset_y += 1; break; - case 'H': clear(); map_offset_x += 20; break; - case 'L': clear(); map_offset_x -= 20; break; - case 'J': clear(); map_offset_y -= 10; break; - case 'K': clear(); map_offset_y += 10; break; + case KEYBINDING_FLEFT: map_offset_x += 20; break; + case KEYBINDING_FRIGHT: map_offset_x -= 20; break; + case KEYBINDING_FDOWN: map_offset_y -= 10; break; + case KEYBINDING_FUP: map_offset_y += 10; break; - case 'z': clear(); map_offset_x = 2; map_offset_y = 1; break; /* Move to top left corner */ - case 'x': clear(); map_offset_x = - width * 2 + COLS - 2; map_offset_y = - height + LINES - 2; break; /* Move to bottom right corner */ - - case 'g': + case KEYBINDING_GOTO: switch (getch()) { - case 's': - clear(); + case KEYBINDING_GOTO_ST: map_offset_x = -start_pos.x * 2 + COLS/2; map_offset_y = -start_pos.y + LINES/2; break; - case 'e': - clear(); + case KEYBINDING_GOTO_GL: map_offset_x = -end_pos.x * 2 + COLS/2; map_offset_y = -end_pos.y + LINES/2; break; } break; - case 'a': + case KEYBINDING_REPATHFIND: /* Only animate if there was already a path, otherwise just calculate one */ if (path == NULL) anim = 0; else anim = 1; @@ -266,15 +259,16 @@ int main(int argc, char **argv) { path_free(path, height); path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, anim); clear_message(); + anim = 0; break; - case 'A': + case KEYBINDING_ANIM: path_free(path, height); path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, 1); clear_message(); break; - case 'd': + case KEYBINDING_ALGO: if (path_func == astar_path) { set_message("Dijkstra's"); path_func = &dijkstra_path; } else { set_message("A*"); path_func = &astar_path; }; path_free(path, height); @@ -282,7 +276,7 @@ int main(int argc, char **argv) { /* TODO: print time */ break; - case '4': + case KEYBINDING_DIRS: if (dirs == 4) { set_message("8 directions"); dirs = 8; } else { set_message("4 directions"); dirs = 4; }; @@ -290,7 +284,7 @@ int main(int argc, char **argv) { path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, anim); break; - case 'f': + case KEYBINDING_WRAPAROUND: wraparound_enabled = !wraparound_enabled; if (wraparound_enabled) set_message("Enabled wraparound, only works on Dijkstra's") @@ -303,20 +297,20 @@ int main(int argc, char **argv) { } break; - case 'r': + case KEYBINDING_REVERSE_PATH: path_reverse(&path, width, height, &start_pos, &end_pos); break; - case 'y': - case 'o': - case 'u': - case 'i': + case KEYBINDING_MAZE_HOR_SHRINK: + case KEYBINDING_MAZE_HOR_GROW: + case KEYBINDING_MAZE_VER_SHRINK: + case KEYBINDING_MAZE_VER_GROW: if(is_maze) { switch (c) { - case 'y': if (mwidth > 5) mwidth -= 1; break; - case 'o': mwidth += 1; break; - case 'u': mheight += 1; break; - case 'i': if (mheight > 2) mheight -= 1; break; + case KEYBINDING_MAZE_HOR_SHRINK: if (mwidth > 5) mwidth -= 1; break; + case KEYBINDING_MAZE_HOR_GROW: mwidth += 1; break; + case KEYBINDING_MAZE_VER_GROW: mheight += 1; break; + case KEYBINDING_MAZE_VER_SHRINK: if (mheight > 2) mheight -= 1; break; } map_free(map, height); visited_free(visited, height); @@ -335,7 +329,7 @@ int main(int argc, char **argv) { } break; - case 's': + case KEYBINDING_BMP: curs_set(2); /* Show the cursor */ echo(); /* Echo characters */ @@ -351,7 +345,7 @@ int main(int argc, char **argv) { getch(); break; - case 'w': /* FIXME: Keys don't make any sense anymore. 'o' should be open. And do them through defines for god's sake */ + case KEYBINDING_OPEN_MAP: is_maze = 0; curs_set(2); /* Show the cursor */ echo(); /* Echo characters */ @@ -378,7 +372,7 @@ int main(int argc, char **argv) { break; - case 'n': + case KEYBINDING_NEW_MAZE: if (is_maze) { map_free(map, height); path_free(path, height); @@ -388,11 +382,11 @@ int main(int argc, char **argv) { path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, anim); } break; - case 't': + case KEYBINDING_PATH_TIME: set_message("%f seconds", path_time); print_message(height); break; - case 'c': /* Load a cost file */ + case KEYBINDING_LOAD_COSTS: /* Load a cost file */ curs_set(2); /* Show the cursor */ echo(); /* Echo characters */ @@ -409,7 +403,7 @@ int main(int argc, char **argv) { break; - case 'e': + case KEYBINDING_EDITOR: is_maze = 0; visited_free(visited, height); path_free(path, height); @@ -426,7 +420,7 @@ int main(int argc, char **argv) { case KEY_RESIZE: clear(); break; - case 'q': cost_free(cell_costs, height); visited_free(visited, height); map_free(map, height); path_free(path, height); endwin(); return 0; + case KEYBINDING_QUIT: cost_free(cell_costs, height); visited_free(visited, height); map_free(map, height); path_free(path, height); endwin(); return 0; } } |
