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


C++ CGameObject::GetObjectTypeSub方法代码示例

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


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

示例1: CollisionDetection

//-----------------------------------------------------------------------------
// Name : CollisionDetection () (Private)
// Desc : Detects and handles collision
//-----------------------------------------------------------------------------
void CGameApp::CollisionDetection()
{
	HDC hdc = m_pBBuffer->getDC();

	// collision detection with the main frame
	for(auto it = m_vGameObjects.begin(); it != m_vGameObjects.end(); ++it)
	{
		CGameObject * pGameObj = it->get();
		Vec2 pos = pGameObj->myPosition;

		if(pGameObj->GetObjectTypeSub() == GOT_BrickNormal || pGameObj->GetObjectTypeSub() == GOT_BrickDouble || pGameObj->GetObjectTypeSub() == GOT_BrickGift)
		{
			BricksExist = true;
		}

		pGameObj->myCollisionSide = CS_None;

		// check collision for ball and player with wall
		if(pGameObj->GetObjectType() == GOT_Ball || pGameObj->GetObjectType() == GOT_Player)
		{
			int dx = (int)pos.x - pGameObj->GetWidth() / 2;
			if( dx < 0 )
			{
				pGameObj->myCollisionSide |= CS_Left;

				if(pGameObj->GetObjectType() == GOT_Ball)
				{
					m_pBall.lock()->myVelocity.x = -m_pBall.lock()->myVelocity.x;
				}

				if(pGameObj->GetObjectType() == GOT_Player)
				{
					pGameObj->myPosition.x = pGameObj->GetWidth()/2;
					if(FollowPlayer == true)
					{
						m_pBall.lock()->myPosition.x = ballPos.x + pGameObj->myPosition.x;
					}
				}
			}

			dx = (int)pos.x - (m_nViewWidth - pGameObj->GetWidth() / 2);
			if( dx > 0 )
			{
				pGameObj->myCollisionSide |= CS_Right;

				if(pGameObj->GetObjectType() == GOT_Ball)
				{
					m_pBall.lock()->myVelocity.x = -m_pBall.lock()->myVelocity.x;
				}

				if(pGameObj->GetObjectType() == GOT_Player)
				{
					pGameObj->myPosition.x = m_nViewWidth - pGameObj->GetWidth() / 2;
					if(FollowPlayer == true)
					{
						m_pBall.lock()->myPosition.x = ballPos.x + pGameObj->myPosition.x;
					}
				}
			}

			int dy = (int)pos.y - pGameObj->GetHeight() / 2;
			if( dy < 0 )
			{
				pGameObj->myCollisionSide |= CS_Top;
				if(pGameObj->GetObjectType() == GOT_Ball)
				{
					m_pBall.lock()->myVelocity.y = -m_pBall.lock()->myVelocity.y;
				}
			}

			dy = (int)pos.y - (m_nViewHeight - pGameObj->GetHeight() / 2);
			if( dy > 0 )
			{
				pGameObj->myCollisionSide |= CS_Bottom;
				if(pGameObj->GetObjectType() == GOT_Ball)
				{
					m_pBall.lock()->myVelocity.y = -m_pBall.lock()->myVelocity.y;
				}
			}

		}

		// check ball collision with game objects
		if(pGameObj->GetObjectType() == GOT_Ball)
			for(auto it2 = m_vGameObjects.begin(); it2 != m_vGameObjects.end(); ++it2)
			{
				CGameObject * pGameObj2 = it2->get();
				Vec2 pos2 = pGameObj2->myPosition;


				if(pGameObj->GetObjectType() == pGameObj2->GetObjectType())
					continue;
				if(pGameObj2->GetObjectType() == GOT_Player || pGameObj2->GetObjectType() == GOT_Brick)
				{

					if(pGameObj2->GetObjectType() == GOT_Player)
//.........这里部分代码省略.........
开发者ID:cifrajanos,项目名称:GameFramework,代码行数:101,代码来源:CGameApp.cpp

示例2: FrameAdvance

//-----------------------------------------------------------------------------
// Name : FrameAdvance () (Private)
// Desc : Called to signal that we are now rendering the next frame.
//-----------------------------------------------------------------------------
void CGameApp::FrameAdvance()
{
	static TCHAR FrameRate[ 50 ];
	static TCHAR TitleBuffer[ 255 ];

	// Advance the timer
	m_Timer.Tick( 60 );

	// Skip if app is inactive
	if ( !m_bActive ) return;

	// Get / Display the framerate
	if ( m_LastFrameRate != m_Timer.GetFrameRate() )
	{
		m_LastFrameRate = m_Timer.GetFrameRate( FrameRate, 50 );
		sprintf_s( TitleBuffer, _T("Game : %s"), FrameRate );
		SetWindowText( m_hWnd, TitleBuffer );
	} // End if Frame Rate Altered

	if(StartGame == true)
	{

		SetCursor( NULL );

		// Poll & Process input devices
		ProcessInput();

		// Collision detection between game objects
		BricksExist=false;
		CollisionDetection();
		if(BricksExist == false)
		{
			Vec2 brickPos;
			brickPos.x = START_BRICK_POS_X;
			brickPos.y = START_BRICK_POS_Y;

			countBricks = 0;
			countGifts = 0;
			nrBricks = 0;

			// delete objects from previous level
			for(auto it = m_vGameObjects.begin(); it != m_vGameObjects.end(); ++it)
			{
				CGameObject * pGameObj = it->get();

				if(pGameObj->GetObjectTypeSub() == GOT_BrickUnbreakable)
				{
					countBricks++;
				}
			}

			for(int cBricks = 0; cBricks <= countBricks; cBricks++)
			{
				for(auto it2 = m_vGameObjects.begin(); it2 != m_vGameObjects.end(); ++it2)
				{
					CGameObject * pGameObj = it2->get();
					if(pGameObj->GetObjectTypeSub() == GOT_BrickUnbreakable)
					{
						m_vGameObjects.erase(it2);
						break;
					}
				}
			}

			for(auto it = m_vGameObjectsGift.begin(); it != m_vGameObjectsGift.end(); ++it)
			{
				CGameObject * pGameObj = it->get();

				countGifts++;

			}

			for(int cGifts = 0; cGifts <= countGifts; cGifts++)
			{
				for(auto it2 = m_vGameObjectsGift.begin(); it2 != m_vGameObjectsGift.end(); ++it2)
				{
					CGameObject * pGameObj = it2->get();

					m_vGameObjectsGift.erase(it2);
					break;

				}
			}

			// load new objects
			m_pBall.lock()->myVelocity.x = 0;
			m_pBall.lock()->myVelocity.y = 0;
			m_pBall.lock()->myPosition.x = m_pPlayer.lock()->myPosition.x;
			m_pBall.lock()->myPosition.y = m_nViewHeight - m_pBall.lock()->GetHeight() - m_pPlayer.lock()->GetHeight() - ONE;
			FollowPlayer = true;
			UnstoppableBall = false;
			StickyBar = false;
			MoveBall = false;
			SystemParametersInfo(SPI_SETMOUSESPEED, NULL, (void*)10, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE );
			ballPos.x = 0;
			if(ShrinkBar == true)
//.........这里部分代码省略.........
开发者ID:cifrajanos,项目名称:GameFramework,代码行数:101,代码来源:CGameApp.cpp


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