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


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

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


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

示例1: Update


//.........这里部分代码省略.........
            } 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
                            ForceNet * fnet = curChamber->GetForceNetContaining( pushable->GetUID() );
                            if ( fnet != 0  ) {
                                // handle pushing a force net
                                if ( fnet->CanMove( desDir, curChamber ) ) {
                                    curChamber->RegisterTileEntityInTile( player, tx, ty );
                                    player->MoveWithAnimation( desDir, 36, PlayerEntity::MOVE::PUSH );
                                    fnet->Move( desDir, curChamber );
                                } else if ( pushable->IsInMotion() && pushable->GetCurrentMotion()->GetDir() == player->GetDir() ) {
                                    // the pushable is moving and it is moving the same direction we want to go

                                    Motion * mot = pushable->GetCurrentMotion();
                                    int ticksLeftInMove = mot->GetTotalMotionTime();
                                    int moveSpeed = (ticksLeftInMove > 24 ? ticksLeftInMove : 24);

                                    // move the player
                                    curChamber->RegisterTileEntityInTile( player, tx, ty );
                                    player->MoveWithAnimation( desDir, moveSpeed, PlayerEntity::MOVE::WALK );

                                } else {
                                    switch ( desDir ) {
                                        case ( UTIL::DIR_NORTH ): player->PlayAnimation( "tryPushNorth" ); break;
                                        case ( UTIL::DIR_EAST ):  player->PlayAnimation( "tryPushEast" );  break;
                                        case ( UTIL::DIR_SOUTH ): player->PlayAnimation( "tryPushSouth" ); break;
                                        case ( UTIL::DIR_WEST ):  player->PlayAnimation( "tryPushWest" );  break;
                                    }
                                }

                            } else {
                                // handle pushing a single tile entity
                                if ( pushable->CanMove( desDir, curChamber ) ) { //if we can push through into next space
                                    curChamber->RegisterTileEntityInTile( player, tx, ty );
                                    player->MoveWithAnimation( desDir, 36, PlayerEntity::MOVE::PUSH );
                                    curChamber->RegisterTileEntityInTile( pushable, tx + dx, ty + dy );
                                    pushable->MoveDir( desDir, 36 );
                                }  else if ( pushable->IsInMotion() && pushable->GetCurrentMotion()->GetDir() == player->GetDir() ) {
                                    // the pushable is moving and it is moving the same direction we want to go

                                    Motion * mot = pushable->GetCurrentMotion();
                                    int ticksLeftInMove = mot->GetTotalMotionTime();
                                    int moveSpeed = min( 36, ticksLeftInMove );

                                    // move the player
                                    curChamber->RegisterTileEntityInTile( player, tx, ty );
                                    player->MoveWithAnimation( desDir, moveSpeed, PlayerEntity::MOVE::WALK );

                                } else {
                                    switch ( desDir ) {
                                        case ( UTIL::DIR_NORTH ): player->PlayAnimation( "tryPushNorth" ); break;
                                        case ( UTIL::DIR_EAST ):  player->PlayAnimation( "tryPushEast" );  break;
                                        case ( UTIL::DIR_SOUTH ): player->PlayAnimation( "tryPushSouth" ); break;
                                        case ( UTIL::DIR_WEST ):  player->PlayAnimation( "tryPushWest" );  break;
                                    }
                                }
                                
                            }
                        }
                    }
			    }

		    }
        }

		player->Update();
	}

	curChamber->Update();

}
开发者ID:tawheeler,项目名称:learn-cpp-01,代码行数:101,代码来源:MainScreen.cpp


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