本文整理汇总了C++中Snake::getLength方法的典型用法代码示例。如果您正苦于以下问题:C++ Snake::getLength方法的具体用法?C++ Snake::getLength怎么用?C++ Snake::getLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Snake
的用法示例。
在下文中一共展示了Snake::getLength方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addFood
void ItemFactory::addFood()
{
//check if the food still exist
if (m_pFood)
return;
//check the empty grid
Snake* snake = dynamic_cast<Snake*>(getParent()->getChildByTag(eID_Snake));
if (!snake)
return;
int left = m_pSnakeMap->getMovableNumbers() - snake->getLength();
//no empty grids left, you win
if (left <= 0)
return;
//set the food index
int index = (int)(rand() % left + 1);
auto mapIndex = m_pSnakeMap->getEmptyGridIndex(index);
//create food model
m_pFood = Food::create();
this->addChild(m_pFood, 1, eID_Food);
m_pFood->setPosition(VisibleRect::getVisibleRect().origin + VisibleRect::getHalfGridVec() + VisibleRect::getGridLength()*mapIndex);
m_pFood->setIndex(mapIndex);
//set the grid type
m_pSnakeMap->setGridType(mapIndex, eType_Food);
}
示例2: addDoor
void ItemFactory::addDoor()
{
//check if the doors exist
if (m_pDoors.first != nullptr || m_pDoors.second != nullptr)
return;
//check the empty grid
Snake* snake = m_pSnakeMap->getSnake();
if (!snake)
return;
int left = m_pSnakeMap->getMovableNumbers() - snake->getLength();
//no empty grids left
if (left <= 0)
return;
//set the door index
int index = (int)(rand() % left + 1);
auto mapIndex = m_pSnakeMap->getEmptyGridIndex(index);
//create door model
m_pDoors.first = Door::create();
this->addChild(m_pDoors.first, 1, eID_Door1);
m_pDoors.first->setPosition(VisibleRect::getVisibleRect().origin + VisibleRect::getHalfGridVec() + VisibleRect::getGridLength()*mapIndex);
m_pDoors.first->setIndex(mapIndex);
//set the door transfer direction
auto transferDir = randomDirection();
m_pDoors.first->setTransferDirection(transferDir);
//actual door direction is opposite to transfer direction
m_pDoors.first->setRotation(arcByDirection(oppositeDirection(transferDir)));
//set the grid type
m_pSnakeMap->setGridType(mapIndex, eType_Door);
//create the second door
index = (int)(rand() % left + 1);
mapIndex = m_pSnakeMap->getEmptyGridIndex(index);
m_pDoors.second = Door::create();
this->addChild(m_pDoors.second, 1, eID_Door2);
m_pDoors.second->setPosition(VisibleRect::getVisibleRect().origin + VisibleRect::getHalfGridVec() + VisibleRect::getGridLength()*mapIndex);
m_pDoors.second->setIndex(mapIndex);
transferDir = randomDirection();
m_pDoors.second->setTransferDirection(transferDir);
m_pDoors.second->setRotation(arcByDirection(oppositeDirection(transferDir)));
m_pSnakeMap->setGridType(mapIndex, eType_Door);
//connect the two doors
m_pDoors.first->setOtherDoor(m_pDoors.second);
m_pDoors.second->setOtherDoor(m_pDoors.first);
}
示例3: addBall
void ItemFactory::addBall(float dt)
{
//check if the ball exist
if (m_pBall)
return;
//check if the random time has finished
if (m_fTimeToAddBall > 0)
{
m_fTimeToAddBall -= dt;
return;
}
// it's time to add ball, check the empty grid
Snake* snake = m_pSnakeMap->getSnake();
if (!snake)
return;
int left = m_pSnakeMap->getMovableNumbers() - snake->getLength();
//no empty grids left
if (left <= 0)
return;
//set the star index
int index = (int)(rand() % left + 1);
auto mapIndex = m_pSnakeMap->getEmptyGridIndex(index);
//create star model
m_pBall = Ball::create();
this->addChild(m_pBall, 1, eID_Ball);
m_pBall->setPosition(VisibleRect::getVisibleRect().origin + VisibleRect::getHalfGridVec() + VisibleRect::getGridLength()*mapIndex);
m_pBall->setIndex(mapIndex);
//add a scale animation
m_pBall->setScale(0.1f);
auto scaleBig = ScaleTo::create(0.7f, 1.2f);
auto scaleBack = ScaleTo::create(0.3f, 1.0f);
auto sequence = Sequence::create(scaleBig, scaleBack, nullptr);
m_pBall->runAction(sequence);
//set the grid type
m_pSnakeMap->setGridType(mapIndex, eType_Ball);
//set the duration from [15, 25] seconds
auto duration = rand() % 16 + 10.0f;
m_pBall->setDuration(duration);
}