From eedec535e93c797312d0141130f2f02e3bf1171a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Thu, 17 Oct 2019 23:58:19 +0200 Subject: [PATCH] Start AI --- constants.h | 6 ++++++ main.c | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/constants.h b/constants.h index c90ccd4..3b6d2b2 100644 --- a/constants.h +++ b/constants.h @@ -54,4 +54,10 @@ */ #define SFG_LEVEL_ELEMENT_ACTIVE_DISTANCE 8 +/** + Time in ms after which AI will be recomputing its state (which also affects + how quickly death animation plays etc). +*/ +#define SFG_AI_UPDATE_INTERVAL 500 + #endif // guard diff --git a/main.c b/main.c index 3eb88a4..b8d2b0a 100755 --- a/main.c +++ b/main.c @@ -283,6 +283,13 @@ typedef struct #define SFG_MAX_MONSTERS 64 +#define SFG_AI_UPDATE_FRAME_INTERVAL \ + (SFG_AI_UPDATE_INTERVAL / SFG_MS_PER_FRAME) + +#if SFG_AI_UPDATE_FRAME_INTERVAL == 0 + #define SFG_AI_UPDATE_FRAME_INTERVAL 1 +#endif + /* GLOBAL VARIABLES =============================================================================== @@ -971,6 +978,11 @@ void SFG_playerRotateWeapon(uint8_t next) SFG_player.weapon %= 3; } +void SFG_monsterPerformAI(SFG_MonsterRecord *monster, int8_t recomputeState) +{ + // TODO +} + /** Performs one game step (logic, physics), happening SFG_MS_PER_FRAME after previous frame. @@ -1269,6 +1281,15 @@ void SFG_gameStep() SFG_currentLevel.monsterRecordCount) SFG_currentLevel.checkedMonsterIndex = 0; } + + int8_t recomputeAIState = ((SFG_gameFrame - SFG_currentLevel.frameStart) % + SFG_AI_UPDATE_FRAME_INTERVAL) == 0; + + for (uint8_t i = 0; i < SFG_currentLevel.monsterRecordCount; ++i) + if (SFG_currentLevel.monsterRecords[i].stateType != + SFG_MONSTER_STATE_INACTIVE) + SFG_monsterPerformAI( + &(SFG_currentLevel.monsterRecords[i]),recomputeAIState); } void SFG_clearScreen(uint8_t color)