Пример #1
0
// 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
0
// 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
0
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
0
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
0
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
0
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
0
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
0
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
0
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
0
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
0
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
0
// A debugging function that can be used to make a particular hexagon
// dense.
void HexGrid::addDenseHexagon(int x, int y)
{
    Hexagon *h = getHexagon(x, y);
    if (!h->dense())
    {
        h->setCount(m_dense_limit);
        h->setDense();
        m_miny = std::min(m_miny, h->y() - 1);
        if (h->possibleRoot())
            m_pos_roots.insert(h);
        markNeighborBelow(h);
    }
}
Пример #13
0
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);
        }
    }
}
Пример #14
0
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);
        }
    }
}
Пример #15
0
float Hexagon::Distance (const Hexagon& h) const
{
    return max (max (abs (q - h.q), abs (r - h.r)), abs (y() - h.y()));
}