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


C++ PlayerEntity::GetPos方法代码示例

本文整理汇总了C++中PlayerEntity::GetPos方法的典型用法代码示例。如果您正苦于以下问题:C++ PlayerEntity::GetPos方法的具体用法?C++ PlayerEntity::GetPos怎么用?C++ PlayerEntity::GetPos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PlayerEntity的用法示例。


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

示例1: Update

void MainScreen::Update() {

    Chamber * curChamber = CM->GetCurrentChamber();
    PlayerEntity * player = CM->GetPlayer();

	if ( player != 0 ) {

        if ( !(player->IsInMotion())  ) { // && !(curChamber->HasEntityInMotion())

            int numDirsPressed = (keysPressed[DOWN] ? 1 : 0) + (keysPressed[UP] ? 1 : 0) + (keysPressed[LEFT] ? 1 : 0) + (keysPressed[RIGHT] ? 1 : 0);

            // interaction with environment
            if ( keysToggled[INTERACT] && keysPressed[INTERACT] ) {
                
                int dx = UTIL::DirToXAdjustment( player->GetDir() );
                int dy = UTIL::DirToYAdjustment( player->GetDir() );
                int curx = player->GetPos()->GetTileX();
                int cury = player->GetPos()->GetTileY();

                // check to see if there is an entity with the sygaldry property in the tile we are facing
                TileEntity * sygaldryAble = curChamber->GetEntityWithPropertyInTile( "Sygaldry", Chamber::GetTileNumFromPos(curx + dx, cury + dy) );
                if ( sygaldryAble != 0 ) {
                    // open the SygaldryScreen on that object
                    BaseScreen * bs = new SygaldryScreen( sygaldryAble );
                    bs->Init();
                    (ScreenManager::GetInstance()).PushGameScreen( bs );
                }
                
            } else if ( keysToggled[INVENTORY] && keysPressed[INVENTORY] ) {

                // open up the inventory screen
                BaseScreen * bs = new InventoryScreen();
                bs->Init();
                (ScreenManager::GetInstance()).PushGameScreen( bs );

            } else if ( keysToggled[ALLEGRO_KEY_F] && keysPressed[ALLEGRO_KEY_F] ) {

                int dx = UTIL::DirToXAdjustment( player->GetDir() );
                int dy = UTIL::DirToYAdjustment( player->GetDir() );
                int curx = player->GetPos()->GetTileX();
                int cury = player->GetPos()->GetTileY();

                std::list <TileEntity *> * tileEntityList = curChamber->GetEntitiesInTile( Chamber::GetTileNumFromPos(curx + dx, cury + dy) );
                std::list < TileEntity * >::iterator iter;
	            for ( iter = tileEntityList->begin(); iter != tileEntityList->end(); ++iter ) {
                    (*iter)->OnInput( "OnHeated" );
                }

            } else if ( keysToggled[ALLEGRO_KEY_G] && keysPressed[ALLEGRO_KEY_G] ) {

                int dx = UTIL::DirToXAdjustment( player->GetDir() );
                int dy = UTIL::DirToYAdjustment( player->GetDir() );
                int curx = player->GetPos()->GetTileX();
                int cury = player->GetPos()->GetTileY();

                std::list <TileEntity *> * tileEntityList = curChamber->GetEntitiesInTile( Chamber::GetTileNumFromPos(curx + dx, cury + dy) );
                std::list < TileEntity * >::iterator iter;
	            for ( iter = tileEntityList->begin(); iter != tileEntityList->end(); ++iter ) {
                    (*iter)->OnInput( "OnChilled" );
                }

            } else if ( keysToggled[ALLEGRO_KEY_R] && keysPressed[ALLEGRO_KEY_R] ) {

                int uid = curChamber->GetUID();
                CM->ReloadChamber( uid );
                CM->SetCurrentChamber( uid ); 
                return;

            } else if ( numDirsPressed == 1 ) {

			    int dx = 0;
			    int dy = 0;
			    if ( keysPressed[DOWN] ) {
				    dy = 1;
			    } else if ( keysPressed[UP] ) {
				    dy = -1;
			    } else if ( keysPressed[RIGHT] ) {
				    dx = 1;
			    } else if ( keysPressed[LEFT] ) {
				    dx = -1;
			    }

			    int desDir = UTIL::DirFromDelta(dx, dy);
			    if ( player->GetDir() != desDir ) {
				    player->SetDir( desDir );
			    } else {
                    int curx = player->GetPos()->GetTileX();
                    int cury = player->GetPos()->GetTileY();
                    int tx = curx + dx;
                    int ty = cury + dy;

				    // check if target is free
                    if ( curChamber->CanTileBeEntered( tx, ty ) ) {
                        curChamber->RegisterTileEntityInTile( player, tx, ty );
                        player->MoveWithAnimation( desDir, 24, PlayerEntity::MOVE::WALK );
                    }
                    else {
                        TileEntity * pushable = curChamber->GetEntityWithPropertyInTile( "MoveType", Chamber::GetTileNumFromPos( tx, ty) );
                        if ( pushable != 0 ) {
                            // we are pushing something
//.........这里部分代码省略.........
开发者ID:tawheeler,项目名称:learn-cpp-01,代码行数:101,代码来源:MainScreen.cpp


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