From 9c2cbe6d0e28387f79c72a43e1e45884e9c7f2f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Wed, 30 Sep 2020 23:17:08 +0200 Subject: [PATCH] Fix monster movement --- game.h | 36 ++++++++++++++++++++++++++---------- main_sdl.c | 4 ++-- main_terminal.c | 2 -- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/game.h b/game.h index 3e4228e..b7b506b 100755 --- a/game.h +++ b/game.h @@ -2332,8 +2332,7 @@ void SFG_monsterPerformAI(SFG_MonsterRecord *monster) SFG_MONSTER_COORD_TO_RCL_UNITS(monster->coords[1]), currentHeight) / 2); - if (add) - state = SFG_MONSTER_STATE_IDLE; + state = SFG_MONSTER_STATE_IDLE; } int16_t newPos[2]; @@ -2349,16 +2348,33 @@ void SFG_monsterPerformAI(SFG_MonsterRecord *monster) } else { - RCL_Unit newHeight = - SFG_floorCollisionHeightAt(newPos[0] / 4,newPos[1] / 4); + uint8_t movingDiagonally = (coordAdd[0] != 0) && (coordAdd[1] != 0); - collision = - RCL_abs(currentHeight - newHeight) > RCL_CAMERA_COLL_STEP_HEIGHT; + // when moving diagonally, we need to check extra tiles - if (!collision) - collision = - (SFG_ceilingHeightAt(newPos[0] / 4,newPos[1] / 4) - newHeight) < - SFG_MONSTER_COLLISION_HEIGHT; + for (uint8_t i = 0; i < (1 + movingDiagonally); ++i) + { + newPos[0] = monster->coords[0] + (i != 1) * coordAdd[0]; + + RCL_Unit newHeight = + SFG_floorCollisionHeightAt( + SFG_MONSTER_COORD_TO_SQUARES(newPos[0]), + SFG_MONSTER_COORD_TO_SQUARES(newPos[1])); + + collision = + RCL_abs(currentHeight - newHeight) > RCL_CAMERA_COLL_STEP_HEIGHT; + + if (!collision) + collision = (SFG_ceilingHeightAt( + SFG_MONSTER_COORD_TO_SQUARES(newPos[0]), + SFG_MONSTER_COORD_TO_SQUARES(newPos[1])) - newHeight) < + SFG_MONSTER_COLLISION_HEIGHT; + + if (collision) + break; + } + + newPos[0] = monster->coords[0] + coordAdd[0]; } if (collision) diff --git a/main_sdl.c b/main_sdl.c index 1d43663..6a38644 100644 --- a/main_sdl.c +++ b/main_sdl.c @@ -33,8 +33,8 @@ #define SFG_REVEAL_MAP 1 // #define SFG_INFINITE_AMMO 1 - #define SFG_SCREEN_RESOLUTION_X 127 - #define SFG_SCREEN_RESOLUTION_Y 42 +// #define SFG_SCREEN_RESOLUTION_X 127 +// #define SFG_SCREEN_RESOLUTION_Y 42 // #define SFG_SCREEN_RESOLUTION_X 80 // #define SFG_SCREEN_RESOLUTION_Y 64 diff --git a/main_terminal.c b/main_terminal.c index f4facb5..75e0d04 100644 --- a/main_terminal.c +++ b/main_terminal.c @@ -21,8 +21,6 @@ #include #include -//#define SFG_SCREEN_RESOLUTION_X 127 -//#define SFG_SCREEN_RESOLUTION_Y 42 #define SFG_SCREEN_RESOLUTION_X 127 #define SFG_SCREEN_RESOLUTION_Y 42 #define SFG_DITHERED_SHADOW 1