You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
1.6 KiB
131 lines
1.6 KiB
#include "monster.h"
|
|
|
|
Monster::Monster(IMAGE* floor, Map* map) :Mover(floor, map)
|
|
{
|
|
fear = 0;
|
|
x = BLOCK_SIZE * 9 + BLOCK_SIZE / 2;
|
|
y = BLOCK_SIZE * 6 + BLOCK_SIZE / 2;
|
|
speed = 1;
|
|
|
|
ImportImage("image/Pinky.png");
|
|
}
|
|
|
|
int Monster::Update(int px, int py)
|
|
{
|
|
if (fear == 0)
|
|
{
|
|
if (TryEatPlayer(px, py))
|
|
return -1;
|
|
}
|
|
else if (fear > 0)
|
|
{
|
|
fear--;
|
|
if (EscapePlayer(px, py))
|
|
{
|
|
fear = -1000;
|
|
return 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 死亡,返回重生区
|
|
|
|
// 待补充代码
|
|
fear++;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
bool Monster::TryEatPlayer(int px, int py)
|
|
{
|
|
dir = GainDirToEatPlayer(px,py);
|
|
if (Move())
|
|
{
|
|
int dx = px - x;
|
|
int dy = py - y;
|
|
if (abs(dx) < EAT_TOLERANCE && abs(dy) < EAT_TOLERANCE)
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
dir += 1;
|
|
dir %= 2;
|
|
Move();
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool Monster::EscapePlayer(int px, int py)
|
|
{
|
|
dir = -GainDirToEatPlayer(px, py);
|
|
if (Move())
|
|
{
|
|
int dx = px - x;
|
|
int dy = py - y;
|
|
if (abs(dx) < EAT_TOLERANCE && abs(dy) < EAT_TOLERANCE)
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
dir += 1;
|
|
dir %= 2;
|
|
Move();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void Monster::SetFear(int f)
|
|
{
|
|
fear = f;
|
|
}
|
|
|
|
int Monster::GetFear()
|
|
{
|
|
return fear;
|
|
}
|
|
|
|
int Monster::GainDirToEatPlayer(int px, int py)
|
|
{
|
|
|
|
int dir = DIR_NONE;
|
|
if (px < x - MOVE_TOLERENCE / 2)
|
|
{
|
|
dir = DIR_LEFT;
|
|
}
|
|
else if (px > x + MOVE_TOLERENCE / 2)
|
|
{
|
|
dir = DIR_RIGHT;
|
|
}
|
|
else if (py < y - MOVE_TOLERENCE / 2)
|
|
{
|
|
dir = DIR_UP;
|
|
}
|
|
else if (py > y + MOVE_TOLERENCE / 2)
|
|
{
|
|
dir = DIR_DOWN;
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
int dir = this->dir;
|
|
static int ddd = 1000;
|
|
ddd--;
|
|
if (ddd == 0)
|
|
{
|
|
dir = rand() % 5 - 2;
|
|
while (dir == 0)
|
|
{
|
|
dir = rand() % 5 - 2;
|
|
}
|
|
ddd = 1000;
|
|
}
|
|
*/
|
|
|
|
|
|
return dir;
|
|
}
|