예제 #1
0
파일: Leg.cpp 프로젝트: kronick/EARTH-ROVER
void Leg::freeze() {
  if(mode == PUSH_MODE) {
    //solveFK();
    //setTarget(foot);
  }
  setMoveVector(MoveVector());
}
예제 #2
0
void Monster::onEnter()
{
	Character::onEnter();

	schedule(schedule_selector(Monster::onUpdate));

	int MonsterIdx = m_iMonsterID - 1;

	setCurSpeed(GI.getMonsterConfig()[MonsterIdx].fMoveSpeed);
	setMaxSpeed(GI.getMonsterConfig()[MonsterIdx].fMoveSpeed);
	setMaxHealth(GI.getMonsterConfig()[MonsterIdx].iHP);
	setCurHealth(GI.getMonsterConfig()[MonsterIdx].iHP);

	setMoveVector(ccp(1, 0));

	sprintf(CMonster, "spirit/monster/Monster%d", m_iMonsterID);
	std::string StrMonster(CMonster);

	// 设置动画
	// 0.右 1.下 2.左 3.上 
	m_pWalkAnim[0] = CCAnimation::create();
	m_pWalkAnim[0]->retain();
	m_pWalkAnim[0]->addSpriteFrameWithFileName( (StrMonster + std::string("_R_1.png")).c_str() );
	m_pWalkAnim[0]->addSpriteFrameWithFileName( (StrMonster + std::string("_R_2.png")).c_str() );
	m_pWalkAnim[0]->setDelayPerUnit(0.5f / getCurSpeed());

	m_pWalkAnim[1] = CCAnimation::create();
	m_pWalkAnim[1]->retain();
	m_pWalkAnim[1]->addSpriteFrameWithFileName( (StrMonster + std::string("_D_1.png")).c_str() );
	m_pWalkAnim[1]->addSpriteFrameWithFileName( (StrMonster + std::string("_D_2.png")).c_str() );
	m_pWalkAnim[1]->setDelayPerUnit(0.5f / getCurSpeed());

	m_pWalkAnim[2] = CCAnimation::create();
	m_pWalkAnim[2]->retain();
	m_pWalkAnim[2]->addSpriteFrameWithFileName( (StrMonster + std::string("_L_1.png")).c_str() );
	m_pWalkAnim[2]->addSpriteFrameWithFileName( (StrMonster + std::string("_L_2.png")).c_str() );
	m_pWalkAnim[2]->setDelayPerUnit(0.5f / getCurSpeed());

	m_pWalkAnim[3] = CCAnimation::create();
	m_pWalkAnim[3]->retain();
	m_pWalkAnim[3]->addSpriteFrameWithFileName( (StrMonster + std::string("_U_1.png")).c_str() );
	m_pWalkAnim[3]->addSpriteFrameWithFileName( (StrMonster + std::string("_U_2.png")).c_str() );
	m_pWalkAnim[3]->setDelayPerUnit(0.5f / getCurSpeed());

	// 设置技能
	m_pSkill = Skill::create(GI.getMonsterConfig()[MonsterIdx].iSkillID);
	addChild(m_pSkill);

	// 冰冻
	m_bIsFrozen = false;
	m_bForceToStop = false;
	m_bDropItemAfterDeath = true;
}
예제 #3
0
/** 
 * 在这里简单实现怪物的AI
 */
bool Monster::onMove()
{
	if (m_bIsMoving)
	{
		return false;
	}

	CCPoint curPos = getPosition();
	CCPoint curMoveVec = getMoveVector();
	
	memset(CanMove, 0, sizeof(CanMove));

	// 先判断是否可达
	for (int i = 0; i < 4; ++i)
	{
		// 跟现在的方向相反
		if (IsReverseDir(curMoveVec, WalkVec[i]))
		{
			continue;
		}
		if (!GI.Helper->isReachable(curPos, WalkVec[i], 1))
		{
			continue;
		}
		++CanMove[i];
	}

	// 是否存在敌人
	CCPoint enemyPos(0, 0);
	bool enemyExist = (GI.Me != NULL && GI.Me->getQueueNum() > 0);
	if (enemyExist)
	{
		enemyPos = GI.Me->getHead()->getPosition();
	}

	// 如果可达,判断最优方向
	for (int i = 0; i < 4; ++i)
	{
		if (CanMove[i] > 0)
		{
			if (enemyExist)
			{
				if (IsAheadOfMe(curPos, WalkVec[i], enemyPos))
				{
					++CanMove[i];
				}
			}
			else 
			{
				// 同向
				if (GI.Helper->ccpEqual(curMoveVec, WalkVec[i]))
				{
					++CanMove[i];
				}
			}
		}
	}

	int index = -1, ret = 0;
	for (int i = 0; i < 4; ++i)
	{
		if (CanMove[i] > ret)
		{
			index = i;
			ret = CanMove[i];
		}
	}

	if (-1 == index)
	{
		return false;
	}
	else 
	{
		setMoveVector(WalkVec[index]);
	}

	return Character::onMove();
}
예제 #4
0
파일: Leg.cpp 프로젝트: kronick/EARTH-ROVER
void Leg::moveTargetDown() {
  setMoveVector(Vec3f(0,0,65), 0);
}
예제 #5
0
파일: Leg.cpp 프로젝트: kronick/EARTH-ROVER
void Leg::moveTargetUp() {
  setMoveVector(Vec3f(0,0,-65), 0);
}