本文整理汇总了C++中Hexagon类的典型用法代码示例。如果您正苦于以下问题:C++ Hexagon类的具体用法?C++ Hexagon怎么用?C++ Hexagon使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Hexagon类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updatePlayer
// Updates the player and checks if the player is in a safe zone.
void Territory::updatePlayer(UpdateInfo info, Controls * controls)
{
player->update(info, controls);
player->setIsInSafeZone(false);
// Check if the player is in a safe zone.
for (int i = 0; i < 6 && !player->getIsInSafeZone(); i++)
{
for (int j = 0; j < safeZonesTiles[i].size(); j++)
{
Hexagon * tile = safeZonesTiles[i][j];
if (Collision::hitBoxesOverlap(tile->getBoundingBox(), Vector2f(), player->getBoundingBox(), player->getSpeed()))
{
std::list<Vector2f> penetration;
if (SAT::collides(player->getConvexHull(), tile->getConvexHull(), player->getSpeed(), penetration))
{
player->setIsInSafeZone(true);
player->setSafeZoneIndex(i);
break;
}
}
}
}
}
示例2: collideBorderTiles
// Caution: Can possibly deactivate this territory and activate another.
void Territory::collideBorderTiles()
{
for (int i = 0; i < borderCoordinates.size(); i++)
{
Hexagon * tile = floorTiles[borderCoordinates[i].q][borderCoordinates[i].r];
if (Collision::hitBoxesOverlap(tile->getBoundingBox(), player->getBoundingBox(), player->getSpeed()))
{
std::list<Vector2f> penetration;
if (SAT::collides(player->getConvexHull(), tile->getConvexHull(), player->getSpeed(), penetration))
{
// Move the player into another territory if the player is in a safe zone.
if (player->getIsInSafeZone())
{
Vector2f direction = Vector2fMath::unitVector(player->getPosition() - position);
Vector2f seekPosition = position + (direction * radius * 1.1f);
world->changeTerritory(seekPosition);
break;
}
else
{
player->translate(SAT::getShortestPenetration(penetration));
}
}
}
}
}
示例3: getHexagon
void HexGrid::markNeighborBelow(Hexagon *h)
{
Coord c = h->neighborCoord(3);
Hexagon *neighbor = getHexagon(c);
neighbor->setDenseNeighbor(0);
if (neighbor->dense() && !neighbor->possibleRoot())
m_pos_roots.erase(neighbor);
}
示例4: ccTouchBegan
bool HelloWorld::ccTouchBegan (CCTouch *pTouch, CCEvent *pEvent)
{
Hexagon h = line.CCP2Hex (this->convertTouchToNodeSpace (pTouch));
h.color = ccc4f (1, 0, 1, 1);
h.Integerlize();
line.hexagones.push_back (h);
return true;
}
示例5: ccTouchMoved
void HelloWorld::ccTouchMoved (CCTouch *pTouch, CCEvent *pEvent)
{
line.hexagones.erase (line.hexagones.begin() + 1, line.hexagones.end());
Hexagon h = field.CCP2Hex (this->convertTouchToNodeSpace (pTouch));
h.Integerlize();
line.MakeLine (line.hexagones[0], h, ccc4f (1, 0.5, 0.5, 1));
intersection.hexagones.clear();
intersection.MakeSolidHex (3, h, ccc4f (1, 1, 1, 1));
}
示例6: Towards
Hexagon Hexagon::Towards (const Hexagon& target) const
{
Hexagon dir = target - *this;
dir.Round();
dir.Normalize();
/* for (int i = 0; i < eDirection::COUNT; ++i)
{
if (dir == s_directions[i])
return eDirection (i);
}*/
return dir;
}
示例7: shakeAround
void TroopsMover::shakeAround(const Hexagon *hex, int strength)
{
const float dt = 0.75f;
// Shake around
for(int side = 0; side < HexSidesCount; ++side){
Hexagon* h = Game::current().getBoard()->sideHexAt((HexSide)side, hex->getXCoord(), hex->getYCoord());
if(h){
h->shake(dt, strength);
}
}
// shake all
//Game::current().getBoard()->runAction(CCEaseIn::create(CCShake::actionWithDuration(dt, strength), dt));
}
示例8: ccc4f
void BeeHive::MakeLine (const Hexagon& start, const Hexagon& end, vector<Hexagon>& line, ccColor4F color /*= ccc4f(1, 1, 1, 1)*/)
{
float N = start.Distance (end);
if (N==0)return;
for (int i = 0; i <= N; ++i)
{
Hexagon h = (start * (1 - i / N) + end * i / N).Round();
h.color = color;
line.push_back (h);
}
}
示例9: while
void HexGrid::findParentPath(Path *p)
{
Segment s = p->rootSegment();
Hexagon *h = s.hex();
int y = h->y();
while (y >= m_miny)
{
HexPathMap::iterator it = m_hex_paths.find(h);
if (it != m_hex_paths.end())
{
Path *parentPath = it->second;
if (parentPath == p->parent())
{
p->setParent(NULL);
}
else if (!p->parent() && parentPath != p)
{
p->setParent(parentPath);
}
}
h = getHexagon(h->x(), --y);
}
}
示例10: while
std::vector<Hexagon*> HexagonGrid::findPath(Hexagon* from, Hexagon* to)
{
Hexagon* current = 0;
std::vector<Hexagon*> result;
std::priority_queue<Hexagon*, std::vector<Hexagon*>, HeuristicComparsion> unvisited;
unsigned int cameFrom[200*200] = {};
unsigned int costSoFar[200*200] = {};
// if we can't go to the location
// @todo remove when path will have lenght restriction
if (!to->canWalkThru()) return result;
unvisited.push(from);
cameFrom[from->number()] = 0;
costSoFar[from->number()] = 0;
while (!unvisited.empty())
{
current = unvisited.top(); unvisited.pop();
if (current == to) break;
// search limit
if (costSoFar[current->number()] >= 100) break;
for (Hexagon* neighbor : *current->neighbors())
{
if (!neighbor->canWalkThru()) continue;
unsigned int newCost = costSoFar[current->number()] + 1;
if (!costSoFar[neighbor->number()] || newCost < costSoFar[neighbor->number()])
{
costSoFar[neighbor->number()] = newCost;
neighbor->setHeuristic(distance(neighbor, to) + newCost);
unvisited.push(neighbor);
cameFrom[neighbor->number()] = current->number();
}
}
}
// found nothing
if (current != to) return result;
while (current->number() != from->number())
{
result.push_back(current);
current = _hexagons.at(cameFrom[current->number()]);
}
return result;
}
示例11: moveTroops
void TroopsMover::moveTroops(Army* army, Hexagon* endHex)
{
// used for achievements and shake
const int armySize = army->getTroopsCount();
const int endHexArmySize = endHex->getTroopsCount();
Hexagon* startHex = army->getCurrentHex();
const int troops = army->getTroopsCount();
startHex->removeArmy(army);
if(troops == 0){
army->free();
return;
}
if(endHex->getOwner() == startHex->getOwner()){
endHex->addArmy(army);
}else{
AttackResult attackResult = getAttackResult(army, endHex);
updateAchievements(army->getCurrentHex()->getOwner(), attackResult, armySize, endHexArmySize, endHex);
handleAttackResult(attackResult, army, startHex, endHex);
if(attackResult == DefenderWins){
if(endHex->getOwner()) EffectPlayer::playAttackEffect();
}
checkAndShake(armySize, endHexArmySize, endHex);
}
if((endHex->getTroopsCount() > 0) && (startHex != endHex)){
endHex->runScaleAction();
}
}
示例12: findHexagon
void HexGrid::addPoint(Point p)
{
Hexagon *h = findHexagon(p);
if (!h->dense())
{
h->increment();
if (dense(h))
{
h->setDense();
m_miny = std::min(m_miny, h->y() - 1);
if (h->possibleRoot())
{
m_pos_roots.insert(h);
}
markNeighborBelow(h);
}
}
}
示例13: processSample
void HexGrid::addPoint(Point p)
{
if (m_width < 0)
{
m_sample.push_back(p);
if (m_sample.size() >= m_maxSample)
processSample();
return;
}
Hexagon *h = findHexagon(p);
h->increment();
if (!h->dense())
{
if (dense(h))
{
h->setDense();
m_miny = std::min(m_miny, h->y() - 1);
if (h->possibleRoot())
m_pos_roots.insert(h);
markNeighborBelow(h);
}
}
}
示例14: Distance
float Hexagon::Distance (const Hexagon& h) const
{
return max (max (abs (q - h.q), abs (r - h.r)), abs (y() - h.y()));
}