本文整理汇总了C++中CGameObject::GetWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ CGameObject::GetWidth方法的具体用法?C++ CGameObject::GetWidth怎么用?C++ CGameObject::GetWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGameObject
的用法示例。
在下文中一共展示了CGameObject::GetWidth方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetupGameState
//-----------------------------------------------------------------------------
// Name : SetupGameState ()
// Desc : Sets up all the initial states required by the game.
//-----------------------------------------------------------------------------
void CGameApp::SetupGameState()
{
Vec2 brickPos;
brickPos.x = START_BRICK_POS_X;
brickPos.y = START_BRICK_POS_Y;
nrBricks = 0;
m_pPlayer.lock()->Init(Vec2((int)m_nViewWidth / 2, (int)m_nViewHeight - m_pPlayer.lock()->GetHeight()));
m_pBall.lock()->Init(Vec2((int)m_nViewWidth / 2, (int)m_nViewHeight - m_pPlayer.lock()->GetHeight() - m_pBall.lock()->GetHeight() - ONE));
for(auto it = m_vGameObjects.begin(); it != m_vGameObjects.end(); ++it)
{
CGameObject * pGameObj = it->get();
if(pGameObj->GetObjectType() == GOT_Brick)
{
for(std::size_t levelbricks = 0; levelbricks < level.bricks.size(); levelbricks++)
{
if(level.bricks[nrBricks] == '-')
{
brickPos.x += pGameObj->GetWidth();
if(brickPos.x >= m_nViewWidth - GET_MAX_BRICK_POS_X)
{
brickPos.x = START_BRICK_POS_X;
brickPos.y += pGameObj->GetHeight();
}
}
else
{
nrBricks++;
break;
}
nrBricks++;
}
pGameObj->Init(Vec2(brickPos.x, brickPos.y));
brickPos.x += pGameObj->GetWidth();
if(brickPos.x >= m_nViewWidth - GET_MAX_BRICK_POS_X)
{
brickPos.x = START_BRICK_POS_X;
brickPos.y += pGameObj->GetHeight();
}
}
}
}
示例2: 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)
//.........这里部分代码省略.........
示例3: FrameAdvance
//.........这里部分代码省略.........
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)
{
ShrinkBar = false;
m_pPlayer.lock()->Normal_Bar();
}
nrLevel++;
level.LoadBricks(nrLevel);
level.RandomBricks("-ud");
string::iterator it;
for(it = level.bricks.begin(); it < level.bricks.end(); it++)
{
if(*it == '-')
{
continue;
}
auto pBrick = std::make_shared<Brick>(*it);
m_vGameObjects.push_back(pBrick);
}
for(auto it = m_vGameObjects.begin(); it != m_vGameObjects.end(); ++it)
{
CGameObject * pGameObj = it->get();
if(pGameObj->GetObjectType() == GOT_Brick)
{
for(std::size_t levelbricks = 0; levelbricks < level.bricks.size(); levelbricks++)
{
if(level.bricks[nrBricks] == '-')
{
brickPos.x += pGameObj->GetWidth();
if(brickPos.x >= m_nViewWidth - GET_MAX_BRICK_POS_X)
{
brickPos.x = START_BRICK_POS_X;
brickPos.y += pGameObj->GetHeight();
}
}
else
{
nrBricks++;
break;
}
nrBricks++;
}
pGameObj->Init(Vec2(brickPos.x, brickPos.y));
brickPos.x += pGameObj->GetWidth();
if(brickPos.x >= m_nViewWidth - GET_MAX_BRICK_POS_X)
{
brickPos.x = START_BRICK_POS_X;
brickPos.y += pGameObj->GetHeight();
}
}
}
if(level.Winner == true)
{
LevelChange = false;
}
else
{
LevelChange = true;
}
}
// Animate the game objects
AnimateObjects();
}
// Drawing the game objects
DrawObjects();
}