Exemple #1
0
void Game::paint()
{
   //Draw the game background.
   OpenGLRenderer::getInstance()->drawTexture(m_Background, 0.0f, 0.0f, getWidth(), getHeight());
    
  //Cycle through and draw all the game objects
  for(int i = 0; i < m_GameObjects.size(); i++)
  {
    if(m_GameObjects.at(i)->getIsActive() == true)
    {
      m_GameObjects.at(i)->paint();
    }
      //Offset to paint the game lives.
      int offset = 0;
      
	  //Check how many lives there are.
      for (int i = 0; i < m_GameLives; i ++)
      {
		  //Paint the life.
          OpenGLRenderer::getInstance()->drawTexture(m_Lives, offset, ScreenManager::getInstance()->getCurrentScreen()->getHeight() - GAME_LIFE_OFFSET);
		  //Increment paint location.
          offset = offset + GAME_LIFE_INCREMENT;
      }
  }
  
  //Draw the outer white walls
  OpenGLRenderer::getInstance()->setForegroundColor(OpenGLColorWhite());
  OpenGLRenderer::getInstance()->setLineWidth(4.0f);
  OpenGLRenderer::getInstance()->drawLine(1.0f, 0.0f, 1.0f, getHeight());
  OpenGLRenderer::getInstance()->drawLine(0.0f, 1.0f, getWidth(), 1.0f);
  OpenGLRenderer::getInstance()->drawLine(getWidth() - 1, 0.0f, getWidth() - 1, getHeight());
  OpenGLRenderer::getInstance()->setLineWidth(1.0f);
}
OpenGLTexture::OpenGLTexture(OpenGLTextureInfo* aTextureInfo) :
m_TextureInfo(NULL),
m_Color(OpenGLColorWhite()),
m_AnchorX(0.0f),
m_AnchorY(0.0f)
{
    //Safety check that the texture info isn't NULL
    if(aTextureInfo != NULL)
    {
        //Allocate the texture info struct
        m_TextureInfo = new OpenGLTextureInfo();
        
        //Copy the texture info data
        m_TextureInfo->sourceX = aTextureInfo->sourceX;
        m_TextureInfo->sourceY = aTextureInfo->sourceY;
        m_TextureInfo->sourceWidth = aTextureInfo->sourceWidth;
        m_TextureInfo->sourceHeight = aTextureInfo->sourceHeight;
        m_TextureInfo->textureWidth = aTextureInfo->textureWidth;
        m_TextureInfo->textureHeight = aTextureInfo->textureHeight;
        m_TextureInfo->textureFormat = aTextureInfo->textureFormat;
        m_TextureInfo->textureId = aTextureInfo->textureId;
        m_TextureInfo->textureFilename = std::string(aTextureInfo->textureFilename);
        m_TextureInfo->atlasKey = std::string(aTextureInfo->atlasKey);
    }
}
OpenGLTexture::OpenGLTexture(const char* aFilename, const char* aAtlasKey) :
m_TextureInfo(NULL),
m_Color(OpenGLColorWhite()),
m_AnchorX(0.0f),
m_AnchorY(0.0f)
{
    //Safety check that the filename isn't NULL
    if(aFilename != NULL)
    {
        //Allocate the texture info struct
        m_TextureInfo = new OpenGLTextureInfo();
        
        //Set the texture info filename
        m_TextureInfo->textureFilename = std::string(aFilename);
        
        //Load the texture
        if(aAtlasKey != NULL)
        {
            m_TextureInfo->atlasKey = std::string(aAtlasKey);
            OpenGLTextureManager::getInstance()->loadTextureFromAtlas(aFilename, aAtlasKey, &m_TextureInfo);
        }
        else
        {
            OpenGLTextureManager::getInstance()->loadTexture(aFilename, &m_TextureInfo);
        }
    }
}
OpenGLTexture::OpenGLTexture(const char* aFilename, const char* aAtlasKey) :
    m_TextureInfo(NULL),
    m_Color(OpenGLColorWhite()),
    m_AnchorX(0.0f),
    m_AnchorY(0.0f)
{
    //Safety check that the filename isn't NULL
    if(aFilename != NULL)
    {
        //Allocate the texture info struct
        m_TextureInfo = (OpenGLTextureInfo*)malloc(sizeof(OpenGLTextureInfo));
        memset(m_TextureInfo, 0, sizeof(OpenGLTextureInfo));

        //Set the texture info filename
        m_TextureInfo->textureFilename = (const char*)malloc(strlen(aFilename)+1);
        memcpy((void*)m_TextureInfo->textureFilename, aFilename, strlen(aFilename)+1);

        //Load the texture
        if(aAtlasKey != NULL)
        {
            OpenGLTextureManager::getInstance()->loadTextureFromAtlas(aFilename, aAtlasKey, &m_TextureInfo);
        }
        else
        {
            OpenGLTextureManager::getInstance()->loadTexture(aFilename, &m_TextureInfo);
        }
    }
}
Exemple #5
0
void Enemy::paint()
{
    OpenGLRenderer::getInstance()->setForegroundColor(OpenGLColorRed());
    OpenGLRenderer::getInstance()->drawCircle(getX() + (getWidth() / 2), getY() + (getHeight() / 2), getWidth() / 2);
    
    OpenGLRenderer::getInstance()->setForegroundColor(OpenGLColorWhite());
    OpenGLRenderer::getInstance()->drawCircle(getX() + (getWidth() / 2), getY() + (getHeight() / 2), getWidth() / 2, false);

}
void Brick::paint()
{
  //Draw the Red paddle with a white outline
  OpenGLRenderer::getInstance()->setLineWidth(2.0f);
  OpenGLRenderer::getInstance()->setForegroundColor(OpenGLColorRed());
  OpenGLRenderer::getInstance()->drawRectangle(getX(), getY(), getWidth(), getHeight());
  OpenGLRenderer::getInstance()->setForegroundColor(OpenGLColorWhite());
  OpenGLRenderer::getInstance()->drawRectangle(getX(), getY(), getWidth(), getHeight(), false);
  OpenGLRenderer::getInstance()->setLineWidth(1.0f);
}
Exemple #7
0
void Tower::paintTowerRange()
{
	if(m_Target == NULL)
	{
		OpenGLRenderer::getInstance()->setForegroundColor(OpenGLColorWhite());
	}
	else
	{
		if(m_Target->getIsActive())
		{
			OpenGLRenderer::getInstance()->setForegroundColor(OpenGLColorRed());
		}
		else
		{
			OpenGLRenderer::getInstance()->setForegroundColor(OpenGLColorWhite());
		}
	}

	OpenGLRenderer::getInstance()->drawCircle(getX() + (getWidth() / 2), getY() + (getHeight() / 2), m_Range, false);
}
Exemple #8
0
void Game::paint()
{	

	//While the game is loading, the load method will be called once per update
	if (isLoading() == true)
	{
		//Cache the screen width and height
		float screenWidth = getScreenWidth();
		float screenHeight = getScreenHeight();

		//Draw a black background, you could replace this
		//in the future with a full screen background texture
		OpenGLRenderer::getInstance()->setForegroundColor(OpenGLColorBlack());
		OpenGLRenderer::getInstance()->drawRectangle(0.0f, 0.0f, screenWidth, screenHeight);

		//Calculate the bar width and height, don't actually hard-code these
		float barWidth = 200.0f * getScale();
		float barHeight = 40.0f * getScale();
		float barX = (screenWidth - barWidth) / 2.0f;
		float barY = (screenHeight - barHeight) / 2.0f;

		//
		float percentageLoaded = (float)m_LoadStep / (float)(GameLoadStepCount - 1);
		float loadedWidth = barWidth * percentageLoaded;
		OpenGLRenderer::getInstance()->setForegroundColor(OpenGLColorYellow());
		OpenGLRenderer::getInstance()->drawRectangle(barX, barY, loadedWidth, barHeight);

		//
		OpenGLRenderer::getInstance()->setForegroundColor(OpenGLColorWhite());
		OpenGLRenderer::getInstance()->drawRectangle(barX, barY, barWidth, barHeight, false);

		return;
	}

	OpenGLRenderer::getInstance()->drawTexture(m_BackgroundTexture,0.0f,0.0f);

#if _DEBUG
	if (m_World != NULL)
	{
		m_World->DrawDebugData();
	}
#endif

	//Paint the game's game objects
	for (int i = 0; i < m_GameObjects.size(); i++)
	{
		m_GameObjects.at(i)->paint();
	}
}
OpenGLTexture::OpenGLTexture(OpenGLTextureInfo* aTextureInfo) :
    m_TextureInfo(NULL),
    m_Color(OpenGLColorWhite()),
    m_AnchorX(0.0f),
    m_AnchorY(0.0f)
{
    //Safety check that the texture info isn't NULL
    if(aTextureInfo != NULL)
    {
        //Allocate the texture info struct
        m_TextureInfo = (OpenGLTextureInfo*)malloc(sizeof(OpenGLTextureInfo));
        memset(m_TextureInfo, 0, sizeof(OpenGLTextureInfo));

        //Copy the contents of the Texture info struct
        memcpy(m_TextureInfo, aTextureInfo, sizeof(OpenGLTextureInfo));
    }
}
Exemple #10
0
void Game::paint()
{
	// Show the title screen
	if(m_ShowTitle)
	{
		OpenGLRenderer::getInstance()->drawTexture(m_Textures[21], 15.0f, 0.0f);
		return;
	}

	// If the game is over
	if(m_GameOver)
	{
		// Draw the game over texture
		OpenGLRenderer::getInstance()->drawTexture(m_Textures[19], ScreenManager::getInstance()->getScreenWidth() / 2 - m_Textures[19]->getSourceWidth() / 2, ScreenManager::getInstance()->getScreenHeight() / 1.5);
		return;
	}

	// Draw the texture for the game background
	Paddle* paddle = (Paddle*)getGameObjectByType(GAME_PADDLE_TYPE);
	if(paddle != NULL)
	{
		// Move the textures as the paddle moves
		// Draw the background texture
		OpenGLRenderer::getInstance()->drawTexture(m_Textures[0], (paddle->getX() / 8) - (m_Textures[0]->getTextureWidth() / 4), 0.0f);

		// Only draw when player has lives
		if(m_Lives > 0)
		{
			// draws the HP texture
			OpenGLRenderer::getInstance()->drawTexture(m_Textures[10], paddle->getX() + paddle->getWidth() / 8, paddle->getY() + paddle->getHeight() * 1.55);
			OpenGLRenderer::getInstance()->drawTexture(m_Textures[m_Lives], paddle->getX() + paddle->getWidth() / 3.5, paddle->getY() + paddle->getHeight() * 1.25);
		}

		// Only draw when within the maximum number of rounds
		if(m_Round <= GAME_MAX_ROUNDS)
		{
			// draws the round texture
			OpenGLRenderer::getInstance()->drawTexture(m_Textures[11], paddle->getX() + paddle->getWidth() / 1.5, paddle->getY() + paddle->getHeight() * 1.55);
			OpenGLRenderer::getInstance()->drawTexture(m_Textures[m_Round + 1], paddle->getX() + paddle->getWidth() / 1.25, paddle->getY() + paddle->getHeight() * 1.25);
		}
	}

	//Cycle through and draw all the game objects
	for(int i = 0; i < m_GameObjects.size(); i++)
	{
		if(m_GameObjects.at(i)->getIsActive() == true)
		{
			// Painting bricks
			if(m_GameObjects.at(i)->getType() == GAME_BRICK_TYPE)
			{
				// Paints a different texture for each round
				m_GameObjects.at(i)->paint(m_Textures[12 + m_Round]);
			}

			// Painting balls
			else if(m_GameObjects.at(i)->getType() == GAME_BALL_TYPE)
			{
				m_GameObjects.at(i)->paint(m_Textures[18]);
			}
			else
			{
				m_GameObjects.at(i)->paint();
			}
		}
	}

	//Draw the outer white walls
	OpenGLRenderer::getInstance()->setForegroundColor(OpenGLColorWhite());
	OpenGLRenderer::getInstance()->setLineWidth(4.0f);
	OpenGLRenderer::getInstance()->drawLine(1.0f, 0.0f, 1.0f, getHeight());
	OpenGLRenderer::getInstance()->drawLine(0.0f, 1.0f, getWidth(), 1.0f);
	OpenGLRenderer::getInstance()->drawLine(getWidth() - 1, 0.0f, getWidth() - 1, getHeight());
	OpenGLRenderer::getInstance()->setLineWidth(1.0f);

	// If the game is paused
	if(m_Pause)
	{
		// Draw the pause texture
		OpenGLRenderer::getInstance()->drawTexture(m_Textures[9], ScreenManager::getInstance()->getScreenWidth() / 2 - m_Textures[9]->getSourceWidth() / 2, ScreenManager::getInstance()->getScreenHeight() / 1.5);
	}
}