当前位置: 首页>>代码示例>>C++>>正文


C++ Direction函数代码示例

本文整理汇总了C++中Direction函数的典型用法代码示例。如果您正苦于以下问题:C++ Direction函数的具体用法?C++ Direction怎么用?C++ Direction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Direction函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: NewPosition

void NewPosition(MazewarInstance::Ptr m)
//void NewPosition(MazewarInstance *m)
{
	Loc newX(0);
	Loc newY(0);
	Direction dir(0); /* start on occupied square */

	while (M->maze_[newX.value()][newY.value()]) {
	  /* MAZE[XY]MAX is a power of 2 */
	  newX = Loc(random() & (MAZEXMAX - 1));
	  newY = Loc(random() & (MAZEYMAX - 1));

	  /* In real game, also check that square is
	     unoccupied by another rat */
	}

	/* prevent a blank wall at first glimpse */

	if (!m->maze_[(newX.value())+1][(newY.value())]) dir = Direction(NORTH);
	if (!m->maze_[(newX.value())-1][(newY.value())]) dir = Direction(SOUTH);
	if (!m->maze_[(newX.value())][(newY.value())+1]) dir = Direction(EAST);
	if (!m->maze_[(newX.value())][(newY.value())-1]) dir = Direction(WEST);

	m->xlocIs(newX);
	m->ylocIs(newY);
	m->dirIs(dir);
}
开发者ID:lufenghuan,项目名称:cs244b-mazewar,代码行数:27,代码来源:toplevel.cpp

示例2: main

int main()
{
    Adjacency v;
    ID id;
    Map map(0);
    cin >> id;
    Feature * r1 = new MockFeature( id );
    r1->addToMap( &map );
    cin >> id;
    Feature * r2 = new MockFeature( id );
    r2->addToMap( &map );
    cin >> id;
    Feature * r3 = new MockFeature( id );
    r3->addToMap( &map );

    std::cout << "******* ADJACENCY TESTS ***********\n";
    std::cout << "Input and save test. Expected output same as last "
              << "line of input plus tag\n";
    v.input( std::cin, &map );
    v.save( std::cout );
    std::cout << '\n';

    std::cout << "\nPretty-printed output (should list only exits "
              << "that are valid above)\n";
    v.printDescription( std::cout );

    std::cout << "\nDirection checks: Should be similar to above\n";
    printExit( v, Direction("north") );
    printExit( v, Direction("east") );
    printExit( v, Direction("south") );
    printExit( v, Direction("west") );
    return 0;
}
开发者ID:patrickmacarthur,项目名称:OurAdventure,代码行数:33,代码来源:test.C

示例3: Vector2int16

void CellularAutomata::handleMouse(bool isPressed, bool isDown, const Ray & mouseRay, const Vector2 & mousePos) {
    m_transientPlayhead.position = Vector2int16(-5, -5);
    if (m_paused) {
        Point2int16 selectedPosition(-1,-1);
        for (int x = 0; x < m_width; ++x) {
            for (int y = 0; y < m_height; ++y) {
                Vector2 normalizedCoord = Vector2(x,y) * 
                    Vector2(1.0f / (m_width - 1.0f), 1.0f / (m_height - 1.0f));
                     
                const Point3& p = normCoordTo3DPoint(normalizedCoord);
                if (intersects(mouseRay, p, collisionRadius())) {
                    selectedPosition = Vector2int16(x, y);
                }
            }
        }
        
        if (selectedPosition.x >= 0) {
 
            m_transientPlayhead.position  = selectedPosition;
            m_transientPlayhead.direction = Direction::DOWN;

            // Super hackish way to select the direction to point in based on mouse position 
            // from the center (should work on in either mode, but only tested on 2D)
            // This is the first thing due for a cleanup
            float minDistance = 10.0f; // Basically infinity...
            Vector2 normalizedCoord = Vector2(selectedPosition) *
                Vector2(1.0f / (m_width - 1.0f), 1.0f / (m_height - 1.0f)); 
            const Point3& center = normCoordTo3DPoint(normalizedCoord);
            float t = mouseRay.intersectionTime(Sphere(center, collisionRadius()));
            Point3 intersectionPoint = mouseRay.origin() + mouseRay.direction() * t;
            for (int i = 0; i < 4; ++i) {
                Vector2 npos = normalizedCoord + Vector2(vecFromDir(Direction(i)))*0.001f;
                const Point3& p = normCoordTo3DPoint(npos);
                if ((intersectionPoint - p).length() < minDistance) {
                    minDistance = (intersectionPoint - p).length();
                    m_transientPlayhead.direction = Direction(i);
                }
            }

            if (isPressed) {
                bool removed = false;
                for (int i = m_playhead.size() - 1; i >= 0; --i) {
                    if (selectedPosition == m_playhead[i].position) {
                        m_playhead.remove(i);
                        removed = true;
                        break;
                    }
                }
                
                if (!removed) {
                    m_playhead.append(m_transientPlayhead);
                }
                
            }
            
        } 
        
    }

}
开发者ID:Mx7f,项目名称:substep,代码行数:60,代码来源:CellularAutomata.cpp

示例4: switch

void Player::event(const sf::Event &event)
{
    if (event.type == sf::Event::KeyPressed)
    {
        switch (event.key.code)
        {
        case sf::Keyboard::Left:
            if (next != RIGHT)
                next = LEFT;
            break;
        case sf::Keyboard::Right:
            if (next != LEFT)
                next = RIGHT;
            break;
        case sf::Keyboard::Up:
            if (next != DOWN)
                next = UP;
            break;
        case sf::Keyboard::Down:
            if (next != UP)
                next = DOWN;
            break;
        default:
            next = Direction(0, 0);
            break;
        }
    }
    else if (event.type == sf::Event::KeyReleased)
        next = Direction(0, 0);
}
开发者ID:fbgtoke,项目名称:VGA-Dungeon,代码行数:30,代码来源:player.cpp

示例5: initializePlanetData

std::vector<PlanetData> initializePlanetData()
{
	std::srand(std::time(NULL));

	std::vector<PlanetData> data(Planet::TypeCount);

	data[Planet::Earth].speed = 45.f;
	data[Planet::Earth].texutre = Textures::Earth;
	data[Planet::Earth].directions.push_back(Direction(20, 1000.f));

	data[Planet::Pluton].speed = 50.f;
	data[Planet::Pluton].texutre = Textures::Pluton;
	data[Planet::Pluton].directions.push_back(Direction(0.f, 1000.f));

	data[Planet::AsteroidGreate].speed = 70.f;
	data[Planet::AsteroidGreate].texutre = Textures::AsteroidGreate;
	data[Planet::AsteroidGreate].directions.push_back(Direction((rand() % 15) * 1.f, 1000.f));

	data[Planet::AsteroidAverage].speed = 90.f;
	data[Planet::AsteroidAverage].texutre = Textures::AsteroidAverage;
	data[Planet::AsteroidAverage].directions.push_back(Direction(-15, 1000.f));

	data[Planet::AsteroidLittle].speed = 110.f;
	data[Planet::AsteroidLittle].texutre = Textures::AsteroidLittle;
	data[Planet::AsteroidLittle].directions.push_back(Direction(10.f, 1000.f));

	return data;
}
开发者ID:AlexDontsov2008,项目名称:spacecrash,代码行数:28,代码来源:DataTables.cpp

示例6: TEST

TEST (Direction, MazeSetDirection_ReturnSetValue)
{
  location_t loc = {3, 4};
  direction_t dir = EAST;
  EXPECT_EQ (INVALID, Direction (loc));
  SetDirection (loc, dir);
  EXPECT_EQ (dir, Direction (loc));
}
开发者ID:micromouseonline,项目名称:micromouse-maze,代码行数:8,代码来源:testDirection.cpp

示例7: tp0

void RandomModel::treesProduce() {
	/*
	double y = this->length / 10;
	double ty = y;
	double ry = 9 * y; 
	Point tp0(- this->width / 2, ty, TREE_HEIGHT);
	Point tp1(this->width / 2, ty, TREE_HEIGHT);
	Point tp2(- this->width / 2, ry, TREE_HEIGHT);
	Point tp3(this->width / 2, ry, TREE_HEIGHT);
	Tree t0(tp0);
    Tree t1(tp1);
    Tree t2(tp2);
    Tree t3(tp3);
	*/
	double x = this->width / 2;
	double y = this->length / 10;
	double z = 0;

	
    TreeConfig *tConfig0 = new TreeConfig(3, Point(x, y, z));
    Geometry *crown = NULL;
	///crown  = new Ball(Point(x, y, z+5), 8);
	//crown  = new BallPart(Point(x, y, z+5), 8, Point(x, y, z+3));
	//crown  = new Cylinder(Point(x, y, z+15), Point(x, y, z+5), 7);
	//crown  = new Cone(Point(x, y, z+25), Point(x, y, z+5), 10);
	//crown  = new Ellipse(Point(x, y, z+13), Point(x, y, z+1), 10, 8);
	//crown  = new EllipsePart(Point(x, y, z+13), Point(x, y, z+1), 10, 8, Point(x, y, z+8), true);
	crown  = new Cuboid(Direction(12,0,0), Direction(0,12,0), Direction(0,0,12), Point(x-3, y-4, z+5));
    tConfig0->setCrown(crown);
	/*
	TreeConfig *tConfig1 = new TreeConfig(3, Point(-x, y, z));
    TreeConfig *tConfig2 = new TreeConfig(3, Point(x,this->length - y, z));
    TreeConfig *tConfig3 = new TreeConfig(3, Point(-x, this->length - y, z));
	*/
	Tree t0(tConfig0);
	t0.generate();
	t0.generateLeavesList();
    /*
	Tree t1(tConfig1);	
	t1.generate();
	t1.generateLeavesList();
    Tree t2(tConfig2);
	t2.generate();
	t2.generateLeavesList();
    Tree t3(tConfig3);
	t3.generate();
	t3.generateLeavesList();
	*/
    this->trees.push_back(t0);

	/*
	this->trees.push_back(t1);
	this->trees.push_back(t2);
	this->trees.push_back(t3);
	*/
}
开发者ID:gabrielwu,项目名称:v2v,代码行数:56,代码来源:random_model.cpp

示例8: Direction

CircleGroup Field::GetSameColoredCircles( const Coordinate& startCoordinate )const
{
	Direction dirs[ 4 ] =
	{
		Direction( 0, 1 ), // <- WEST
		Direction( 1, 1 ), // _\| NORD_WEST
		Direction( 1, 0	), // _|_ NORD
		Direction( 1, -1 ) // _|/_ NORD_EAST
	};


	Coordinate firstCircle;

	CircleGroup result;
	result.isErase = false;

	int count = 0;
	int row = 0, col = 0;
	int i = 0;
	for( i = 0; i < 4; i ++ )
	{
		firstCircle = GetFirstCircle( startCoordinate, dirs[ i ] );

		row = firstCircle.row ;
		col = firstCircle.col ;

		count = 0;

		while( field[ firstCircle.row ][ firstCircle.col ].color ==
			field[ row ][ col ].color &&
			row >= 0 && row <= NUMSQUARES &&
			col >= 0 && col < NUMSQUARES &&
			( field[ row ][ col ].isFilled == true )
			)
		{
			row += dirs[ i ].plusToRow;
			col += dirs[ i ].plusToCol;

			count ++;
		}
		if( count >= 5 )
			break;

	}

	result.countOfCircles = count;
	result.firstCircle = firstCircle;
	result.isErase = ( count >= 5 ) ? true : false;
	result.moveDir = dirs[ i ];	

	return result;
}
开发者ID:AM636E,项目名称:Color-Lines,代码行数:52,代码来源:Field.cpp

示例9: Direction

String DumbDirectionSolver::mergeCommands(Point bomb, Direction direction) const {
	if (direction == Direction(LL("STOP"))) {
		bomb.setNull(true);
	}
	StringStream ss;
	if (!bomb.isNull()) {
		ss << Direction(LL("ACT")).toString();
		if (direction != Direction(LL("NULL"))) {
			ss << LL(",");
		}
	}
	ss << direction.toString();
	return ss.str();
}
开发者ID:Mperv,项目名称:snake,代码行数:14,代码来源:DumbDirectionSolver.cpp

示例10: Direction

Spiral::Direction Spiral::getIdealDirection(Direction current)
{
    if(rotation == Clockwise)
    {
        return Direction((current + 1) % Count);
    }
    else
    {
        if(current == Up)
            return Left;
        
        return Direction(current - 1);
    }
}
开发者ID:Elegy,项目名称:ProjectEuler,代码行数:14,代码来源:Spiral.cpp

示例11: initializeAircraftData

std::vector<AircraftData> initializeAircraftData(){
	std::vector<AircraftData> data(Aircraft::TypeCount);

	data[Aircraft::EAGLE].hitpoints = 100;
	data[Aircraft::EAGLE].speed = 200.f;
	data[Aircraft::EAGLE].texture = Resources::Textures::Entities;
	data[Aircraft::EAGLE].textureRect = sf::IntRect(0, 0, 48, 64);
	data[Aircraft::EAGLE].hasRollAnimation = true;

	data[Aircraft::RAPTOR].hitpoints = 20;
	data[Aircraft::RAPTOR].speed = 80;
	data[Aircraft::RAPTOR].texture = Resources::Textures::Entities;
	data[Aircraft::RAPTOR].textureRect = sf::IntRect(144, 0, 84, 64);
	data[Aircraft::RAPTOR].hasRollAnimation = false;

	data[Aircraft::RAPTOR].directions.push_back(Direction(+45, 80));
	data[Aircraft::RAPTOR].directions.push_back(Direction(-45, 160));
	data[Aircraft::RAPTOR].directions.push_back(Direction(+45, 80));

	data[Aircraft::AVENGER].hitpoints = 40;
	data[Aircraft::AVENGER].speed = 50.f;
	data[Aircraft::AVENGER].texture = Resources::Textures::Entities;
	data[Aircraft::AVENGER].textureRect = sf::IntRect(228, 0, 60, 59);
	data[Aircraft::AVENGER].hasRollAnimation = false;

	data[Aircraft::AVENGER].directions.push_back(Direction(+45, 50));
	data[Aircraft::AVENGER].directions.push_back(Direction(0, 50));
	data[Aircraft::AVENGER].directions.push_back(Direction(-45, 100));
	data[Aircraft::AVENGER].directions.push_back(Direction(0, 50));
	data[Aircraft::AVENGER].directions.push_back(Direction(+45, 50));



	return data;
}
开发者ID:mrphilips,项目名称:sfml,代码行数:35,代码来源:DataTable.cpp

示例12: BallAIFunction

	Direction BallAIFunction(QbertModel* /*model*/)
	{
		srand( (unsigned)time(NULL) );
		if (LastBox->IsOnPerimeter())
			return IntoBox;
		if (MovingDirection == OutOfBox)
			return Direction(rand() % 4);
		if (MovingDirection == Left)
			return ((rand() % 2) ? Right: Up);
		if (MovingDirection == Right)
			return ((rand() % 2) ? Left: Up);

		return Direction(rand() % 3);
	}
开发者ID:sangongs,项目名称:qbert3d,代码行数:14,代码来源:DiamondQbertModelEnemies.cpp

示例13: ToSlaw

 /// Creates a slaw that fully describes a Hand found by the Leap
 Slaw ToSlaw (Leap::Hand const& h) const
 { Leap::Vector
     phys_origin  = Point (h . palmPosition ()),
     phys_through = phys_origin + Direction (h . direction ());
   return Slaw::Map ("id", h . id (),
                     "dir", ToSlaw (Direction (h . direction ())),
                     "plmnrm", ToSlaw (Direction (h . palmNormal ())),
                     "plmpos", ToSlaw (phys_origin),
                     "plmvel", ToSlaw (h . palmVelocity ()),
                     "center", ToSlaw (Direction (h . sphereCenter ())),
                     "radius", h . sphereRadius (),
                     "orig", ToSlaw (phys_origin),
                     "thru", ToSlaw (phys_through));
 }
开发者ID:Oblong,项目名称:splash,代码行数:15,代码来源:splash.C

示例14: if

void Game::areDelayHandleEvent(const SDL_Event &event)
{
    if (event.type == SDL_KEYUP){
	SDLKey sym = event.key.keysym.sym;
	if (sym == playerData->moveLeft){
	    dropStatus = NORMAL;
	}
	else if (sym == playerData->moveRight){
	    dropStatus = NORMAL;
	}
    }
    
    if (event.type == SDL_KEYDOWN){
	SDLKey sym = event.key.keysym.sym;
	if (sym == playerData->moveLeft){
	    dropStatus = ARRLEFT;
	}
	else if (sym == playerData->moveRight){
	    dropStatus = ARRRIGHT;
	}
	else if (sym == playerData->rotateLeft){
	    direction = Direction(
		direction == 3? 0: direction + 1);
	}
	else if (sym == playerData->rotateRight){
	    direction = Direction(
		direction == 0? 3: direction - 1);
	}
	else if (sym == playerData->hardDrop){
	    pos = getLockPos();
	    ResourceData::sound->playChunk(Sound::HARDDROP);	    
	    if (!checkBlock(pos, direction)){
		gameOver();
	    } else{
		fillMap();
		gameStatus = START;
	    }
	}
	else if (sym == playerData->hold){
	    if (holdStatus == PREPAREHOLD){
		ResourceData::sound->playChunk(Sound::HOLD);
		holdStatus = HOLD;
		gameStatus = START;
	    } else{
		ResourceData::sound->playChunk(Sound::HOLDFAIL);
	    }
	}
    }
}
开发者ID:hjqqq,项目名称:tetrimino,代码行数:49,代码来源:game.cpp

示例15: ExtremePoint_BinarySearch

/*
\brief 二分查找法,求多边形上方向是u的极点,设凸多边形是逆时针顺序的。
*/
int ExtremePoint_BinarySearch( const Point2D* p, int n, const Vector2D& u)
{
	int	a = 0, b = n, m;
	int upA = Direction(p[1] - p[0],u) , upM;
	if( upA<=0 && !IsAbove(p[n-1],p[0],u) )
		return 0;
	while(true)
	{
		m = (a + b) / 2;
		upM = Direction(p[(m+1)%n] - p[m],u);
		if( upM<=0 && !IsAbove(p[m-1],p[m],u) )
			return m;
		if( upA>0 )
		{
			if( upM<0 )
			{				//选择[a,m]
				b = m;		
			}
			else if( IsAbove(p[a],p[m],u) )
			{				//选择[a,m]
				b = m;		
			}
			else
			{				//选择[m,b]
				a = m;
				upA = upM;
			}
		}
		else
		{
			if( upM>0 )
			{				//选择[m,b]
				a = m;
				upA = upM;
			}
			else if( IsBelow(p[a],p[m],u) )
			{				//选择[a,m]
				b = m;
			}
			else
			{				//选择[m,b]
				a = m;
				upA = upM;
			}
		}
	}
	return 0;
}
开发者ID:chongbingbao,项目名称:Programmers_Computational_Geometry,代码行数:51,代码来源:ExtremePoint.cpp


注:本文中的Direction函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。