From 1bea2213692a91ba5f0aee2f71aeae26fb92ac54 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Tue, 13 Mar 2018 23:36:39 +0100 Subject: [PATCH] Smooths out some glitches Don't move dead monsters. Don't run player and monster turn in one frame. Fixes a bad "position_in_room" check. --- src/main.c | 6 +++--- src/map.c | 3 ++- src/position.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 3fcfca8..be2454b 100644 --- a/src/main.c +++ b/src/main.c @@ -476,10 +476,10 @@ run_game(void) currentTurn = MONSTER; player_reset_steps(gPlayer); } - } - if (currentTurn == MONSTER) { - if (map_move_monsters(gMap, gRoomMatrix)) + } else if (currentTurn == MONSTER) { + if (map_move_monsters(gMap, gRoomMatrix)) { currentTurn = PLAYER; + } } SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0); diff --git a/src/map.c b/src/map.c index 93a0625..91c16f3 100644 --- a/src/map.c +++ b/src/map.c @@ -102,7 +102,6 @@ map_clear_dead_monsters(Map *map, Player *player) while (map->monsters) { Monster *monster = linkedlist_pop(&map->monsters); if (monster->stats.hp <= 0) { - // Loot drops monster_drop_loot(monster, map, player); monster_destroy(monster); } else { @@ -147,6 +146,8 @@ map_move_monsters(Map *map, RoomMatrix *rm) while (m) { Monster *monster = m->data; m = m->next; + if (monster->stats.hp <= 0) + continue; if (!position_in_room(&monster->sprite->pos, &map->currentRoom)) continue; allDone = allDone && monster_move(monster, rm); diff --git a/src/position.c b/src/position.c index 2092a70..2a0d387 100644 --- a/src/position.c +++ b/src/position.c @@ -78,5 +78,5 @@ bool position_in_room(Position *pos, Position *roomPos) bool position_in_roommatrix(const Position *pos) { - return pos->x >= 0 && pos->x < MAP_ROOM_WIDTH && pos->y > 0 && pos->y < MAP_ROOM_HEIGHT; + return pos->x >= 0 && pos->x < MAP_ROOM_WIDTH && pos->y >= 0 && pos->y < MAP_ROOM_HEIGHT; }