Ejemplo n.º 1
0
//取得精灵位置
Vec2	 FishLayer::GetSpritePosition()
{
	auto  s = Director::getInstance()->getWinSize();
	Vec2  tPos(s.width/2,s.height/2);
	if(m_Sprite)
	{
		tPos = m_Sprite->getPosition();
	}
	return tPos;
}
Ejemplo n.º 2
0
void TurretAIComponent::search() // Currently Only Shoots at the Player
{
	bool foundTarget = false;
	Position pos = curPosition_;
	Position tPos(0,0); // Target Position;

	pos = curPosition_;
	searchLine(pos, DIRECTION_UP, visionRange_, tPos, foundTarget);
	if (foundTarget == true)
	{
		targetPosition_ = tPos;
		shoot(DIRECTION_UP);
		targetFound_ = true;
		return;
	}

	pos = curPosition_;
	searchLine(pos, DIRECTION_DOWN, visionRange_, tPos, foundTarget);

	if (foundTarget == true)
	{
		targetPosition_ = tPos;
		shoot(DIRECTION_DOWN);
		targetFound_ = true;
		return;
	}

	pos = curPosition_;
	searchLine(pos, DIRECTION_LEFT, visionRange_, tPos, foundTarget);

	if (foundTarget == true)
	{
		targetPosition_ = tPos;
		shoot(DIRECTION_LEFT);
		targetFound_ = true;
		return;
	}

	pos = curPosition_;
	searchLine(pos, DIRECTION_RIGHT, visionRange_, tPos, foundTarget);

	if (foundTarget == true)
	{
		targetPosition_ = tPos;
		shoot(DIRECTION_RIGHT);
		targetFound_ = true;
		return;
	}
}
void CircleTerrainBrush::Apply(TerrainUtility* m,const math::vector3d& pos,float strength,ETerrainModificationMode mode)
{
	math::vector3d*vtx= m->LockVerticies();

	//compute min and max bounding box of the brush in XZ plane
	math::vector3d minP=pos-m_outerRadius;
	math::vector3d maxP=pos+m_outerRadius;

	int segments=m->GetTerrain()->GetSegementsCount();

	//convert it to terrain space
	minP=m->GetTerrain()->TransformVectorToLocal(minP);
	maxP=m->GetTerrain()->TransformVectorToLocal(maxP);
	minP.x=math::Max(0,(int)minP.x);
	minP.z=math::Max(0,(int)minP.z);

	maxP.x=math::Min(segments-1,(int)maxP.x);
	maxP.z=math::Min(segments-1,(int)maxP.z);

	float weight;

	//math::vector3d tPos=m->GetTerrain()->TransformVector(pos);
	math::vector3d tPos(pos);
	tPos.y=0;

	for(int i=minP.x;i<maxP.x;++i)
	{
		for(int j=minP.z;j<maxP.z;++j)
		{
			int idx=i*segments+j;
			math::vector3d vPos=vtx[idx];
			vPos.y=0;
			weight=CalcWeight(tPos,vPos);
			if(weight>0){
				vtx[idx].y=ApplyAtVertex(vtx[idx].y,strength*weight,mode);
				m->GetTerrain()->OnHeightChanged(idx,vtx[idx].y);
			}
		}
	}


	m->Unlock();
}