From: Christian Heller Date: Wed, 10 Jul 2013 02:16:43 +0000 (+0200) Subject: Added hitpoints and death for player. X-Git-Tag: tce~1165 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/add_task?a=commitdiff_plain;h=1191fe6ec56b6fd2155c0c71de15740187739fd9;p=plomrogue Added hitpoints and death for player. --- diff --git a/README b/README index 9f80b04..40c7a0a 100644 --- a/README +++ b/README @@ -3,13 +3,12 @@ plomrogue plomlompom tries to build his own roguelike. Currently, it doesn't do much interesting, apart from managing some ncurses windows in a bizarre -fashion. You can move around a player and meet a random number enemies; -they will occasionally hit you on contact, but without consequence to -you: The player has no hitpoints so far. Enemies have 5 hitpoints at -start and disappear if their hitpoints reach 0. The map gets generated -randomly, too. There is only one save file (named "savefile"), and it -gets overwritten each new turn. To start over with a new world, delete -it. +fashion. You can move around a player and meet a random number enemies. +They move randomly and will only accidentally hit you. You have 5 +hitpoints to lose before death, and so has each of them. The map gets +generated randomly, too. There is only one save file (named "savefile"), +and it gets overwritten each new turn. To start over with a new world, +delete it. Install/run ----------- diff --git a/src/draw_wins.c b/src/draw_wins.c index 197b7c3..d44d257 100644 --- a/src/draw_wins.c +++ b/src/draw_wins.c @@ -104,9 +104,8 @@ extern void draw_map_win (struct Win * win) { extern void draw_info_win (struct Win * win) { // Draw info window by appending win->data integer value to "Turn: " display. struct World * world = (struct World *) win->data; - uint16_t count = world->turn; char text[100]; - snprintf(text, 100, "Turn: %d", count); + snprintf(text, 100, "Turn: %d\nHitpoints: %d", world->turn, world->player->hitpoints); draw_with_linebreaks(win, text, 0); } extern void draw_keys_win (struct Win * win) { diff --git a/src/objects_on_map.c b/src/objects_on_map.c index 70d4378..76c57e0 100644 --- a/src/objects_on_map.c +++ b/src/objects_on_map.c @@ -105,6 +105,9 @@ extern void move_monster (struct World * world, struct Monster * monster) { struct yx_uint16 t = mv_yx_in_dir (d, monster->cmo.pos); if (yx_uint16_cmp (t, world->player->pos)) { update_log (world, "\nThe monster hits you."); + world->player->hitpoints--; + if (0 == world->player->hitpoints) + update_log (world, "\nYou are dead."); return; } struct Monster * other_monster; for (other_monster = world->monster; other_monster != 0; other_monster = other_monster->cmo.next) { diff --git a/src/objects_on_map.h b/src/objects_on_map.h index 0d56c01..6f3772e 100644 --- a/src/objects_on_map.h +++ b/src/objects_on_map.h @@ -8,7 +8,8 @@ struct World; struct Map; struct Player { - struct yx_uint16 pos; }; + struct yx_uint16 pos; + unsigned char hitpoints; }; struct ChainMapObject { void * next; diff --git a/src/roguelike.c b/src/roguelike.c index 162740d..c3078b2 100644 --- a/src/roguelike.c +++ b/src/roguelike.c @@ -198,6 +198,7 @@ int main (int argc, char *argv[]) { world.log = calloc(1, sizeof(char)); update_log (&world, " "); struct Player player; + player.hitpoints = 5; world.player = &player; world.monster = 0; world.item = 0; @@ -253,8 +254,8 @@ int main (int argc, char *argv[]) { struct Win win_log = init_win(&win_meta, "Log", &world, draw_log_win); win_keys.frame.size.x = 29; win_map.frame.size.x = win_meta.pad.size.x - win_keys.frame.size.x - win_log.frame.size.x - 2; - win_info.frame.size.y = 1; - win_log.frame.size.y = win_meta.pad.size.y - 3; + win_info.frame.size.y = 2; + win_log.frame.size.y = win_meta.pad.size.y - (2 + win_info.frame.size.y); toggle_window(&win_meta, &win_keys); toggle_window(&win_meta, &win_map); toggle_window(&win_meta, &win_info); @@ -263,8 +264,8 @@ int main (int argc, char *argv[]) { // Replay mode. int key; unsigned char quit_called = 0; + unsigned char await_actions = 1; if (0 == world.interactive) { - unsigned char still_reading_file = 1; int action; while (1) { if (start_turn == world.turn) @@ -272,12 +273,12 @@ int main (int argc, char *argv[]) { if (0 == start_turn) { draw_all_wins (&win_meta); key = getch(); } - if (1 == still_reading_file && + if (1 == await_actions && (world.turn < start_turn || key == get_action_key(world.keybindings, "wait / next turn")) ) { action = getc(file); if (EOF == action) { start_turn = 0; - still_reading_file = 0; } + await_actions = 0; } else if (0 == action) player_wait (&world); else if (NORTH == action) @@ -300,17 +301,19 @@ int main (int argc, char *argv[]) { if (last_turn != world.turn) { save_game(&world); last_turn = world.turn; } + if (1 == await_actions && 0 == player.hitpoints) + await_actions = 0; draw_all_wins (&win_meta); key = getch(); - if (key == get_action_key(world.keybindings, "player up")) + if (1 == await_actions && key == get_action_key(world.keybindings, "player up")) move_player(&world, NORTH); - else if (key == get_action_key(world.keybindings, "player right")) + else if (1 == await_actions && key == get_action_key(world.keybindings, "player right")) move_player(&world, EAST); - else if (key == get_action_key(world.keybindings, "player down")) + else if (1 == await_actions && key == get_action_key(world.keybindings, "player down")) move_player(&world, SOUTH); - else if (key == get_action_key(world.keybindings, "player left")) + else if (1 == await_actions && key == get_action_key(world.keybindings, "player left")) move_player(&world, WEST); - else if (key == get_action_key(world.keybindings, "wait / next turn")) + else if (1 == await_actions && key == get_action_key(world.keybindings, "wait / next turn")) player_wait (&world); else quit_called = meta_keys(key, &world, &win_meta, &win_keys, &win_map, &win_info, &win_log);