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,10 +476,10 @@ run_game(void)
currentTurn = MONSTER; currentTurn = MONSTER;
player_reset_steps(gPlayer); player_reset_steps(gPlayer);
} }
} } else if (currentTurn == MONSTER) {
if (currentTurn == MONSTER) { if (map_move_monsters(gMap, gRoomMatrix)) {
if (map_move_monsters(gMap, gRoomMatrix))
currentTurn = PLAYER; currentTurn = PLAYER;
}
} }
SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0); SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0);

View File

@ -102,7 +102,6 @@ map_clear_dead_monsters(Map *map, Player *player)
while (map->monsters) { while (map->monsters) {
Monster *monster = linkedlist_pop(&map->monsters); Monster *monster = linkedlist_pop(&map->monsters);
if (monster->stats.hp <= 0) { if (monster->stats.hp <= 0) {
// Loot drops
monster_drop_loot(monster, map, player); monster_drop_loot(monster, map, player);
monster_destroy(monster); monster_destroy(monster);
} else { } else {
@ -147,6 +146,8 @@ map_move_monsters(Map *map, RoomMatrix *rm)
while (m) { while (m) {
Monster *monster = m->data; Monster *monster = m->data;
m = m->next; m = m->next;
if (monster->stats.hp <= 0)
continue;
if (!position_in_room(&monster->sprite->pos, &map->currentRoom)) if (!position_in_room(&monster->sprite->pos, &map->currentRoom))
continue; continue;
allDone = allDone && monster_move(monster, rm); allDone = allDone && monster_move(monster, rm);

View File

@ -78,5 +78,5 @@ bool position_in_room(Position *pos, Position *roomPos)
bool bool
position_in_roommatrix(const Position *pos) 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;
} }