Adds prevention from passive monsters being "dodgy"

When player gets close to passive monsters they will stop moving now.
This should prevent annoying behaviour when trying to line up a strike.
This commit is contained in:
Linus_Probert 2018-03-19 10:25:32 +01:00
parent 83a36db574
commit c8386ee719
3 changed files with 24 additions and 0 deletions

View File

@ -152,6 +152,13 @@ map_move_monsters(Map *map, RoomMatrix *rm)
continue;
if (!position_in_room(&monster->sprite->pos, &map->currentRoom))
continue;
// Prevent passive monsters from being "dodgy"
Position pos = position_to_matrix_coords(&monster->sprite->pos);
if (monster->state.current == PASSIVE
&& position_proximity(1, &rm->playerRoomPos, &pos))
continue;
allDone = allDone && monster_move(monster, rm);
}

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include "position.h"
#include "defines.h"
@ -55,6 +56,19 @@ position_equals(const Position *p1, const Position *p2)
return p1->x == p2->x && p1->y == p2->y;
}
bool
position_proximity(unsigned int distance,
const Position *p1,
const Position *p2)
{
unsigned int dx, dy;
dx = abs(p1->x - p2->x);
dy = abs(p1->y - p2->y);
return dx <= distance && dy <= distance;
}
bool
position_in_room(Position *pos, Position *roomPos)
{

View File

@ -38,6 +38,9 @@ position_in_room(Position *pos, Position *roomPos);
bool
position_equals(const Position*, const Position*);
bool
position_proximity(unsigned int distance, const Position*, const Position*);
bool
position_in_roommatrix(const Position*);