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 (and each other) on contact, but without
-consequences (no hitpoints implemented yet). The map gets generated
+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.
if (other_monster == monster)
continue;
if (yx_uint16_cmp (t, other_monster->pos)) {
- update_log (world, "\nMonster hits monster.");
+ update_log (world, "\nMonster bumps into monster.");
return; } }
if (is_passable(world->map, t))
monster->pos = t; }
for (monster = world->monster; monster != 0; monster = monster->next)
if (yx_uint16_cmp (t, monster->pos)) {
update_log (world, "\nYou hit the monster.");
+ monster->hitpoints--;
+ if (0 == monster->hitpoints) {
+ update_log (world, "\nYou kill the monster.");
+ if (world->monster == monster)
+ world->monster = world->monster->next;
+ else {
+ struct Monster * m_prev;
+ for (m_prev = world->monster; m_prev->next != monster; m_prev = m_prev->next);
+ m_prev->next = monster->next; }
+ free(monster); }
turn_over (world, d);
return; }
char * msg = calloc(25, sizeof(char));
struct Monster {
struct Monster * next;
unsigned char name;
- struct yx_uint16 pos; };
+ struct yx_uint16 pos;
+ unsigned char hitpoints; };
extern char is_passable (struct Map *, struct yx_uint16);
extern struct yx_uint16 find_passable_pos (struct Map *);
for (monster = world->monster; monster != 0; monster = monster->next) {
write_uint16_bigendian(monster->pos.y + 1, file);
write_uint16_bigendian(monster->pos.x + 1, file);
- fputc(monster->name, file); }
+ fputc(monster->name, file);
+ fputc(monster->hitpoints, file); }
write_uint16_bigendian(0, file);
struct Item * item;
for (item = world->item; item != 0; item = item->next) {
monster = monster->next; }
monster->pos.y = test - 1;
monster->pos.x = read_uint16_bigendian(file) - 1;
- monster->name = fgetc(file); }
+ monster->name = fgetc(file);
+ monster->hitpoints = fgetc(file); }
if (!start)
monster->next = 0;
start = 1;
monster->next = malloc(sizeof(struct Monster));
monster = monster->next; }
monster->pos = find_passable_pos(&map);
- monster->name = 'A' + (rrand(0, 0) % 8); }
+ monster->name = 'A' + (rrand(0, 0) % 8);
+ monster->hitpoints = 5; }
if (!start)
monster->next = 0;
start = 1;