X-Git-Url: https://plomlompom.com/repos/feed.xml?a=blobdiff_plain;f=roguelike.c;h=0279043ecd1d427a39b6e3c3a13729ddc2fe4eda;hb=231090b75bf54933f8016781c9c3f83e6ba3d669;hp=0de96ee87ede95cd6018b7873e3a9aa1b77e2529;hpb=c1a11c82ca5dd7aa7b48e79b72fcb0112565e1bc;p=plomrogue diff --git a/roguelike.c b/roguelike.c index 0de96ee..0279043 100644 --- a/roguelike.c +++ b/roguelike.c @@ -54,8 +54,8 @@ void write_uint32_bigendian(uint32_t x, FILE * file) { fputc(c, file); fputc(d, file); } -void load_seed(struct World * world) { -// Load seed integer from seed file. +void load_game(struct World * world) { +// Load game data from game file. FILE * file = fopen("savefile", "r"); world->seed = read_uint32_bigendian(file); world->turn = read_uint32_bigendian(file); @@ -65,8 +65,8 @@ void load_seed(struct World * world) { world->monster->x = read_uint16_bigendian(file); fclose(file); } -void save_seed(struct World * world) { -// Save seed integer to seed file. +void save_game(struct World * world) { +// Save game data to game file. FILE * file = fopen("savefile", "w"); write_uint32_bigendian(world->seed, file); write_uint32_bigendian(world->turn, file); @@ -134,6 +134,7 @@ void map_scroll (struct Map * map, char dir) { void next_turn (struct World * world) { // Increment turn and move enemy. world->turn++; + rrand(1, world->seed * world->turn); char d = rrand(0, 0) % 5; uint16_t ty = world->monster->y; uint16_t tx = world->monster->x; @@ -219,24 +220,24 @@ void player_wait (struct World * world) { int main (int argc, char *argv[]) { struct World world; + init_keybindings(&world); + + world.log = calloc(1, sizeof(char)); + update_log (&world, " "); struct Player player; world.player = &player; struct Monster monster; world.monster = &monster; if (0 == access("savefile", F_OK)) - load_seed(&world); + load_game(&world); else { player.y = 8; player.x = 8; monster.y = 55; monster.x = 55; world.seed = time(NULL); - world.turn = 0; } + world.turn = 1; } rrand(1, world.seed); - - init_keybindings(&world); - world.log = calloc(1, sizeof(char)); - update_log (&world, "Start!"); struct Map map = init_map(); world.map = ↦ @@ -250,9 +251,21 @@ int main (int argc, char *argv[]) { struct Win win_map = init_window(&win_meta, "Map", &world, draw_map_win); struct Win win_info = init_window(&win_meta, "Info", &world, draw_info_win); struct Win win_log = init_window(&win_meta, "Log", &world, draw_log_win); + win_keys.width = 29; + win_map.width = win_meta.width - win_keys.width - win_log.width - 2; + win_info.height = 1; + win_log.height = win_meta.height - 3; + toggle_window(&win_meta, &win_keys); + toggle_window(&win_meta, &win_map); + toggle_window(&win_meta, &win_info); + toggle_window(&win_meta, &win_log); int key; + uint32_t last_turn = 0; while (1) { + if (last_turn != world.turn) { + save_game(&world); + last_turn = world.turn; } draw_all_windows (&win_meta); key = getch(); if (key == get_action_key(world.keybindings, "quit")) @@ -293,8 +306,6 @@ int main (int argc, char *argv[]) { keyswin_move_selection (&world, 'd'); else if (key == get_action_key(world.keybindings, "keys mod")) keyswin_mod_key (&world, &win_meta); - else if (key == get_action_key(world.keybindings, "save game")) - save_seed(&world); else if (key == get_action_key(world.keybindings, "map up")) map_scroll (&map, 'n'); else if (key == get_action_key(world.keybindings, "map down"))