Esempio n. 1
0
bool MGMap::mouseScrollingUpdate(int x, int y)
{
	if(m_MouseScrollingOngoing)
	{
		int setY = getScrollY() + m_MouseScrollingYClick - y;
		int setX = getScrollX() + m_MouseScrollingXClick - x;

		if(setY > getTopEdge())
		{
			setY = getTopEdge();
		}
		else if(setY < getWindowHeight() - getHeight() * getTileHeight() - getBottomEdge())
		{
			setY = getWindowHeight() - getHeight() * getTileHeight() - getBottomEdge();
		}

		if(setX > getLeftEdge())
		{
			setX = getLeftEdge();
		}
		else if(setX < getWindowWidth() - getWidth() * getTileWidth() - getRightEdge())
		{
			setX = getWindowWidth() - getWidth() * getTileWidth() - getRightEdge();
		}

		setScrollOffset(setX, setY);
	}
	return m_MouseScrollingOngoing;
}
Esempio n. 2
0
void TiledMap::setColTiles()
{

	int width = getTileWidth();
	int height = getTileHeight();
	int tilesetID(0);
	int tileID(-1);

	for (int y(0); y < static_cast<int>(currentTMXMap_->getLayer()[0]->data.size()); ++y)
	{
		for (int x(0); x < static_cast<int>(currentTMXMap_->getLayer()[0]->data[0].size()); x++)
		{
			tilesetID = getTilesetID(currentTMXMap_->getLayer()[0]->data[y][x]);
			if (tilesetID > -1)
			{
				tileID = currentTMXMap_->getLayer()[0]->data[y][x] - currentTMXMap_->getTileSet()[tilesetID]->firstgid_; // +firstGID_[tilesetID];
				if (currentTMXMap_->getTileSet()[tilesetID]->getTilePropertyName(tileID) == "blocked" && currentTMXMap_->getTileSet()[tilesetID]->getTilePropertyValue(tileID) == "true")
				{
					blocked_[y][x] = 1;
				}
				else
				{
					blocked_[y][x] = 0;
				}
			}
			else
			{
				blocked_[y][x] = 0;
			}
		}

	}
	std::cout << blocked_.size() << " - " << blocked_[0].size() << std::endl;

}
Esempio n. 3
0
void tmx::Tileset::tell() {
	std::cout << "Name: " << getName() << "\n"
			  << "Source: " << getSource() << "\n"
			  << "First gID: " << getFirstGid() << "\n"
			  << "Tile Width: " << getTileWidth() << "\n"
			  << "Tile Height: " << getTileHeight() << "\n"
			  << "Spacing: " << getSpacing() << "\n"
			  << "Margin: " << getMargin() << std::endl;
}
Esempio n. 4
0
void HeightMipmap::getTile(int level, int tx, int ty, float *tile)
{
    int tileSize = min(topLevelSize << level, this->tileSize);
    for (int j = 0; j <= tileSize + 4; ++j) {
        for (int i = 0; i <= tileSize + 4; ++i) {
            tile[i + j * (this->tileSize + 5)] = getTileHeight(i + tileSize * tx - 2, j + tileSize * ty - 2) / scale;
        }
    }
}
Esempio n. 5
0
ossimRefPtr<ossimImageData> ossimImageSource::getTile(const ossimIpt& origin,
                                                      ossim_uint32 resLevel)
{
   ossimIrect tileRect(origin.x,
                       origin.y,
                       origin.x + getTileWidth()  - 1,
                       origin.y + getTileHeight() - 1);
   
   return getTile(tileRect, resLevel);
}
Esempio n. 6
0
rspfRefPtr<rspfImageData> rspfImageSource::getTile(const rspfIpt& origin,
        rspf_uint32 resLevel)
{
    rspfIrect tileRect(origin.x,
                       origin.y,
                       origin.x + getTileWidth()  - 1,
                       origin.y + getTileHeight() - 1);

    return getTile(tileRect, resLevel);
}
Esempio n. 7
0
void HeightMipmap::buildMipmapLevel(int level)
{
    char buf[256];
    int nTiles = max(1, (baseLevelSize / tileSize) >> (maxLevel - level));
    int nTilesPerFile = min(nTiles, 16);

    printf("Build mipmap level %d...\n", level);

    currentLevel = level + 1;
    reset(baseLevelSize >> (maxLevel - currentLevel), baseLevelSize >> (maxLevel - currentLevel), min(topLevelSize << currentLevel, tileSize));

    for (int dy = 0; dy < nTiles / nTilesPerFile; ++dy) {
        for (int dx = 0; dx < nTiles / nTilesPerFile; ++dx) {
            sprintf(buf, "%s/%.2d-%.4d-%.4d.tiff", cache.c_str(), level, dx, dy);
            if (flog(buf)) {
                TIFF* f = TIFFOpen(buf, "wb");
                for (int ny = 0; ny < nTilesPerFile; ++ny) {
                    for (int nx = 0; nx < nTilesPerFile; ++nx) {
                        int tx = nx + dx * nTilesPerFile;
                        int ty = ny + dy * nTilesPerFile;

                        int off = 0;
                        int currentTileSize = min(topLevelSize << level, tileSize);
                        for (int j = -2; j <= currentTileSize + 2; ++j) {
                            for (int i = -2; i <= currentTileSize + 2; ++i) {
                                int ix = 2 * (tx * currentTileSize + i);
                                int iy = 2 * (ty * currentTileSize + j);
                                /*float h1 = getTileHeight(ix, iy);
                                float h2 = getTileHeight(ix+1, iy);
                                float h3 = getTileHeight(ix, iy+1);
                                float h4 = getTileHeight(ix+1, iy+1);
                                short sh = (short) ((h1 + h2 + h3 + h4) / 4);*/
                                short sh = (short) (getTileHeight(ix, iy));
                                tile[off++] = sh & 0xFF;
                                tile[off++] = sh >> 8;
                            }
                        }

                        TIFFSetField(f, TIFFTAG_IMAGEWIDTH, currentTileSize + 5);
                        TIFFSetField(f, TIFFTAG_IMAGELENGTH, currentTileSize + 5);
                        TIFFSetField(f, TIFFTAG_SAMPLESPERPIXEL, 1);
                        TIFFSetField(f, TIFFTAG_BITSPERSAMPLE, 16);
                        TIFFSetField(f, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
                        TIFFSetField(f, TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT);
                        TIFFSetField(f, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
                        TIFFSetField(f, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
                        TIFFWriteEncodedStrip(f, 0, tile, (currentTileSize + 5) * (currentTileSize + 5) * 2);
                        TIFFWriteDirectory(f);
                    }
                }
                TIFFClose(f);
            }
        }
    }
}
Esempio n. 8
0
void
IsoMapTile::render()
{
	SDL_Rect rect;

	if (getImage() == NULL || getScreen() == NULL)
		return;

	int xOff = 0, yOff = 0;

	yOff = -(TILE_HEIGHT / 2);

	if (getLocation().getY() % 2 == 0)
		xOff = -(TILE_WIDTH / 2);

	rect.x = getLocation().getX() * TILE_WIDTH + xOff;
	rect.y = getLocation().getY() * (TILE_HEIGHT / 2) +
	         (TILE_HEIGHT - getTileHeight()) + yOff;
	rect.w = getTileWidth();
	rect.h = getTileHeight();

	SDL_BlitSurface(getImage(), NULL, getScreen(), &rect);
}
Esempio n. 9
0
int MGMap::getTileIndex(int clickX, int clickY)
{
	MGFLOG_INFO("MGMap::getTileIndex(" << clickX << ", " << clickY << ")");
	if(	clickX > getLeftEdge() &&
		clickX < (getWindowWidth() - getRightEdge()) &&
		clickY > getTopEdge() &&
		clickY < (getWindowHeight() - getBottomEdge()))
	{
		int x = (clickX - getScrollX()) / getTileWidth();
		int y = (clickY - getScrollY()) / getTileHeight();
		if(x < getWidth() && y < getHeight())
		{
			return y * getWidth() + x;
		}
	}
	return -1; // Click outside of map
}
Esempio n. 10
0
void ossimLasReader::initTile()
{
   const ossim_uint32 BANDS = getNumberOfOutputBands();

   m_tile = new ossimImageData(this,
                               getOutputScalarType(),
                               BANDS,
                               getTileWidth(),
                               getTileHeight());

   for(ossim_uint32 band = 0; band < BANDS; ++band)
   {
      m_tile->setMinPix(getMinPixelValue(band),   band);
      m_tile->setMaxPix(getMaxPixelValue(band),   band);
      m_tile->setNullPix(getNullPixelValue(band), band);
   }

   m_tile->initialize();
}
Esempio n. 11
0
void TiledLayer::createBox2DTileWorld(Game *game, b2World *world)
{
	//Definitions for the tile body
	b2PolygonShape boxShape;
	boxShape.SetAsBox(64.0f, 64.0f);
	b2FixtureDef boxFixtureDef;
	boxFixtureDef.shape = &boxShape;
	boxFixtureDef.density = 1.0f;

	b2BodyDef myBodyDef;
	myBodyDef.type = b2_staticBody; //change body type

	if (this->hasCollidableTiles()) // For all the collidable tiles only
	{
		int cols = getColumns();
		int rows = getRows();
		int height = getTileHeight();
		int width = getTileWidth();
		Tile *tile;


		// create a box2d b2Body for each collidable tile
		for (int j = 0; j < cols; j++)
		{
			for (int k = 0; k < rows; k++)
			{
				tile = getTile(k, j);
				if ((*tile).collidable)
				{
					float32 tX = k * width / 64.0f;
					float32 tY = j * height / 64.0f;
					myBodyDef.position.Set(tX / 2, tY / 2);
					b2Body* staticBody = world->CreateBody(&myBodyDef);
					staticBody->CreateFixture(&boxFixtureDef);

				}
			}
		}
	}

}
Esempio n. 12
0
bool TiledMap::initaliseMap()
{
	if (currentTMXMap_)
	{
		mapBounds_.x = static_cast<unsigned> (currentTMXMap_->getWidth());
		mapBounds_.y = static_cast<unsigned> (currentTMXMap_->getHeight());
		tileSize_.x = static_cast<unsigned> (currentTMXMap_->getTileWidth());
		tileSize_.y = static_cast<unsigned> (currentTMXMap_->getTileHeight());

		firstGID_.resize(currentTMXMap_->getTileSet().size());
		tileCount_.resize(currentTMXMap_->getTileSet().size());

		blocked_.resize(mapBounds_.y); //resize the first dimension of the blocked map vector to the map bounds 

		for (int i(0); i < static_cast<int>(blocked_.size()); ++i)//Initialise the 2nd dimension with the right size
			blocked_[i].resize(mapBounds_.x);

		for (int i(0); i < static_cast<int>(firstGID_.size()); ++i)
		{
			firstGID_[i] = currentTMXMap_->getTileSet()[i]->firstgid_;
			tileCount_[i] = currentTMXMap_->getTileSet()[i]->tileCount_;
		}

		tempText.loadFromFile("res//tiles//tilesheet.png");

		initVertexArrays();
		setColTiles();

		for (int i(0); i < 8; ++i)
		{
			collisionArea_[i].collider.width = static_cast<float>(getTileWidth());
			collisionArea_[i].collider.height = static_cast<float>(getTileHeight());
		}

	}
	else
		return(false);

	return(true);
}
Esempio n. 13
0
void tmx::Tilemap::tell() {
    std::cout << "==MAP==" << "\n\n"
              << "Version: " << getVersion() << "\n"
              << "Orientation: " << getOrientation() << "\n"
              << "Width: " << getWidth() << "\n"
              << "Height: " << getHeight() << "\n"
              << "Tile width: " << getTileWidth() << "\n"
              << "Tile height: " << getTileHeight() << "\n"
              << "Background color: " << getBackgroundColor() << "\n"
              << "# of tilesets: " << mTileset.size() << "\n"
              << "# of layers: " << mLayer.size() << "\n"
              << "# of objectgroups: " << mObjectGroup.size() << "\n"
              << "# of imagelayers: " << mImageLayer.size() << "\n\n"
              << "==TILESETS==" << "\n" << std::endl;

    for(std::vector<Tileset>::size_type i = 0; i != mTileset.size(); ++i) {
        mTileset[i].tell();
    }

    std::cout << "\n==LAYERS==\n" << std::endl;

    for(std::vector<Layer>::size_type i = 0; i != mLayer.size(); ++i) {
        mLayer[i].tell();
    }

    std::cout << "\n==OBJECT GROUPS==\n" << std::endl;

    for(std::vector<Objectgroup>::size_type i = 0; i != mObjectGroup.size(); ++i) {
        mObjectGroup[i].tell();
    }

    std::cout << "\n==IMAGE LAYERS==\n" << std::endl;

    for(std::vector<Imagelayer>::size_type i = 0; i != mImageLayer.size(); ++i) {
        mImageLayer[i].tell();
    }
}
Esempio n. 14
0
	bool isSolidAtCoord(const glm::vec2 &pos) {
		return getTile(pos.x / getTileWidth(), pos.y / getTileHeight()).isSolid;
	}
Esempio n. 15
0
	bool isSolidAtCoord(float x, float y) const {
		return getTile(x / getTileWidth(), y / getTileHeight()).isSolid;
	}
Esempio n. 16
0
bool TiledMap::isCollided(sf::FloatRect collider, const sf::Vector2f& moveVector)
{

	/*
	Collision Area order =
	left-up = (-1,-1)
	up = (0,-1)
	right-up = (1,-1)
	right = (1, 0)
	right-down = (1,1)
	down = (0,1)
	left-down = (-1,1)
	left = (-1,0)
	*/
	sf::Vector2i gridLoc(static_cast<int>(collider.left / getTileWidth()), static_cast<int>(collider.top / getTileWidth()));

	collisionArea_[0].blockedValue = blocked_[gridLoc.y - 1][gridLoc.x - 1]; //left-up tile
	collisionArea_[0].collider.top = static_cast<float>((gridLoc.y - 1) * getTileHeight());
	collisionArea_[0].collider.left = static_cast<float>((gridLoc.x - 1) * getTileWidth());

	collisionArea_[1].blockedValue = blocked_[gridLoc.y - 1][gridLoc.x]; //up tile
	collisionArea_[1].collider.top = static_cast<float>((gridLoc.y - 1) * getTileHeight());
	collisionArea_[1].collider.left = static_cast<float>((gridLoc.x) * getTileWidth());

	collisionArea_[2].blockedValue = blocked_[gridLoc.y - 1][gridLoc.x + 1]; //right-up tile
	collisionArea_[2].collider.top = static_cast<float>((gridLoc.y - 1) * getTileHeight());
	collisionArea_[2].collider.left = static_cast<float>((gridLoc.x + 1) * getTileWidth());

	collisionArea_[3].blockedValue = blocked_[gridLoc.y][gridLoc.x + 1]; //right tile
	collisionArea_[3].collider.top = static_cast<float>((gridLoc.y) * getTileHeight());
	collisionArea_[3].collider.left = static_cast<float>((gridLoc.x + 1) * getTileWidth());

	collisionArea_[4].blockedValue = blocked_[gridLoc.y + 1][gridLoc.x + 1]; //right-down tile
	collisionArea_[4].collider.top = static_cast<float>((gridLoc.y + 1) * getTileHeight());
	collisionArea_[4].collider.left = static_cast<float>((gridLoc.x + 1) * getTileWidth());


	collisionArea_[5].blockedValue = blocked_[gridLoc.y + 1][gridLoc.x]; //down tile
	collisionArea_[5].collider.top = static_cast<float>((gridLoc.y + 1) * getTileHeight());
	collisionArea_[5].collider.left = static_cast<float>((gridLoc.x) * getTileWidth());

	collisionArea_[6].blockedValue = blocked_[gridLoc.y + 1][gridLoc.x - 1]; //down-left tile
	collisionArea_[6].collider.top = static_cast<float>((gridLoc.y + 1) * getTileHeight());
	collisionArea_[6].collider.left = static_cast<float>((gridLoc.x - 1) * getTileWidth());

	collisionArea_[7].blockedValue = blocked_[gridLoc.y][gridLoc.x - 1]; //left tile
	collisionArea_[7].collider.top = static_cast<float>((gridLoc.y) * getTileHeight());
	collisionArea_[7].collider.left = static_cast<float>((gridLoc.x - 1) * getTileWidth());

	for (int i(0); i < 8; ++i)
	{
		if (collisionArea_[i].blockedValue == 1)
		{
			if (collisionArea_[i].collider.intersects(sf::FloatRect(collider.left + moveVector.x, collider.top + moveVector.y, collider.width, collider.height)))
				return(true);
		}
	}

	return false;

}
Esempio n. 17
0
sf::Vector2f TiledMap::getCollisionVector(sf::FloatRect collider, const sf::Vector2f& moveVector, const int id)
{
	assert(p_player_);
	sf::Vector2f moveBy(moveVector);

	//Get the grid location of the player
	sf::Vector2i gridLoc(static_cast<int>(collider.left / getTileWidth()), static_cast<int>(collider.top / getTileWidth()));
	/*
	Collision Area order =
	left-up = (-1,-1)
	up = (0,-1)
	right-up = (1,-1)
	right = (1, 0)
	right-down = (1,1)
	down = (0,1)
	left-down = (-1,1)
	left = (-1,0)
	*/
	collisionArea_[0].blockedValue = blocked_[gridLoc.y - 1][gridLoc.x - 1]; //left-up tile
	collisionArea_[0].collider.top = static_cast<float>((gridLoc.y - 1) * getTileHeight());
	collisionArea_[0].collider.left = static_cast<float>((gridLoc.x - 1) * getTileWidth());

	collisionArea_[1].blockedValue = blocked_[gridLoc.y - 1][gridLoc.x]; //up tile
	collisionArea_[1].collider.top = static_cast<float>((gridLoc.y - 1) * getTileHeight());
	collisionArea_[1].collider.left = static_cast<float>((gridLoc.x) * getTileWidth());

	collisionArea_[2].blockedValue = blocked_[gridLoc.y - 1][gridLoc.x + 1]; //right-up tile
	collisionArea_[2].collider.top = static_cast<float>((gridLoc.y - 1) * getTileHeight());
	collisionArea_[2].collider.left = static_cast<float>((gridLoc.x + 1) * getTileWidth());

	collisionArea_[3].blockedValue = blocked_[gridLoc.y][gridLoc.x + 1]; //right tile
	collisionArea_[3].collider.top = static_cast<float>((gridLoc.y) * getTileHeight());
	collisionArea_[3].collider.left = static_cast<float>((gridLoc.x + 1) * getTileWidth());

	collisionArea_[4].blockedValue = blocked_[gridLoc.y + 1][gridLoc.x + 1]; //right-down tile
	collisionArea_[4].collider.top = static_cast<float>((gridLoc.y + 1) * getTileHeight());
	collisionArea_[4].collider.left = static_cast<float>((gridLoc.x + 1) * getTileWidth());


	collisionArea_[5].blockedValue = blocked_[gridLoc.y + 1][gridLoc.x]; //down tile
	collisionArea_[5].collider.top = static_cast<float>((gridLoc.y + 1) * getTileHeight());
	collisionArea_[5].collider.left = static_cast<float>((gridLoc.x) * getTileWidth());

	collisionArea_[6].blockedValue = blocked_[gridLoc.y + 1][gridLoc.x - 1]; //down-left tile
	collisionArea_[6].collider.top = static_cast<float>((gridLoc.y + 1) * getTileHeight());
	collisionArea_[6].collider.left = static_cast<float>((gridLoc.x - 1) * getTileWidth());

	collisionArea_[7].blockedValue = blocked_[gridLoc.y][gridLoc.x - 1]; //left tile
	collisionArea_[7].collider.top = static_cast<float>((gridLoc.y) * getTileHeight());
	collisionArea_[7].collider.left = static_cast<float>((gridLoc.x - 1) * getTileWidth());

	for (int i(0); i < 8; ++i)
	{
		if (collisionArea_[i].blockedValue == 1)
		{
			//if there is a horizontal collision
			if (collisionArea_[i].collider.intersects(sf::FloatRect(collider.left + moveVector.x, collider.top, collider.width, collider.height)))
			{
				moveBy.x = 0.f;
			}
			//if there is a vertical collision
			if (collisionArea_[i].collider.intersects(sf::FloatRect(collider.left, collider.top + moveVector.y, collider.width, collider.height)))
			{
				moveBy.y = 0.f;
			}
		}

	}

	EnemyManager* eManage(EnemyManager::Get());

	assert(eManage != nullptr);

	if (id != 0)
	{

		if (p_player_->getCollider().intersects(sf::FloatRect(collider.left + moveVector.x, collider.top, collider.width, collider.height)))
		{
			moveBy.x = 0.f;
		}

		if (p_player_->getCollider().intersects(sf::FloatRect(collider.left, collider.top + moveVector.y, collider.width, collider.height)))
		{
			moveBy.y = 0.f;
		}

		for (int i(0); i < eManage->getEnemyCount(); ++i)
		{
			Enemy* e(eManage->getEnemy(i));

			assert(e != nullptr); //sanity checks

			if (i + 1 != id)
			{
				if (e->getAlive())
				{
					if (e->getCollider().intersects(sf::FloatRect(collider.left + moveVector.x, collider.top, collider.width, collider.height)))
					{
						e->collidedX_ = true;
						moveBy.x *= -1.f;
						if (e->getCollider().intersects(sf::FloatRect(collider.left + (moveVector.x + moveBy.x), collider.top, collider.width, collider.height)))
						{
							moveBy.x *= -1.f;
						}
					}
					else
					{
						e->collidedX_ = false;
					}
					if (e->getCollider().intersects(sf::FloatRect(collider.left, collider.top + moveVector.y, collider.width, collider.height)))
					{
						e->collidedY_ = true;
						moveBy.y *= -1.f;
						if (e->getCollider().intersects(sf::FloatRect(collider.left, collider.top + (moveVector.y + moveBy.y), collider.width, collider.height)))
						{
							moveBy.y *= -1.f;
						}
					}

					else
					{
						e->collidedY_ = false;
					}
				}
			}
		}
	}
	else
	{
		for (int i(0); i < gconsts::Gameplay::MAXENEMIES; i++)
		{
			Enemy* e(eManage->getEnemy(i));
			if (e->getAlive())
			{
				assert(e != nullptr); //sanity checks

				if (e->getCollider().intersects(sf::FloatRect(collider.left + moveVector.x, collider.top, collider.width, collider.height)))
				{
					moveBy.x = 0.f;
				}
				if (e->getCollider().intersects(sf::FloatRect(collider.left, collider.top + moveVector.y, collider.width, collider.height)))
				{
					moveBy.y = 0.f;
				}
			}
		}
	}

	return(moveBy);
}
Esempio n. 18
0
void SDL_TMXMap::Populate_Map(SDL_Renderer *Render)
{
    if( MapSurf || getMapFile().length())
    {
        if (!MapSurf)
        {
            std::ifstream *in_xml = new ifstream(getMapFile().c_str(), ifstream::in);
            if(!in_xml->is_open())
            {
                std::cout << "No way to Populate Map. Quitting..." <<endl;
                return;
            }
            std::stringstream *ss_xml = new std::stringstream;
            *ss_xml << in_xml->rdbuf();
            char *xml_data = new char[ss_xml->str().length()+1]();
            strcpy(xml_data, ss_xml->str().c_str());
            in_xml->close();
            delete ss_xml;
            Load_Map(xml_data);
            MapSurf = SDL_CreateRGBSurface(0, getWidth()*getTileWidth(), getHeight()*getTileHeight(), 32, rmask, gmask, bmask, amask);
        }

        string ResDir = "Resources\\";
        SDL_Surface **TileSurf = new SDL_Surface*[getNumTilesets()];
        for ( unsigned int fn = 0; fn < getNumTilesets(); fn++)
        {
            //eventually, there will be a means to load multiple images per tileset. TODO: Make a loop that allows it.
            //TODO: Write it so that it also works with
            string Filenname = ResDir + getTileset(fn).getImage(0).getFilename();
            TileSurf[fn] = IMG_Load(Filenname.c_str());
            if (!TileSurf[fn]) return;
        }

        unsigned long color = getTileset(0).getImage(0).getTrans();
        SDL_Color CKey;
        CKey.r = (color & 0xFF0000)   >> 16;
        CKey.g = (color & 0x00FF00)   >> 8 ;
        CKey.b = (color & 0x0000FF)        ;
        SDL_SetColorKey( MapSurf , SDL_TRUE , SDL_MapRGB(TileSurf[0]->format , CKey.r , CKey.g , CKey.b));
        SDL_Rect SrcRect;
        SDL_Rect DstRect;
        DstRect.h = getTileHeight();
        DstRect.w = getTileWidth();
        unsigned char **in_data  = new unsigned char* [getNumLayers()];
        unsigned char **out_data = new unsigned char* [getNumLayers()];
        unsigned int **tiledata = (unsigned int **) out_data;
        for(unsigned i = 0; i < getNumLayers(); i++)
        {
            in_data[i]  = new unsigned char [getLayer(i).getData().getData().size()];
            out_data[i] = new unsigned char [getWidth()*getHeight()*4];
            memcpy( in_data[i] , getLayer(i).getData().getData().c_str() , getLayer(i).getData().getData().size() );
            unsigned char *dec_data = new unsigned char[( getLayer(i).getData().getData().size())];
            TMX_Decode( in_data[i] , dec_data , getLayer(i).getData().getData().size() );
            TMX_Uncompress( dec_data , out_data[i] , ( getLayer(i).getData().getData().size() ), getWidth() * getHeight() * 4,
                           getLayer(i).getData().getCompression().c_str());
        }

        delete[]in_data;

        for (unsigned l = 0; l < TMX_Map::getNumLayers(); l++)
        {

            LayerSurf.push_back(SDL_CreateRGBSurface(0, getWidth()*getTileWidth(), getHeight()*getTileHeight(), 32, rmask, gmask, bmask, amask));
            SDL_SetSurfaceAlphaMod(LayerSurf[l], getLayer(l).getOpacity() * 255);
            for(unsigned int y = 0; y < getHeight(); y++)
            {
                DstRect.y = y * getTileHeight();
                for (unsigned int x = 0; x  < getWidth(); x++)
                {
                    if(tiledata[l][y*getWidth()+x])
                    {
                        DstRect.x = x * getTileWidth();
                        unsigned tilesetindex = findTileset(tiledata[l][y*getWidth()+x]);
                        unsigned srcindex = tiledata[l][y*getWidth()+x] - getTileset(tilesetindex).getGID();
                        SrcRect.h = getTileset(tilesetindex).getTileHeight();
                        SrcRect.w = getTileset(tilesetindex).getTileWidth();
                        float Float_TPL = (float) getTileset(tilesetindex).getImage(0).getWidth()
                                                  / (getTileset(tilesetindex).getTileWidth() + getTileset(tilesetindex).getSpacing());
                        unsigned long Tiles_Per_Line = (long) ceil(Float_TPL);
                        SrcRect.x = srcindex % Tiles_Per_Line * (getTileset(tilesetindex).getTileWidth() + getTileset(tilesetindex).getSpacing());
                        SrcRect.y = srcindex / Tiles_Per_Line * (getTileset(tilesetindex).getTileWidth() + getTileset(tilesetindex).getSpacing());
                        if( SDL_BlitSurface(TileSurf[tilesetindex], &SrcRect, LayerSurf[l], &DstRect) )
						{
							cout << "SDL_BlitSurface Failed: " << SDL_GetError() << endl;
							// if for some reason the application does not implode and instead run this code, we need to know why it crapped us.
							exit (-2);
						}
                    }
                }
            }
            if(getLayer(l).isVisible()) SDL_BlitSurface(LayerSurf[l],NULL, MapSurf, NULL);
        }

        delete[] tiledata;
        for (unsigned l = 0; l < getNumTilesets(); l++)
            SDL_FreeSurface(TileSurf[l]);

        MapTex = SDL_CreateTextureFromSurface(Render, MapSurf);
        SDL_FreeSurface(MapSurf);
    }
    else std::cout << "No way to Populate Map. Quitting..." << endl;
Esempio n. 19
0
	bool isInterestingAtCoord(float x, float y) const {
		return getTile(x / getTileWidth(), y / getTileHeight()).isInteresting;
	}
Esempio n. 20
0
	bool isInterestingAtCoord(const glm::vec2 &pos) {
		return getTile(pos.x / getTileWidth(), pos.y / getTileHeight()).isInteresting;
	}
Esempio n. 21
0
SDL_TMXMap::SDL_TMXMap(const char *Filename)
    :TMX_Map(Filename)
{
    MapSurf = SDL_CreateRGBSurface(0, getWidth()*getTileWidth(), getHeight()*getTileHeight(), 32, rmask, gmask, bmask, amask);
}