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.

102 lines
1.3 KiB

#include "monster.h"
#include "define.h"
Monster::Monster()
{
status = 0;
}
int Monster::GetStatus()
{
return status;
}
void Monster::SetStatus(int _status)
{
status = _status;
}
bool Monster::TryEatPlayer(Player player)
{
double px, py;
px = player.GetX();
py = player.GetY();
if (px - x < 0.1 && px - x > -0.1 &&
py - y < 0.1 && py - y > -0.1) // 判断怪物是否遇到玩家
{
if (status == 0)
return true;
else if (status > 0)
{
player.EatMonster();
status = -1;
}
}
return false;
}
void Monster::MonsterMove(const Map& wall, Player player, const Map& bean, const Map& goldBean)
{
int dir;
if (status < 0)
{
dir = WaitingBorn(wall);
}
else if (status > 0)
{
dir = Escape(wall, player);
status--;
}
else
{
dir = Chase(wall, player);
}
Move(dir);
// 恢复绘制走过的bean和goldBean
// ....
}
int Monster::Chase(const Map& wall, Player player)
{
return 0;
}
int Monster::Escape(const Map& wall, Player player)
{
int dir = Chase(wall, player);
// 反向逃避即可
switch (dir)
{
case DIR_UP: dir = DIR_DOWN; break;
case DIR_DOWN: dir = DIR_UP; break;
case DIR_LEFT: dir = DIR_RIGHT; break;
case DIR_RIGHT: dir = DIR_LEFT; break;
default: dir = DIR_LEFT; break;
}
return dir;
}
int Monster::WaitingBorn(const Map& wall)
{
return 0;
}