From 00c6708f8a54cb7cfe7f6221bb17e5537bd16dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sun, 29 Dec 2019 11:39:49 +0100 Subject: [PATCH] Remove dead monsters --- main.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 6fa9423..50c6293 100755 --- a/main.c +++ b/main.c @@ -1466,6 +1466,8 @@ void SFG_monsterPerformAI(SFG_MonsterRecord *monster) SFG_createExplosion(mX * RCL_UNITS_PER_SQUARE ,mY * RCL_UNITS_PER_SQUARE, SFG_TILE_FLOOR_HEIGHT(tile) * SFG_WALL_HEIGHT_STEP + SFG_WALL_HEIGHT_STEP); + + state = SFG_MONSTER_STATE_DYING; } } else @@ -2166,14 +2168,33 @@ void SFG_gameStep() } } - // update AI + // update AI and remove dead monsters if ((SFG_gameFrame - SFG_currentLevel.frameStart) % SFG_AI_UPDATE_FRAME_INTERVAL == 0) + { for (uint8_t i = 0; i < SFG_currentLevel.monsterRecordCount; ++i) - if (SFG_MR_STATE(SFG_currentLevel.monsterRecords[i]) != - SFG_MONSTER_STATE_INACTIVE) + { + uint8_t state = SFG_MR_STATE(SFG_currentLevel.monsterRecords[i]); + + if (state == SFG_MONSTER_STATE_DYING) + { + // remove dead + + for (uint8_t j = i; j < SFG_currentLevel.monsterRecordCount - 1; ++j) + SFG_currentLevel.monsterRecords[j] = + SFG_currentLevel.monsterRecords[j + 1]; + + SFG_currentLevel.monsterRecordCount -= 1; + + i--; + } + else if (state != SFG_MONSTER_STATE_INACTIVE) + { SFG_monsterPerformAI(&(SFG_currentLevel.monsterRecords[i])); + } + } + } } void SFG_clearScreen(uint8_t color)