Fix monster movement

This commit is contained in:
Miloslav Číž 2020-09-30 23:17:08 +02:00
parent 256cfb3cb5
commit 9c2cbe6d0e
3 changed files with 28 additions and 14 deletions

36
game.h
View File

@ -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)

View File

@ -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

View File

@ -21,8 +21,6 @@
#include <sys/time.h>
#include <time.h>
//#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