コード例 #1
0
ファイル: VectorEnumerator.cpp プロジェクト: dpantele/crag
VectorEnumerator& VectorEnumerator::operator++( )
{
  int cur;
  
  if( seqLimit( ) ) {
    curLength--;
    if( curLength>=0 ) {
      stepBack( curVector[curLength] );
      cur = next( curVector[curLength] );
    }
  }
  else
    cur = start( );
  
  while( curLength>=0 ) {
    
    if( !finish( cur ) ) {
      
      if( curLength>=curVector.capacity( ) )
	curVector.resize( curLength+5 );
      
      curVector[curLength] = cur;
      ++curLength;
      
      if( seqOK( ) ) {
	stepTo( );
	if( seqComplete( ) ) {
	  return *this;
	}
	else {
	  if( seqLimit( ) ) {
	    curLength--;
	    stepBack( curVector[curLength] );
	    cur = next( curVector[curLength] );
	  }
	  else {
	    cur = start( );
	  }
	}
      }
      else {
	cur = next( curVector[--curLength] );
      }
    } // if( !finish( cur ) ) {
    else{
      --curLength;
      if( curLength>=0 ) {
	stepBack( curVector[curLength] );
	cur = curVector[curLength];
      }
      cur = next( cur );
    } // if( !finish( cur ) ) { } else {
    
  } // while( curLength>=0 ) {
  
  return *this;
}
コード例 #2
0
ファイル: Monster.cpp プロジェクト: kidsang/GlassTD2
bool Monster::findPath( Pos sour )
{
	this->parent = Pos(sour.x + 1, sour.y);
	Pos** record;
	record = new Pos *[mMapHeight];
	for(int i = 0; i < mMapHeight; ++i)
	{
		record[i] = new Pos[mMapWidth];
	}
	stack<CellNode> st = stack<CellNode>();
	CellNode node;
	node.self = sour;
	st.push(node);

	//判断从起点到终点之间是否有通路
	CellNode temp;
	while(true)
	{
		if(!st.empty())
		{
			temp = st.top();
			st.pop();
		}
		else
		{
			return false;
		}
		if(isFinal(temp.self))
		{
			if(isValid(temp.self))
			{
				markIt(temp.self);
				record[temp.self.y][temp.self.x] = temp.pare;
				parent = temp.pare;
			}
			break;
		}
		else
		{
			if(isValid(temp.self))
			{
				markIt(temp.self);
				record[temp.self.y][temp.self.x] = temp.pare;
				parent = temp.pare;
				pushPos(temp.self, st);
			}
		}
	}

	//// 如果有通路则寻找合适的路径
	Pos parent = finalPos;
	bool success = false;
	while(isValid(parent) && !success)
	{
		stepTo(parent);
		path.push_back(getStep());
		markIt(parent);
		parent = record[parent.y][parent.x];
		if(parent.x==sour.x && parent.y==sour.y)
		{
			success = true;
		}
	}
	path.push_back(fromPos);
	std::reverse(path.begin(),path.end());
	return true;
}
コード例 #3
0
ファイル: Timeline.cpp プロジェクト: Justinmaurer/Cinder
void Timeline::step( float timestep )
{
	mCurrentTime += timestep;
	stepTo( mCurrentTime, timestep < 0 );
}
コード例 #4
0
ファイル: Timeline.cpp プロジェクト: Justinmaurer/Cinder
void Timeline::update( float absTime )
{
	absTime = loopTime( absTime );
	stepTo( absTime );
}