X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/copy_free?a=blobdiff_plain;ds=sidebyside;f=src%2Fobjects_on_map.c;h=61efcdefc635ba1bb53dc0567ed7e37c0f81013c;hb=b4bb10b6e9089bd267a513dbf37543c318b5eb1e;hp=eedf800dca3b1ee58f80cbacc616cac9bddaa1be;hpb=5fc067b01c4651afec131a6c9f79c4cdd336e5c8;p=plomrogue diff --git a/src/objects_on_map.c b/src/objects_on_map.c index eedf800..61efcde 100644 --- a/src/objects_on_map.c +++ b/src/objects_on_map.c @@ -32,7 +32,7 @@ extern void move_monster (struct World * world, struct Monster * monster) { 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; } @@ -44,6 +44,16 @@ extern void move_player (struct World * world, char d) { 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));