Example #1
0
void ScrollViewBar::onScrolled(const Vec2& outOfBoundary)
{
    if(_autoHideEnabled)
    {
        _autoHideRemainingTime = _autoHideTime;
        ProtectedNode::setOpacity(_opacity);
    }
    
    Layout* innerContainer = _parent->getInnerContainer();
    
    float innerContainerMeasure = 0;
    float scrollViewMeasure = 0;
    float outOfBoundaryValue = 0;
    float innerContainerPosition = 0;
    if(_direction == ScrollView::Direction::VERTICAL)
    {
        innerContainerMeasure = innerContainer->getContentSize().height;
        scrollViewMeasure = _parent->getContentSize().height;
        outOfBoundaryValue = outOfBoundary.y;
        innerContainerPosition = -innerContainer->getPositionY();
    }
    else if(_direction == ScrollView::Direction::HORIZONTAL)
    {
        innerContainerMeasure = innerContainer->getContentSize().width;
        scrollViewMeasure = _parent->getContentSize().width;
        outOfBoundaryValue = outOfBoundary.x;
        innerContainerPosition = -innerContainer->getPositionX();
    }
    
    float length = calculateLength(innerContainerMeasure, scrollViewMeasure, outOfBoundaryValue);
    Vec2 position = calculatePosition(innerContainerMeasure, scrollViewMeasure, innerContainerPosition, outOfBoundaryValue, length);
    updateLength(length);
    setPosition(position);
}
Example #2
0
quint32 AbstractSshPacket::length() const
{
    //Q_ASSERT(currentDataSize() >= minPacketSize());
    if (m_length == 0)
        calculateLength();
    return m_length;
}
	void AnimationClip::setCurves(const AnimationCurves& curves)
	{
		*mCurves = curves;

		buildNameMapping();
		calculateLength();
		mVersion++;
	}
Example #4
0
void Album::printLength(){
	unsigned long length = calculateLength();
	cout << length/60 << ":";  //convert to minutes and seconds. Unnecessary, but looks nice
	if(length%60 < 10)
		cout << "0" << length%60;   //cout "0:04" instead of "0:4"
	else
		cout << length%60;
}
Example #5
0
        CubicCurve::CubicCurve(const Vector2D &start, const Vector2D &control1,
                const Vector2D &control2, const Vector2D &end)
        {
            this->start = start;
            this->control1 = control1;
            this->control2 = control2;
            this->end = end;

            calculateLength();
        }
Example #6
0
 Dubins::Dubins(State pos, bool isCCC, myFloat le1, myFloat le2, myFloat le3, myFloat rad) {
     start = pos;
     radius = rad;
     this->radius = rad;
     this->isCCC = isCCC;
     len1 = le1;
     len2 = le2;
     len3 = le3;
     calculateLength();
     end = getSecondArc().getEnd();
 }
Example #7
0
// public
void kpTool::setUserShapePoints (const QPoint &startPoint,
                                 const QPoint &endPoint,
                                 bool setSize)
{
    m_userShapeStartPoint = startPoint;
    m_userShapeEndPoint = endPoint;
    emit userShapePointsChanged (m_userShapeStartPoint, m_userShapeEndPoint);

    if (setSize)
    {
        if (startPoint != KP_INVALID_POINT &&
            endPoint != KP_INVALID_POINT)
        {
            setUserShapeSize (calculateLength (startPoint.x (), endPoint.x ()),
                              calculateLength (startPoint.y (), endPoint.y ()));
        }
        else
        {
            setUserShapeSize ();
        }
    }
}
	AnimationClip::AnimationClip(const SPtr<AnimationCurves>& curves, bool isAdditive, UINT32 sampleRate, 
		const SPtr<RootMotion>& rootMotion)
		: Resource(false), mVersion(0), mCurves(curves), mRootMotion(rootMotion), mIsAdditive(isAdditive), mLength(0.0f)
		, mSampleRate(sampleRate)
	{
		if (mCurves == nullptr)
			mCurves = bs_shared_ptr_new<AnimationCurves>();

		if (mRootMotion == nullptr)
			mRootMotion = bs_shared_ptr_new<RootMotion>();

		buildNameMapping();
		calculateLength();
	}
Example #9
0
/** switch row and column in the alignment. Use more efficient implementations in derived classes.
 */
void ImplAlignment::switchRowCol()
{

	debug_func_cerr(5);

	HAlignment copy = getClone();

	AlignmentIterator it     = copy->begin();
	AlignmentIterator it_end = copy->end();

	clear();

	// copy over residue pairs from copy reversing row and column
	for (;it != it_end; ++it)
		addPair( ResiduePair( it->mCol, it->mRow, it->mScore ) );

	setScore( copy->getScore() );
	calculateLength();
	return;
}
//--------------> mapping functions <----------------------------------------------------------------------------
Position ImplAlignmentMatrixDiagonal::mapRowToCol( Position pos, SearchType search ) const
{
    debug_func_cerr( 5 );

    if (pos >= mRowTo || pos < mRowFrom || mPairs.size() == 0)
        return NO_POS;

    if (mChangedLength) calculateLength();

    assert( mIndex[mNumDiagonals] == NODOT);

    // find the row with the smallest diagonal
    Dot ndots = mPairs.size();

    for (Position diagonal = 0; diagonal < mNumDiagonals; ++diagonal)
    {
        Dot dot = mIndex[diagonal];
        debug_cerr( 5, "diagonal=" << diagonal << " dot=" << dot );

        if (dot != NODOT)
        {
            // mIndex[mNumDiagonals] = NODOT

            Dot next_dot = mIndex[diagonal+1];

            // go along one diagonal
            while ( dot != next_dot &&
                    dot < ndots &&
                    mPairs[dot].mRow < pos)
            {
                debug_cerr( 5, "diagonal=" << diagonal << " dot=" << dot << " pair=" << mPairs[dot] );
                ++dot;
            }
            if (dot < ndots && mPairs[dot].mRow == pos)
                return mPairs[dot].mCol;
        }
    }

    return NO_POS;
}
Example #11
0
int overmindFoundResources(gameMap_t * self,
              sf::RenderWindow & window,
              selection_t * cUnit,
              sf::Sprite & aCell,
              sf::Sprite & aEnemy,
              cursor_t * gCur,
              sf::Sprite & gameBackground,
              sf::Sprite & gameInterface,
              sf::Sprite & gameMenu,
              sf::Sprite & gameEndTurn,
              int player,
              sf::Sprite & cTc,
              player_t*pl,
              sf::Sprite & cBc,int XI,int YJ,resources_t * OP){

                  int tmpWay = 10000;
                  int tmpCount;

                  for(int i = 0;i<OP->count;i++){

                        if(OP->op[i]->object->currentPlayer!=1){

                                std::string tmp;
                                self->cell[OP->op[i]->iX][OP->op[i]->jY].obj_un_null=0;
                                        tmp = pathFind(cUnit->cell->iX,cUnit->cell->jY,OP->op[i]->iX,OP->op[i]->jY,self);
                                        if(tmpWay>calculateLength(tmp)){
                                                tmpCount = i;
                                        }
                                        self->cell[OP->op[i]->iX][OP->op[i]->jY].obj_un_null=1;
                        }


                  }

                  int tmpXX1 = cUnit->cell->iX;
                  int tmpYY1 = cUnit->cell->jY;

                  int tmpXX2 = OP->op[tmpCount]->iX+1;
                  int tmpYY2 = OP->op[tmpCount]->jY+1;

                std::string tmp = pathFind(tmpXX1,tmpYY1,tmpXX2,tmpYY2,self);
                if(tmp!=""){
                    goto startMoving;
                }
                tmp = pathFind(cUnit->cell->iX,cUnit->cell->jY,OP->op[tmpCount]->iX,OP->op[tmpCount]->jY+1,self);
                if(tmp!=""){
                    goto startMoving;
                }
                tmp = pathFind(cUnit->cell->iX,cUnit->cell->jY,OP->op[tmpCount]->iX+1,OP->op[tmpCount]->jY,self);
                if(tmp!=""){
                    goto startMoving;
                }

                tmp = pathFind(cUnit->cell->iX,cUnit->cell->jY,OP->op[tmpCount]->iX+1,OP->op[tmpCount]->jY-1,self);
                if(tmp!=""){
                    goto startMoving;
                }
                tmp = pathFind(cUnit->cell->iX,cUnit->cell->jY,OP->op[tmpCount]->iX-1,OP->op[tmpCount]->jY+1,self);
                if(tmp!=""){
                    goto startMoving;
                }
                tmp = pathFind(cUnit->cell->iX,cUnit->cell->jY,OP->op[tmpCount]->iX-1,OP->op[tmpCount]->jY,self);
                if(tmp!=""){
                    goto startMoving;
                }
                tmp = pathFind(cUnit->cell->iX,cUnit->cell->jY,OP->op[tmpCount]->iX,OP->op[tmpCount]->jY-1,self);
                if(tmp!=""){
                    goto startMoving;
                }
                tmp = pathFind(cUnit->cell->iX,cUnit->cell->jY,OP->op[tmpCount]->iX-1,OP->op[tmpCount]->jY-1,self);
                if(tmp!=""){
                    goto startMoving;
                }

                return 0;
                startMoving:;

                int tmpCP;
                 int tmpInt = tmp[0] - 48;
                 if(tmpInt==0||tmpInt==2||tmpInt==4||tmpInt==6){

                                        tmpCP=-1;
                                    }else{

                                        tmpCP=-2;
                                    }

                                    if(cUnit->cell->unit->cPoints+tmpCP>=0){

                                            cUnit->cell->unit->cPoints+=tmpCP;





                //cUnit->cell->unit->direction=tmpInt;
                cUnit->cell->unit->direction = tmpInt;



                /*
                *Start move!
                */


                                   int tmpX = cUnit->cell->iX;

                                   int tmpY = cUnit->cell->jY;

                                    self->cell[tmpX][tmpY].obj_un_null=0;



                                   int tmpCX = cUnit->cell->X;
                                   int tmpCY = cUnit->cell->Y;


                                   sf::Texture tmpT;
                                   sf::Sprite tmpS;

                                   int tX = cUnit->cell->iX;
                                   int tY = cUnit->cell->jY;

                                    tmpT.loadFromFile(cUnit->cell->unit->sprites.path[cUnit->cell->unit->direction]);

                                    tmpS.setTexture(tmpT);

                                    switch(tmpInt){
                                        case 0:

                                            tX+=1;
                                             break;
                                        case 1:

                                            tX+=1;
                                            tY+=1;
                                             break;
                                        case 2:

                                             tY+=1;
                                             break;
                                        case 3:

                                             tX-=1;
                                             tY+=1;
                                             break;
                                        case 4:

                                            tX-=1;
                                             break;
                                        case 5:

                                            tX-=1;
                                            tY-=1;
                                             break;
                                        case 6:

                                             tY-=1;
                                             break;
                                        case 7:

                                              tY-=1;
                                              tX+=1;
                                             break;

                                           }



                for(int a = 0 ; a<10;a++){
                                            switch(tmpInt){
                                        case 0:
                                            tmpCX+=10;

                                             break;
                                        case 1:
                                            tmpCX+=10;
                                            tmpCY+=10;

                                             break;
                                        case 2:
                                             tmpCY+=10;

                                             break;
                                        case 3:
                                             tmpCX-=10;
                                             tmpCY+=10;

                                             break;
                                        case 4:
                                            tmpCX-=10;

                                             break;
                                        case 5:
                                            tmpCX-=10;
                                            tmpCY-=10;

                                             break;
                                        case 6:
                                             tmpCY-=10;

                                             break;
                                        case 7:
                                              tmpCY-=10;
                                              tmpCX+=10;

                                             break;

                                           }

                                            Sleep(20);

                                            window.clear(sf::Color::Black);
                                            window.draw(gameBackground);
                                            drawUnits(self,window);

                                           /* window.draw(gameInterface);
                                            window.draw(gameMenu);
                                            drawMinMap(window,player,self);
                                            window.draw(gameEndTurn);
                                            drawPlayer(window,player,pl);*/




                                            tmpS.setPosition(tmpCX,tmpCY);

                                            window.draw(tmpS);

                                            window.draw(gameInterface);
                                            window.draw(gameMenu);
                                            drawMinMap(window,player,self);
                                            window.draw(gameEndTurn);
                                            drawPlayer(window,player,pl);


                                            window.draw(cTc);
                                            window.draw(cBc);


                                            window.display();

                                    }




                                    self->cell[tX][tY].unit = self->cell[tmpX][tmpY].unit;
                                    self->cell[tX][tY].obj_un_null=1;






                                    cUnit->cell = &self->cell[tX][tY];
                                    cUnit->status = 1;

                                    int TEST = cUnit->cell->unit->cPoints;



                                    self->cell[tmpX][tmpY].unit = NULL;


                                    window.clear(sf::Color::Black);
                                            window.draw(gameBackground);
                                            drawUnits(self,window);

                                          /*  window.draw(gameInterface);
                                            window.draw(gameMenu);
                                            drawMinMap(window,player,self);
                                            window.draw(gameEndTurn);
                                            drawPlayer(window,player,pl);*/




                                            tmpS.setPosition(tmpCX,tmpCY);

                                            window.draw(tmpS);


                                            window.draw(gameInterface);
                                            window.draw(gameMenu);
                                            drawMinMap(window,player,self);
                                            window.draw(gameEndTurn);
                                            drawPlayer(window,player,pl);

                                            window.draw(cTc);
                                            window.draw(cBc);



                                            window.display();



                                    return 1;





              }
              return 0;

              }
int Recognizer::recognizeGesture()
{
	PositionList directions = simplify(limitDirections(d->positions));
	const double minimumLength = (calculateLength(directions) * d->minimumMatch);

	while (!directions.empty() && calculateLength(directions) > minimumLength)
	{
		for (unsigned int i = 0; i < d->gestures.size(); ++i)
		{
			if (d->gestures[i].size() == directions.size())
			{
				bool match = true;
				PositionList::const_iterator positionsIterator = directions.begin();

				for (ActionList::const_iterator directionsIterator = d->gestures[i].begin(); directionsIterator != d->gestures[i].end() && match; ++directionsIterator, ++positionsIterator)
				{
					switch (*directionsIterator)
					{
						case MoveUpMouseAction:
							if (positionsIterator->y >= 0)
							{
								match = false;
							}

							break;
						case MoveDownMouseAction:
							if (positionsIterator->y <= 0)
							{
								match = false;
							}

							break;
						case MoveLeftMouseAction:
							if (positionsIterator->x >= 0)
							{
								match = false;
							}

							break;
						case MoveRightMouseAction:
							if (positionsIterator->x <= 0)
							{
								match = false;
							}

							break;
						case MoveHorizontallyMouseAction:
							if (positionsIterator->x == 0)
							{
								match = false;
							}

							break;
						case MoveVerticallyMouseAction:
							if (positionsIterator->y == 0)
							{
								match = false;
							}

							break;
						default:
							match = false;

							break;
					}
				}

				if (match)
				{
					return (int) i;
				}
			}
		}

		directions = simplify(removeShortest(directions));
	}

	return -1;
}
int main()
{
    int t,n,k,*arr,a,i,x,xelement,oldElement,len,element;
    struct Node *list[11];
    struct Node *newList[11];
    scanf("%d",&t);
    while(t--)
    {
        for(i=0;i<=10;i++)
        {
            list[i]=NULL;
            newList[i]=NULL;
        }
        scanf("%d%d",&n,&k);
        arr=(int*)malloc(sizeof(int)*n);
        for(i=0;i<n;i++)
            scanf("%d",&arr[i]);
        for(i=0;i<n;i++)
        {
            a=calculateLength(arr[i]);
            list[a]=add(list[a],makeNode(arr[i]));
        }
        // Gaussian Elimination
        for(i=10;i>=0;i--)
        {
            //printf("hello lavish kothari\n");
            if(list[i])
            {
                xelement=list[i]->data;
                newList[i]=add(newList[i],makeNode(xelement));
                list[i]=removeFirst(list[i]);
                element=newList[i]->data;
                while(list[i])
                {
                    oldElement=list[i]->data;
                    list[i]=removeFirst(list[i]);
                    len=calculateLength(element^oldElement);
                    if(len>0)
                        list[len]=add(list[len],makeNode(element^oldElement));
                }
            }
        }
        x=k;

        for(i=10;i>=1;i--)
        {
            if(newList[i])
            {
                element=newList[i]->data;
                if((x^element) > x)
                    x=(x^element);
            }
        }
        printf("%d\n",x);
        for(i=0;i<=10;i++)
        {
            if(list[i])
                free(list[i]);
            if(newList[i])
                free(newList[i]);
        }
    }
    return 0;
}
void  findWay(gameMap_t * self,
              sf::RenderWindow & window,
              selection_t * cUnit,
              sf::Sprite & aCell,
              sf::Sprite & aEnemy,
              cursor_t * gCur,
              sf::Sprite & gameBackground,
              sf::Sprite & gameInterface,
              sf::Sprite & gameMenu,
              sf::Sprite & gameEndTurn,
              int player,
              sf::Sprite & cTc,
              player_t*pl,
              sf::Sprite & cBc){

    if(cUnit->status==0){
        return;
    }
    for(int i = 0;i<cellNumX;i++){
            for(int j = 0;j<cellNumY;j++){

                    int added = 0;

                    if (cUnit->cell!=NULL&&(float)sqrt((cUnit->cell->iX-i)*(cUnit->cell->iX-i)+(cUnit->cell->jY-j)*(cUnit->cell->jY-j)) <=  (float)(cUnit->cell->unit->cPoints) || (float)sqrt((cUnit->cell->iX-i)*(cUnit->cell->iX-i)+(cUnit->cell->jY-j)*(cUnit->cell->jY-j)) <=  (float)(cUnit->cell->unit->aRange)) {

                    std::string tmp;

                    int tmpSt = self->cell[i][j].obj_un_null;



                    if(self->cell[i][j].unit!=NULL && self->cell[i][j].unit->player  !=  cUnit->cell->unit->player && self->cell[i][j].obj_un_null == 1)
                        {
                            self->cell[i][j].obj_un_null = 0;
                            tmpSt = 1;
                        }


                    tmp = pathFind(cUnit->cell->iX,cUnit->cell->jY,i,j,self);

                    if(tmp!="" && calculateLength(tmp)<=cUnit->cell->unit->cPoints){



                         aCell.setPosition(self->cell[i][j].X,self->cell[i][j].Y);
                         window.draw(aCell);

                          if(gCur->status==1&&gCur->cell->iX == i &&gCur->cell->jY == j && tmp!=""&& self->cell[gCur->cell->iX][gCur->cell->jY].unit == NULL){

                                if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){

                                    cUnit->cell->unit->cPoints-=calculateLength(tmp);

                                    int tmpInt = tmp[0] - 48;

                                    cUnit->cell->unit->direction=tmpInt;

                                    int tmpX = 0, tmpY = 0;

                                    cUnit->cell->unit->direction = tmpInt;


                                    tmpX = cUnit->cell->iX;

                                    tmpY = cUnit->cell->jY;

                                    self->cell[tmpX][tmpY].obj_un_null=0;

                                   int tmpCX = cUnit->cell->X;
                                   int tmpCY = cUnit->cell->Y;


                                    for(int l = 0;l<tmp.length();l++){

                                    int tmpD = tmp[l] - 48;

                                    cUnit->cell->unit->direction = tmpD;

                                    sf::Texture tmpT;
                                    sf::Sprite tmpS;


                                    tmpT.loadFromFile(cUnit->cell->unit->sprites.path[cUnit->cell->unit->direction]);
                                    tmpS.setTexture(tmpT);

                                    for(int a = 0 ; a<10;a++){
                                            switch(tmpD){
                                        case 0:
                                            tmpCX+=10;
                                             break;
                                        case 1:
                                            tmpCX+=10;
                                            tmpCY+=10;
                                             break;
                                        case 2:
                                             tmpCY+=10;
                                             break;
                                        case 3:
                                             tmpCX-=10;
                                             tmpCY+=10;
                                             break;
                                        case 4:
                                            tmpCX-=10;
                                             break;
                                        case 5:
                                            tmpCX-=10;
                                            tmpCY-=10;
                                             break;
                                        case 6:
                                             tmpCY-=10;
                                             break;
                                        case 7:
                                             tmpCY-=10;
                                              tmpCX+=10;
                                             break;

                                           }

                                            Sleep(20);

                                            window.clear(sf::Color::Black);
                                            window.draw(gameBackground);
                                            drawUnits(self,window);
/*
                                            window.draw(gameInterface);
                                            window.draw(gameMenu);
                                            drawMinMap(window,player,self);
                                            window.draw(gameEndTurn);
                                            drawPlayer(window,player,pl);*/




                                            tmpS.setPosition(tmpCX,tmpCY);

                                            window.draw(tmpS);

                                            window.draw(gameInterface);
                                            window.draw(gameMenu);
                                            drawMinMap(window,player,self);
                                            window.draw(gameEndTurn);
                                            drawPlayer(window,player,pl);



                                            window.draw(cTc);
                                             window.draw(cBc);
                                            pData(window,cUnit);


                                            window.display();

                                    }




                                    }

                                    self->cell[gCur->cell->iX][gCur->cell->jY].unit = cUnit->cell->unit;
                                    self->cell[gCur->cell->iX][gCur->cell->jY].obj_un_null=1;
                                    added = 1;




                                    setSelect(&self->cell[gCur->cell->iX][gCur->cell->jY],cUnit);

                                    self->cell[tmpX][tmpY].unit = NULL;



                                }
                            }



                   }

                    if(tmpSt == 1 && tmp!="" && calculateLength(tmp)<=cUnit->cell->unit->aRange&&cUnit->cell->unit->cPoints>0){


                         aEnemy.setPosition(self->cell[i][j].X,self->cell[i][j].Y);
                         window.draw(aEnemy);

                         if(gCur->status==1&&gCur->cell->iX == i &&gCur->cell->jY == j&& self->cell[gCur->cell->iX][gCur->cell->jY].unit != NULL && cUnit->cell->unit->player!=self->cell[i][j].unit->player){

                                if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){

                                        if(added!=1){
                                        self->cell[i][j].obj_un_null = tmpSt;
                                        }

                                        int tmpD = tmp[0] - 48;
                                        cUnit->cell->unit->direction = tmpD;

                                            window.clear(sf::Color::Black);
                                            window.draw(gameBackground);

                                            drawUnits(self,window);


                                        sf::Texture tmpT;
                                        sf::Sprite tmpS;
                                        tmpT.loadFromFile(self->cell[i][j].unit->sprites.path[10]);
                                        tmpS.setTexture(tmpT);
                                        tmpS.setPosition(self->cell[i][j].X + rand()%50+20,self->cell[i][j].Y + rand()%50+20);
                                        window.draw(tmpS);


                                        window.draw(gameInterface);
                                            window.draw(gameMenu);
                                            drawMinMap(window,player,self);
                                            window.draw(gameEndTurn);
                                            drawPlayer(window,player,pl);
                                            pData(window,cUnit);


                                        sf::Texture tmpT1;
                                        sf::Sprite tmpS1;



                                       tmpT1.loadFromFile(self->cell[i][j].unit->sprites.path[11+cUnit->cell->unit->direction]);


                                        tmpS1.setTexture(tmpT1);
                                        tmpS1.setPosition(cUnit->cell->X,cUnit->cell->Y);


                                        window.draw(tmpS1);
                                        window.display();
                                        Sleep(400);


                                      cUnit->cell->unit->cPoints-=1;
                                      int tmpDmg = cUnit->cell->unit->dmg -  self->cell[i][j].unit->armor;
                                      if(tmpDmg<0){tmpDmg=0;}
                                      self->cell[i][j].unit->hp-=tmpDmg;


                                      if(self->cell[i][j].unit->hp<=0){

                                        sf::Texture tmpT;
                                        sf::Sprite tmpS;


                                        tmpT.loadFromFile(self->cell[i][j].unit->sprites.path[8]);
                                        tmpS.setTexture(tmpT);
                                        tmpS.setPosition(self->cell[i][j].X,self->cell[i][j].Y);



                                            window.clear(sf::Color::Black);
                                            window.draw(gameBackground);
                                            drawUnits(self,window);

                                            window.draw(gameInterface);
                                            window.draw(gameMenu);
                                            drawMinMap(window,player,self);
                                            window.draw(gameEndTurn);
                                            drawPlayer(window,player,pl);

                                            pData(window,cUnit);
                                            window.draw(cBc);
                                            window.draw(tmpS);




                                        window.display();
                                        Sleep(400);

                                        deleteUnit(self->cell[i][j].unit);
                                        self->cell[i][j].unit = NULL;
                                        self->cell[i][j].obj_un_null = 0;
                                        return;
                                      }
                               }
                         }
                   }

                   if(added!=1){

                   self->cell[i][j].obj_un_null = tmpSt;
                   }
                 }
            }
        }
}
Example #15
0
int overmindAttack(gameMap_t * self,
              sf::RenderWindow & window,
              selection_t * cUnit,sf::Sprite & aCell,
              sf::Sprite & aEnemy,
              cursor_t * gCur,
              sf::Sprite & gameBackground,
              sf::Sprite & gameInterface,
              sf::Sprite & gameMenu,
              sf::Sprite & gameEndTurn,
              int player,
              sf::Sprite & cTc,
              player_t*pl,
              sf::Sprite & cBc
              //,
              //int XI,
              //int YJ
              ){

                   for(int i = 0;i<cellNumX;i++){
                        for(int j = 0;j<cellNumY;j++){
                                if(cUnit->cell==NULL){
                                    return 0;
                                }

                            if ((float)sqrt((cUnit->cell->iX-i)*(cUnit->cell->iX-i)+(cUnit->cell->jY-j)*(cUnit->cell->jY-j)) <=  (float)(cUnit->cell->unit->aRange)) {

                                   std::string tmp;

                            if(self->cell[i][j].unit!=NULL && self->cell[i][j].unit->player  !=  1 && self->cell[i][j].obj_un_null == 1)
                                {
                                    self->cell[i][j].obj_un_null = 0;
                                    std::string tmp;
                                    tmp = pathFind(cUnit->cell->iX,cUnit->cell->jY,i,j,self);

                                    if(tmp!="" && calculateLength(tmp) <= cUnit->cell->unit->aRange && cUnit->cell->unit->cPoints>0){


                                            int tmpD = tmp[0] - 48;

                                            self->cell[i][j].obj_un_null = 1;
                                            cUnit->cell->unit->direction = tmpD;

                                            window.clear(sf::Color::Black);
                                            window.draw(gameBackground);

                                            drawUnits(self,window);

                                            window.draw(gameInterface);
                                            window.draw(gameMenu);
                                            drawMinMap(window,player,self);
                                            window.draw(gameEndTurn);

                                            drawPlayer(window,1,pl);

                                            //pData(window,cUnit);



                                        sf::Texture tmpT;
                                        sf::Sprite tmpS;
                                        tmpT.loadFromFile(self->cell[i][j].unit->sprites.path[10]);
                                        tmpS.setTexture(tmpT);
                                        tmpS.setPosition(self->cell[i][j].X + rand()%50+20,self->cell[i][j].Y + rand()%50+20);
                                        window.draw(tmpS);

                                        sf::Texture tmpT1;
                                        sf::Sprite tmpS1;



                                       tmpT1.loadFromFile(self->cell[i][j].unit->sprites.path[11+self->cell[i][j].unit->direction]);


                                        tmpS1.setTexture(tmpT1);
                                        tmpS1.setPosition(self->cell[i][j].X,self->cell[i][j].Y);


                                        window.draw(tmpS1);
                                        window.display();
                                          Sleep(400);


                                      cUnit->cell->unit->cPoints-=1;


                                      int tmpDmg = cUnit->cell->unit->dmg -  self->cell[i][j].unit->armor;


                                      if(tmpDmg<0){tmpDmg=0;}

                                      self->cell[i][j].unit->hp-=tmpDmg;

                                       if(self->cell[i][j].unit->hp<=0){

                                        sf::Texture tmpT;
                                        sf::Sprite tmpS;


                                        tmpT.loadFromFile(self->cell[i][j].unit->sprites.path[8]);
                                        tmpS.setTexture(tmpT);
                                        tmpS.setPosition(self->cell[i][j].X,self->cell[i][j].Y);



                                            window.clear(sf::Color::Black);
                                            window.draw(gameBackground);
                                            drawUnits(self,window);

                                            window.draw(gameInterface);
                                            window.draw(gameMenu);
                                            drawMinMap(window,player,self);
                                            window.draw(gameEndTurn);
                                            drawPlayer(window,1,pl);


                                            window.draw(cBc);
                                            window.draw(tmpS);




                                        window.display();
                                        Sleep(400);

                                        deleteUnit(self->cell[i][j].unit);


                                        self->cell[i][j].unit = NULL;
                                        self->cell[i][j].obj_un_null = 0;
                                        return 1;
                                      }



                                      return 1;



                                    }else{
                                    self->cell[i][j].obj_un_null = 1;
                                    }
                                }



                            }

                        }
                   }
                return 0;
              }
Example #16
0
//--------------------------------------------------------------------------------------------------------------
Position ImplAlignment::getNumGaps() const
{
	if (mChangedLength)
		calculateLength();
	return mNumGaps;
}
Example #17
0
//first only left alignment
//align 0 left, 1 center, 2 justified
void Text::setBlockText(std::string text, float width, int align, float xOffset, float yOffset){
	logInf("setBlockText width: %f", width);
	const float maxWhiteSpaceModificator = 2.0f;
	const float tooLargeWhiteSpaceModificator = 8.0f;
	float x = 0.0f + xOffset;
	float y = GlobalData::getInstance()->screenHeight - maxHeight + yOffset;

	if(vbo != 0) glDeleteBuffers(1, &vbo);
	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);

	const uint8_t *p;

	uint8_t *lineEnding;
	//logWar("Text::setText message: %s x: %f y: %f sx: %f sy: %f", text, x, y, sx, sy);
    text = parseAndReplaceAccents(text);
	point coords[6 * strlen(text.c_str())];
	cIndex = 0;
	float line = 0.0f;
	lineEnding = calculatePointerEndLine(text.c_str(), width);
	/* Loop through all characters */
	float whiteSpaceModificator = 1.0f;
	if(align == 2){//justificat
		float messageLength = calculateLength(text.c_str(),(const char *)lineEnding);
		float numWhiteSpaces = calculateNumWhiteSpaces(text.c_str(),(const char *)lineEnding);
		float advanceWhiteSpace = c[' '].ax;

		whiteSpaceModificator = (width - messageLength + numWhiteSpaces*advanceWhiteSpace)/(numWhiteSpaces*advanceWhiteSpace);

		if(whiteSpaceModificator >= tooLargeWhiteSpaceModificator){
			whiteSpaceModificator = 1.0f;
		}else if(whiteSpaceModificator >= maxWhiteSpaceModificator){
			whiteSpaceModificator = maxWhiteSpaceModificator;
		}
	}

	if(align == 1){//center
		p = (const uint8_t *)text.c_str();
		x = (width - xOffset)/2.0f-calculateLength((const char *)p,(const char *)lineEnding)/2.0f + xOffset;
	}
	for(p = (const uint8_t *)text.c_str(); *p; p++){
		if(p == lineEnding){
			line--;
			if(*p == '\\') p++;
			p++;
			lineEnding = calculatePointerEndLine((const char*)p, width - xOffset);
			x = 0.0f + xOffset;
			if(align == 1){//center
				x = (width - xOffset)/2.0f-calculateLength((const char *)p,(const char *)lineEnding)/2.0f + xOffset;
			}else if(align == 2){//justificat
				float messageLength = calculateLength((const char *)p,(const char *)lineEnding);
				float numWhiteSpaces = calculateNumWhiteSpaces((const char *)p,(const char *)lineEnding);
				float advanceWhiteSpace = c[' '].ax;

				whiteSpaceModificator = (width - messageLength + numWhiteSpaces*advanceWhiteSpace)/(numWhiteSpaces*advanceWhiteSpace);

				if(whiteSpaceModificator >= tooLargeWhiteSpaceModificator){
					whiteSpaceModificator = 1.0f;
				}else if(whiteSpaceModificator >= maxWhiteSpaceModificator){
					whiteSpaceModificator = maxWhiteSpaceModificator;
				}
			}
		}
		/* Calculate the vertex and texture coordinates */
		float x2 = x + c[*p].bl;//bl bitmap left
		float y2 = -y - (c[*p].bt  + line * maxHeight);//bt bitmap top
		float w = c[*p].bw;//bw bitmap width
		float h = c[*p].bh;//bh bitmap height
		//logInf("caracter A bl bt bw bh ty tx = {%f, %f, %f, %f, %f, %f}", c[*p].bl, c[*p].bt, c[*p].bw, c[*p].bh, c[*p].ty, c[*p].tx);
		/* Advance the cursor to the start of the next character */

		if(*p == ' '){
			x += c[*p].ax*whiteSpaceModificator;//advance x
		}else{
			x += c[*p].ax;//advance x
		}
		y += c[*p].ay;//advance y

		/* Skip glyphs that have no pixels */
		if (!w || !h)
			continue;
		float marginXTexture = 0.5f/(float)atlasWidth;
		float marginYTexture = 0.5f/(float)atlasHeight;
		coords[cIndex++] = (point) {x2 + w, 	-y2,		c[*p].tx + c[*p].bw/(float)atlasWidth - marginXTexture,		c[*p].ty + marginYTexture};
		coords[cIndex++] = (point) {x2, 		-y2,		c[*p].tx + marginXTexture,									c[*p].ty + marginYTexture};
		coords[cIndex++] = (point) {x2, 		-y2 - h,	c[*p].tx + marginXTexture,									c[*p].ty + c[*p].bh / (float)atlasHeight - marginYTexture};
		coords[cIndex++] = (point) {x2 + w, 	-y2,		c[*p].tx + c[*p].bw/(float)atlasWidth - marginXTexture,		c[*p].ty + marginYTexture};
		coords[cIndex++] = (point) {x2, 		-y2 - h,	c[*p].tx + marginXTexture,									c[*p].ty + c[*p].bh / (float)atlasHeight - marginYTexture};
		coords[cIndex++] = (point) {x2 + w, 	-y2 - h,	c[*p].tx + c[*p].bw/(float)atlasWidth - marginXTexture,		c[*p].ty + c[*p].bh / (float)atlasHeight - marginYTexture};
	}
	glBufferData(GL_ARRAY_BUFFER, sizeof(coords), coords, GL_STATIC_DRAW);
}
Example #18
0
//--------------------------------------------------------------------------------------------------------------
Position ImplAlignment::getLength() const
{
	if (mChangedLength)
		calculateLength();
	return mLength;
}