From 53d4b86b0a3a1e2010dd6eb297fd935ddf24928b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Fri, 18 Oct 2019 17:26:13 +0200 Subject: [PATCH] Continue AI --- constants.h | 8 +++++++- main.c | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/constants.h b/constants.h index 1068865..5b793b4 100644 --- a/constants.h +++ b/constants.h @@ -58,6 +58,12 @@ Rate at which AI will be updated, which also affects how fast enemies will appear. */ -#define SFG_AI_FPS 5 +#define SFG_AI_FPS 2 + +/** + Says a probability (0 - 255) of the AI changing its state during one update + step. +*/ +#define SFG_AI_RANDOM_CHANGE_PROBABILITY 20 #endif // guard diff --git a/main.c b/main.c index 2f66867..8fdcf80 100755 --- a/main.c +++ b/main.c @@ -1015,6 +1015,11 @@ void SFG_monsterPerformAI(SFG_MonsterRecord *monster) coordAdd[0] = 0; coordAdd[1] = 0; + if (SFG_random() < SFG_AI_RANDOM_CHANGE_PROBABILITY) + { + // sometimes randomly change state + state = SFG_MONSTER_STATE_IDLE; + } if (state == SFG_MONSTER_STATE_IDLE) { switch (SFG_random() % 8)