Exemplo n.º 1
0
void Tile::paintScoreNumber(int aNumber, float aX, float aY)
{
    //Check to see if its a walkable tile
    if(isWalkableTile() == true)
    {
        //Convert the number to a stringstream
        std::stringstream numberStream;
        numberStream << aNumber;
        
        //Next convert the stringstream into a string
        std::string numberString(numberStream.str());
        
        //Cycle through each number in the string and draw it
        for(int i = 0; i < (int)(numberString.length()); i++)
        {
            //Convert the letter in the string back to an int
            int index = atoi(numberString.substr(i,1).c_str());
            
            //Draw the texture that is equivalent to the number
            OpenGLRenderer::getInstance()->drawTexture(m_TileScoreNumbers[index], aX, aY);
            
            //Increment the X value
            aX += m_TileScoreNumbers[index]->getSourceWidth();
        }
    }
}
Exemplo n.º 2
0
void Tile::paintScoreNumber(int number, ScoreNumberPosition position, float scale, float padding)
{
    //Check to see if its a walkable tile
    if(isWalkableTile() == true)
    {
        //Convert the number to a stringstream
        std::stringstream numberStream;
        numberStream << number;
        
        //Next convert the stringstream into a string
        std::string numberString(numberStream.str());
        
        //Cycle through each number in the string and calculate the total width of the string
        float stringWidth = 0.0f;
        float stringHeight = 0.0f;
        for(int i = 0; i < numberString.length(); i++)
        {
            //Convert the letter in the string back to an int
            int index = atoi(numberString.substr(i,1).c_str());
            
            //Increment the X value
            stringWidth += m_TileScoreNumbers[index]->getSourceWidth();
            stringHeight = stringHeight < m_TileScoreNumbers[index]->getSourceHeight() ? m_TileScoreNumbers[index]->getSourceHeight() : stringHeight;
        }
        
        float scaledWidth = stringWidth * scale;
        float scaledHeight = stringHeight * scale;
        float x = 0.0f;
        float y = 0.0f;
        
        //Calculate the x and y position based on the string width and height
        switch (position)
        {
            case TopLeft:
            x = getX() + padding;
            y = getY() + padding;
            break;

            case BottomLeft:
            x = getX() + padding;
            y = getY() + getHeight() - scaledHeight - padding;
            break;

            case BottomRight:
            x = getX() + getWidth() - scaledWidth - padding;
            y = getY() + getHeight() - scaledHeight - padding;
            break;
        }
        
        //Cycle through each number in the string and draw it
        for(int i = 0; i < numberString.length(); i++)
        {
            //Convert the letter in the string back to an int
            int index = atoi(numberString.substr(i,1).c_str());
            
            //Calculate the scaled width and height
            float width = m_TileScoreNumbers[index]->getSourceWidth() * scale;
            float height = m_TileScoreNumbers[index]->getSourceHeight() * scale;
            
            //Draw the texture that is equivalent to the number
            OpenGLRenderer::getInstance()->drawTexture(m_TileScoreNumbers[index], x, y, width, height);
            
            //Increment the X value
            x += m_TileScoreNumbers[index]->getSourceWidth() * scale;
        }
    }
}