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.
This commit is contained in:
Linus Probert 2018-03-13 23:36:39 +01:00
parent d983318453
commit 1bea221369
3 changed files with 6 additions and 5 deletions

View File

@ -476,11 +476,11 @@ 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);
SDL_RenderClear(gRenderer);

View File

@ -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);

View File

@ -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;
}