Esempio n. 1
0
void TileLayer::render()
{
    int x, y, x2, y2 = 0;
    
    x = m_position.getX() / m_tileSize;
    y = m_position.getY() / m_tileSize;
    
    x2 = int(m_position.getX()) % m_tileSize;
    y2 = int(m_position.getY()) % m_tileSize;
    
    for(signed int i = 0; i < m_numRows; i++)
    {
        for(int j = 0; j < m_numColumns; j++)
        {
            int id = m_tileIDs[i + y][j + x];
            
            if(id == 0)
            {
                continue;
            }
            
            Tileset tileset = getTilesetByID(id);
            
            id--;
            
            TheTextureManager::Instance()->drawTile(tileset.name, tileset.margin, tileset.spacing, (j * m_tileSize) - x2, (i * m_tileSize) - y2, m_tileSize, m_tileSize, (id - (tileset.firstGridID - 1)) / tileset.numColumns, (id - (tileset.firstGridID - 1)) % tileset.numColumns, TheGame::Instance()->getRenderer());
        }
    }
}
Esempio n. 2
0
void TileLayer::render() {
	int x, y, x2, y2 = 0;
	x2 = TheCamera::Instance()->getPosition().getX();
	y2 = int(m_position.getY()) % m_tileHeight;
	int firstCol = TheCamera::Instance()->getPosition().getX() / m_tileWidth;

	for (int i = 0; i < m_numRow; i++){
		for (int j = firstCol; j < m_numCol + firstCol-1; j++){
			int id = m_tileIDs[i][j];
			if (id == 0){
				continue;
			}
			Tileset tileset = getTilesetByID(id);
			id--;
			TextureManager::Instance()->drawTileset(
				tileset.name.c_str(),
				tileset.margin,
				tileset.spacing,
				((j * m_tileWidth) - x2),
				((i * m_tileHeight) - y2),
				m_tileWidth,
				m_tileHeight,
				(id - (tileset.firstGridID - 1)) / tileset.numColumns,
				(id - (tileset.firstGridID - 1)) % tileset.numColumns,
				Game::Instance()->getRender()
				);
		}
	}
	
}
Esempio n. 3
0
void TileLayer::render()
{

	for (int i = 0; i < m_nRows; ++i)
	{
		for (int j = m_nColumnIncrement; j < m_nColumns + m_nColumnIncrement; ++j)
		{
			int id = m_tileIDs[i][j];
			if (id != 0)
			{
				Tileset tileset = getTilesetByID(id);
				TextureManager::Instance()->drawTile(tileset.name, id, tileset, i, j, m_nColumnIncrement, Game::Instance()->getRenderer());
			}
		}
	}
}
Esempio n. 4
0
void TileLayer::render()
{
	int x, y, x2, y2 = 0;

	x = m_position.getX() / m_tileSize; // Gives us the x tile to start drawing from e.g. If position is 100 and tile width is 32 then this equals 3. Therefore we draw from 3rd Tile
	y = m_position.getY() / m_tileSize; // This works the same way as above but for y axis

	x2 = int(m_position.getX()) % m_tileSize; // This ensures smooth scrolling by giving use the remaining amount of tile width after int calculation
	y2 = int(m_position.getY()) % m_tileSize; // This ensures smooth scrolling by giving use the remaining amount of tile width after int calculation

	for (int i = 0; i < m_numRows; i++)
	{
		for (int j = 0; j < m_numColumns; j++)
		{

			int id = m_tileIDs[i + y][j + x];

			if (id == 0)
			{
				continue;
			}

			// if outside viewable area then skip tile
			if (((j * m_tileSize) - x2) - TheCamera::Instance()->getPosition().m_x < -m_tileSize || 
				((j * m_tileSize) - x2) - TheCamera::Instance()->getPosition().m_x > TheGame::Instance()->getWindowWidth() || 
				(((i * m_tileSize) - y2) - TheCamera::Instance()->getPosition().m_y < -m_tileSize ||
				((i * m_tileSize) - y2) - TheCamera::Instance()->getPosition().m_y > TheGame::Instance()->getWindowHeight()))
			{
				continue;
			}

			Tileset tileset = getTilesetByID(id);

			id--;

			//draw the tile into position by offsetting its x & y position by subtracting the camera
			TheTextureManager::Instance()->drawTile(tileset.name, tileset.margin, tileset.spacing,
				((j * m_tileSize) - x2) - TheCamera::Instance()->getPosition().m_x, ((i * m_tileSize) - y2) - TheCamera::Instance()->getPosition().m_y, // Subtract smooth scrolling amounts & camera pos
				m_tileSize, m_tileSize,
				(id - (tileset.firstGridID - 1)) / tileset.numColumns,
				(id - (tileset.firstGridID - 1)) % tileset.numColumns, 
				TheGame::Instance()->getRenderer());
		}
	}
}
Esempio n. 5
0
void TileLayer::render()
{
	int x, y, x2, y2 = 0;
	x = m_position.getX() / m_tileSize;
	y = m_position.getY() / m_tileSize;
//	x2 = int(m_position.getX()) % m_tileSize;
	Vector2D tempCamPos = Camera::Instance()->getPosition();
	x2 = tempCamPos.getX();
	y2 = int(m_position.getY()) % m_tileSize;
	int firstCol = tempCamPos.getX() / m_tileSize;
	//printf("La posicion de la camara es: X: %f   Y:%f \n", tempCamPos.getX(), tempCamPos.getY());
	//Lo hago generico.
	/*if (x > m_width - 101) {
		x2 = 0;
		x = m_width - 101;
	}*/


	for (int i = 0; i < m_numRows + 1; i++)
	{
		for (int j = firstCol; j < firstCol+m_numColumns + 1; j++)
		{
			
			int id = m_tileIDs[i][j + x];
			if (id == 0)
			{
				continue;
			}
			Tileset tileset = getTilesetByID(id);
			id--;

			TextureManager::Instance()->drawTile(tileset.name, tileset.margin, tileset.spacing, (j * m_tileSize) - x2, (i *
				m_tileSize) - y2, m_tileSize, m_tileSize, (id - (tileset.firstGridID - 1)) / tileset.numColumns, (id -
					(tileset.firstGridID - 1)) % tileset.numColumns, Game::Instance()->GetRenderer());
		}
	}
}
Esempio n. 6
0
void TileLayer::render()
{
	
	int x, y, x2, y2 = 0;
	x = m_position.getX() / m_tileSize;
	y = m_position.getY() / m_tileSize;
	Vector2D tempCamPos = Camera::Instance()->getPosition();
	x2 = tempCamPos.getX();
	y2 = int(m_position.getY()) % m_tileSize;
	
	int firstCol = tempCamPos.getX() / m_tileSize;
	for (int i = 0; i < m_numRows+1; i++)
	{
		
		for (int j = firstCol; j < firstCol + m_numColumns; j++)
		{
			/*if (j + x < 0 || j + x > m_tileIDs[0].size() - 1 || i > m_tileIDs.size() - 1) {
				col++;
				continue;
			}*/
			int id = m_tileIDs[i][j + x];
			
			if (id == 0)
			{
				
				continue;
			}
			Tileset tileset = getTilesetByID(id);
			id--;
			
			TextureManager::Instance()->drawTile(tileset.name.c_str(), tileset.margin, tileset.spacing, (j * m_tileSize) - x2, (i * m_tileSize) - y2,
				m_tileSize, m_tileSize, (id - (tileset.firstGridID - 1)) / tileset.numColumns,
				(id - (tileset.firstGridID - 1)) % tileset.numColumns, Game::Instance()->getRender());
			
		}
	}
}