From: Christian Heller Date: Tue, 27 Aug 2013 03:32:32 +0000 (+0200) Subject: Player earns a score by killing enemies. X-Git-Tag: tce~1022 X-Git-Url: https://plomlompom.com/repos/?p=plomrogue;a=commitdiff_plain;h=435c55c675cad9355a4e82c4d4379267f0c9a9b0 Player earns a score by killing enemies. --- diff --git a/README b/README index 0e55639..09cff46 100644 --- a/README +++ b/README @@ -3,12 +3,18 @@ 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 number of different -enemies. They move randomly and will only accidentally hit you. You have -5 hitpoints to lose before death; they have either 1, 3 or 9. The map -get 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 number of different enemies. +They move randomly and will only accidentally hit you. You have 5 +hitpoints to lose before death; they have either 1, 3 or 9. Your score +grows by killing enemies, to the amount of hitpoints each killed enemy +started with. + +The map get 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 a72978c..7747757 100644 --- a/src/draw_wins.c +++ b/src/draw_wins.c @@ -209,7 +209,8 @@ extern void draw_info_win(struct Win * win) struct World * world = (struct World *) win->data; char text[100]; snprintf(text, 100, - "Turn: %d\nHitpoints: %d", world->turn, world->player->hitpoints); + "Turn: %d\nHitpoints: %d\nScore: %d", + world->turn, world->player->hitpoints, world->score); draw_with_linebreaks(win, text, 0); } diff --git a/src/main.c b/src/main.c index 7caef90..f811867 100644 --- a/src/main.c +++ b/src/main.c @@ -106,6 +106,7 @@ int main(int argc, char *argv[]) exit_err(0 == file, &world, err_o); if ( read_uint32_bigendian(file, &world.seed) || read_uint32_bigendian(file, &world.turn) + || read_uint16_bigendian(file, &world.score) || read_uint16_bigendian(file, &player.pos.y) || read_uint16_bigendian(file, &player.pos.x) || read_uint8(file, &player.hitpoints) @@ -140,6 +141,7 @@ int main(int argc, char *argv[]) else { world.seed = time(NULL); + world.score = 0; err_o = "Trouble recording new seed (fopen() in main()) / " "opening 'record_tmp' file for writing."; @@ -192,7 +194,7 @@ int main(int argc, char *argv[]) struct Win win_keys = init_win(&win_meta, "Keys", 0, 29, &world, draw_keys_win); struct Win win_info = init_win(&win_meta, "Info", - 2, 20, &world, draw_info_win); + 3, 20, &world, draw_info_win); uint16_t height_logwin = win_meta.padframe.size.y - (2 + win_info.frame.size.y); struct Win win_log = init_win(&win_meta, "Log", diff --git a/src/main.h b/src/main.h index fc9bbc3..5eec390 100644 --- a/src/main.h +++ b/src/main.h @@ -26,6 +26,7 @@ struct World struct KeysWinData * keyswindata; /* Pointer to key edit window metadata. */ uint32_t seed; /* Randomness seed. */ uint32_t turn; /* Current game turn. */ + uint16_t score; /* Player's score. */ char * log; /* Pointer to the game log string. */ struct Map * map; /* Pointer to the game map cells. */ struct ItemDef * item_def; /* Pointer to the item definitions. */ diff --git a/src/map_object_actions.c b/src/map_object_actions.c index 53253bc..bc6e473 100644 --- a/src/map_object_actions.c +++ b/src/map_object_actions.c @@ -101,6 +101,8 @@ static void player_hits_monster(struct World * world, struct Monster * monster) m_prev->map_obj.next = monster->map_obj.next; } } + uint8_t score = md->hitpoints_start; + world->score = world->score + score; free(monster); } } diff --git a/src/misc.c b/src/misc.c index 8a78273..8eda126 100644 --- a/src/misc.c +++ b/src/misc.c @@ -167,6 +167,7 @@ extern void save_game(struct World * world) exit_err(0 == file, world, err_open); if ( write_uint32_bigendian(world->seed, file) || write_uint32_bigendian(world->turn, file) + || write_uint16_bigendian(world->score, file) || write_uint16_bigendian(world->player->pos.y + 1, file) || write_uint16_bigendian(world->player->pos.x + 1, file) || write_uint8(world->player->hitpoints, file)