Esempio n. 1
0
void TerrainGrid::Init()
{
	myTiles.Init(ourTileGridSizeX * ourTileGridSizeY, 1000);

	Vector2f pos;
	Vector2f tileSize(ourTileSize, ourTileSize);

	int index = 0;
	for( index; index < ourTileGridSizeX * 10; ++index )
	{
		myTiles.Add( Tile() );
		myTiles[index].mySprite.SetTexture( 0, tileSize );
		pos = Vector2f( ourTileSize * (index % ourTileGridSizeX), ourTileSize * (index / ourTileGridSizeX));
		myTiles[index].mySprite.SetPosition( pos );
		myTiles[index].myIsSolid = false;
	}
	for( index; index < ourTileGridSizeX * ourTileGridSizeY; ++index )
	{
		myTiles.Add( Tile() );
		myTiles[index].mySprite.SetTexture( Renderer::GetInstance()->CreateTexture( "Sprites//Terrain//Grass.bmp" ), tileSize );
		pos = Vector2f( ourTileSize * (index % ourTileGridSizeX), ourTileSize * (index / ourTileGridSizeX));
		myTiles[index].mySprite.SetPosition( pos );
		myTiles[index].myIsSolid = true;
	}
}
Esempio n. 2
0
Tile World::GetTileAtPositionForCollision(const Position &position, const CollidableComponent *collidable) const
{
	auto colliders = GetComponentsOfType_const(CTYPE_COLLIDABLE);
	for (auto collider = colliders.begin(); collider != colliders.end(); ++collider)
	{
		const CollidableComponent *cleanCollider = static_cast<const CollidableComponent*>(*collider);
		if (cleanCollider->collisionInfo[INFOTYPE_LOGICAL_SPRITE] != collidable->collisionInfo[INFOTYPE_LOGICAL_SPRITE] &&
			cleanCollider->collisionInfo[INFOTYPE_SPRITE] != collidable->collisionInfo[INFOTYPE_SPRITE])
		{
			const TransformComponent *colliderTransform =
				cleanCollider->owner->GetComponentDirectly<TransformComponent>(CTYPE_TRANSFORM);
			if (colliderTransform && colliderTransform->position.IsEqual(position))
			{
				return Tile(cleanCollider->collisionInfo[INFOTYPE_SPRITE],
							cleanCollider->collisionInfo[INFOTYPE_LOGICAL_SPRITE], position);
			}
		}
	}

	if (levels[currentLevelIdx].IsPositionInsideMap(position))
	{
		return levels[currentLevelIdx].GetMap().GetTileAtPosition(position);
	}
	else
	{
		return Tile(' ', ' ', position);
	}
}
Esempio n. 3
0
Tile& WorldGenerator::generateTile( const Point& targetTilePosition, Tile& target ) const noexcept
{
	double heightValue = finalTerrain.GetValue( (double)( targetTilePosition.x ) / csScale, (double)( targetTilePosition.y ) / csScale, 0 );
	if( heightValue >= 0.6 )
	{
		target = Tile( &mDataset.getObject< TileSubtype >( "stone" ), heightValue * csHeightMultiplier);
	}
	else if( heightValue >= 0.5 )
	{
		target = Tile( &mDataset.getObject< TileSubtype >( "dirt" ), heightValue * csHeightMultiplier);
	}
	else if( heightValue >= -0.05 )
	{
		target = Tile( &mDataset.getObject< TileSubtype >( "grass" ), heightValue * csHeightMultiplier);
		if( heightValue >= 0 and heightValue <= 0.45  and ( rand() % 50 ) == 1 )
		{
			mWorld.addEntity< Entity >( targetTilePosition,
				&mDataset.getObject< EntitySubtype >( "tree" ),
				mWorld );
		}
	}
	else if( heightValue >= -0.2 )
	{
		target = Tile( &mDataset.getObject< TileSubtype >(  "sand" ), heightValue * csHeightMultiplier);
	}
	else if( heightValue < -0.2 )
	{
		target = Tile( &mDataset.getObject< TileSubtype >( "water" ), heightValue * csHeightMultiplier);
	}
	return target;
}
Esempio n. 4
0
    Map(std::vector<bool> &visible, const tmx::Map& source)
    {
        // Let's build tilesets
        for(auto tileset : source.getTilesets())
            tilesets.push_back(Tileset(tileset));
           
        // The following part assumes we have only one tileset 
        unsigned tilesetwidth = tilesets[0].image.getSize().x / tilesets[0].tilewidth;

        int i = 0;
        for(auto layer : source.getLayers())
        {
            int j = 0;
            layers.push_back(std::vector<Tile>());
            visible.push_back(layer->getVisible());
            for(auto tile : layer->getData())
            {
                // Position of the tile on the tileset
                sf::Vector2i post(((tile.getId() - tilesets[0].firstgid) % tilesetwidth) * tilesets[0].tilewidth,
                                  ((tile.getId()-tilesets[0].firstgid) / tilesetwidth) * tilesets[0].tileheight
                                 );
                // Dimensions of the tile according to the tileset
                sf::Vector2i dim(tilesets[0].tilewidth, tilesets[0].tileheight);
                
                sf::IntRect rec(post, dim);
                
                // Position of the tile on the view
                sf::Vector2f pos((j % source.getWidth()) * tilesets[0].tilewidth, (j / source.getWidth()) * tilesets[0].tileheight);
                
                layers[i].push_back(Tile(tilesets[0].image, rec, pos));
                j++;
            }
            i++;
        }
        
        for(auto objectgroup : source.getObjectgroups())      
        {
            layers.push_back(std::vector<Tile>());
            for(auto object : *objectgroup)
            {
                // Position of the object on the tileset
                sf::Vector2i post(((object.getId() - tilesets[0].firstgid) % tilesetwidth) * tilesets[0].tilewidth,
                                  ((object.getId()-tilesets[0].firstgid) / tilesetwidth) * tilesets[0].tileheight
                                 );
                                 
                // Dimensions of the object according to the tileset                 
                sf::Vector2i dim(tilesets[0].tilewidth, tilesets[0].tileheight);
                
                sf::IntRect rec(post, dim);
                
                // Position of the tile on the view. Do NOT forget the offset due to Tile Map Editor positioning conventions.
                sf::Vector2f pos(object.getX(),object.getY()-tilesets[0].tileheight);
                
                layers[i].push_back(Tile(tilesets[0].image, rec, pos));
            }
        }
    }
Esempio n. 5
0
Tile Map::GetTile(int row, int col) const
{
	//tile Range Check

	if (row < 0 || row >= MAP_ROW) return Tile();
	if (col < 0 || col >= MAP_COL) return Tile();

	return m_Tiles[row][col];
}
Esempio n. 6
0
File: Map.cpp Progetto: anliec/Mosp
Map::Map(std::string filePath)
{
    try{
        std::ifstream myStream(filePath);

        if(myStream)
        {
            char c;
            int line = 0;
            int i=0;
            while(myStream.get(c))
            {
                if(c != '\n')
                {
                    if(i >= tiles.size())
                    { //if the column doesn't exist
                        std::vector<Tile> column;
                        tiles.push_back(column); //add the column
                        //add the missing lines:
                        for (int y = 0; y < line; ++y)
                        {
                            tiles.at(i).push_back(Tile(Coordinate(i,line),TILE_UNWALKABLE));
                        }
                    }
                    int type;
                    if(std::isdigit(c))
                    {
                        type = std::atoi(&c);
                    }
                    else
                    {
                        type = TILE_UNWALKABLE;
                    }
                    tiles.at(i).push_back( Tile(Coordinate(i,line),type));
                    i++;
                }
                else
                {
                    i=0;
                    line++;
                }
            }
        }
        else
        {
            std::cerr << "ERROR WHEN LOADING FILE: " << filePath << std::endl;
        }
        myStream.close();
    }
    catch(std::exception const& e)
    {
        std::cerr << "ERROR WHEN LOADING FILE: " << filePath << std::endl << e.what() << std::endl;
        throw;
    }

}
const GenericTiledMap::Tile &GenericTiledMap::Layer::getTile(const int cell_x, const int cell_y)
{
    if(cell_y < 0 || cell_y >= v_tiles.size())
        return Tile(cell_x, cell_y, 0);
    
    if(cell_x < 0 || cell_x >= v_tiles[0].size())
        return Tile(cell_x, cell_y, 0);
    
    return (v_tiles[cell_y][cell_x]);
}
Esempio n. 8
0
File: Map.cpp Progetto: coquicox/jeu
void Map::loadMap(std::string name)
{
	sf::Image topo;
	topo.loadFromFile("media/map/" + name + ".png");
	m_width = topo.getSize().x;
	m_heigth = topo.getSize().y;

	for (int i = 0; i < m_width; i++) {
		m_tiles.push_back(vector<Tile>(m_heigth));
	}
	srand((unsigned int)time(NULL));
	std::cout << "Chargement de la map" << std::endl;

	for (unsigned int i = 0; i < m_width; i++) {
		for (unsigned int j = 0; j < m_heigth; j++) {
			sf::Color color = topo.getPixel(i, j);

			if (color == sf::Color(0,255,0)) {
				m_tiles[i][j] = Tile(TypeCase::PLAINE);
			}
			else if (color == sf::Color(0,176,0)) {
				m_tiles[i][j] = Tile(TypeCase::FORET);
			}
			else if (color == sf::Color(131,193,42)) {
				m_tiles[i][j] = Tile(TypeCase::MARAIS);
			}
			else if (color == sf::Color(0,0,255)) {
				m_tiles[i][j] = Tile(TypeCase::MER);
			}
			else if (color == sf::Color(159,128,5)) {
				m_tiles[i][j] = Tile(TypeCase::MONTAGNE);
			}
			else if (color == sf::Color(193,163,42)) {
				m_tiles[i][j] = Tile(TypeCase::COLINE);
			}
			else if (color == sf::Color(112,112,112)) {
				m_tiles[i][j] = Tile(TypeCase::RUINE);
			}
			else if (color == sf::Color(0,0,0)) {
				m_tiles[i][j] = Tile(TypeCase::VILLE);
			}
			else if (color == sf::Color(255,255,0)) {
				m_tiles[i][j] = Tile(TypeCase::PLAGE);
			}
			else {
				std::cerr << "Pixel (" <<i<<','<<j<<") de couleur inconnue"<< std::endl;
				std::string str = "Couleur (" + to_string(color.r) + ',' + to_string(color.g) + ',' + to_string(color.b) + ',' + to_string(color.a) + ')';
				std::cerr << str << std::endl;
				sf::Clock clock;
				clock.restart();
				while (clock.getElapsedTime().asSeconds() < 5) {

				}
				exit(EXIT_FAILURE);
			}
		}
	}
	std::cout << "Chargement termin�" << std::endl;
}
Esempio n. 9
0
Maze::Tile Maze::getTile(int x, int y) const
{
    // If out of bounds, return a wall tile
    if (x < 0 || (unsigned)x >= mWidth)
        return Tile(Tile::External);

    if (y < 0 || (unsigned)y >= mHeight)
        return Tile(Tile::External);

    return mMaze[y][x];
}
Esempio n. 10
0
void GameMap::createMap(){
	for (int i = 0; i < size_x; i++){
		for (int j = 0; j < size_y; j++){
			if (i == 2 && j == 2){
				map[i][j] = Tile("WALL", "Iron", 2, "ROCK WALL", "ROCK WALL", false);
			}
			else{
				map[i][j] = Tile("GRASS", "Grass", 0, "GRASS", "GRASS", true);
			}
		}
	}
}
Esempio n. 11
0
int main() {
	sf::Vector2i levelSize(30, 20);
	sf::Vector2i tileSize(32, 32);
	sf::RenderWindow window(sf::VideoMode(levelSize.x * tileSize.x, levelSize.y * tileSize.y), "Cellular Automata Cave Generation");
	window.setVerticalSyncEnabled(true);

	sf::Texture texture;
	if (!texture.loadFromFile("tileset.png")) {
		std::cout << "Unable to load the texture" << std::endl;
		return 0;
	}
	Tile tileset[] = {
		Tile(texture, sf::IntRect(tileSize.x, 0, tileSize.x, tileSize.y)),
		Tile(texture, sf::IntRect(0, 0, tileSize.x, tileSize.y))
	};
	sf::Font font;
	if (!font.loadFromFile("LCD_Solid.TTF")) {
		std::cout << "Unable to load the font" << std::endl;
		return 0;
	}
	sf::String str(" FPS\n\nPRESS 'G' TO GENERATE A NEW CAVE");
	sf::Text text(str, font, 10);
	text.setPosition(10, 10);
	text.setColor(sf::Color::White);

	TileMap tileMap(levelSize, tileSize, tileset);
	MapGenerator generator(levelSize.x, levelSize.y);
	generator.setIterations(4);
	generator.setDeathThreshold(3);
	generator.setBirthThreshold(4);
	generator.setChanceToStartAlive(50);
	
	int frameCount = 0;
	sf::Clock clock;
	while (window.isOpen()) {
		if (clock.getElapsedTime().asMilliseconds() >= 1000) {
			clock.restart();
			text.setString(std::to_string(frameCount) + str);
			frameCount = 0;
		}
		frameCount++;
		if (generateLevel) {
			tileMap.setMap(generator.generate());
			generateLevel = false;
		}
		processInput(window);
		window.draw(tileMap);
		window.draw(text);
		window.display();
	}
	return 0;
}
Esempio n. 12
0
AnimToolBar::AnimToolBar(){
    //set caption of window
    setCaption("Select Animation Type");

    //load images
    InfraellyImageLoader loader;

    //load tileset buttons as tileset
    cache::tilesets.loadResource("tilesets/animatorButtons.xml");
    //store the pointer locally to make code more readble
    Tileset *btn_ptr = cache::tilesets.get("tilesets/animatorButtons.xml");

    //initialise buttons with tiles from above tileset
    typeItemBtn = new gcn::ImageButton(   loader.load( Tile(btn_ptr, 0, 0)  )   );
    typeCharBtn = new gcn::ImageButton(   loader.load( Tile(btn_ptr, 1, 0)  )   );
    typeObjectBtn = new gcn::ImageButton( loader.load( Tile(btn_ptr, 2, 0)  )   );
    typeClipBtn = new gcn::ImageButton(   loader.load( Tile(btn_ptr, 3, 0)  )   );

    // set sizes
    typeItemBtn->setFrameSize(0);
    typeCharBtn->setFrameSize(0);
    typeObjectBtn->setFrameSize(0);
    typeClipBtn->setFrameSize(0);

    //set othr properties
    typeItemBtn->setFocusable(false);
    typeCharBtn->setFocusable(false);
    typeObjectBtn->setFocusable(false);
    typeClipBtn->setFocusable(false);


    //position stuff
    typeItemBtn->setPosition(0, 0);
    typeCharBtn->setPosition(typeItemBtn->getX()+typeItemBtn->getWidth(), 0);
    typeObjectBtn->setPosition(typeCharBtn->getX()+typeCharBtn->getWidth(), 0);
    typeClipBtn->setPosition(typeObjectBtn->getX()+typeObjectBtn->getWidth(), 0);


    //set colours


    //add
    add(typeItemBtn);
    add(typeCharBtn);
    add(typeObjectBtn);
    add(typeClipBtn);

    resizeToContent();
}
Esempio n. 13
0
void Nappaform::fLoad()
{
			frameCount = 0;
			offScreenBitmap = gcnew Bitmap(width, height);
			offScreenCanvas = Graphics::FromImage(offScreenBitmap);
			random = gcnew Random();
			runLeft = gcnew Bitmap("playerRunLeft.bmp");
			runRight = gcnew Bitmap("playerRunRight.bmp");
			mainCanvas = CreateGraphics();

			//Tilemaps
			whiteSquare = gcnew Bitmap("tiles.bmp");
			blackSquare = gcnew Bitmap("tileBlack.bmp");
			tile = gcnew Tile(whiteSquare, true);
			tile2 = gcnew Tile(blackSquare, false);
			tileList = gcnew TileList(2);
			tileList->setTileArrayEntry(tile);
			tileList->setTileArrayEntry(tile2);
			
			//Create the tile map
			tileMap = gcnew TileMap(tileList, offScreenCanvas, TILES_WIDE, TILES_HIGH, TILE_SIDE);

			tileMap->loadFromFile("whiteRoom.csv");

			//TileMaps

			//Viewport

			//Create the view port
			viewPort = gcnew ViewPort(0,0,VP_TILE_WIDE,VP_TILE_HIGH,Width,Height,tileMap, offScreenCanvas, TILE_SIDE);
			
			//ViewPort
			playerList = gcnew SpriteList();

			playerFileNames = gcnew array<String^>{
			"playerRunR.bmp",
			"player5.bmp",
			"playerRun.bmp",
			"player5.bmp"
			};

			int boundX = TILES_WIDE * TILE_SIDE;
			int boundY = TILES_HIGH * TILE_SIDE;

			player = gcnew Player(tileMap, offScreenCanvas, playerFileNames, random, 8, Rectangle(0,0,boundX, boundY),BOUNCE);
			
			playerList->addSprite(player);
			
}
Esempio n. 14
0
void Map::make_rectangle(int x, int y, int width, int height) {
    for(int i = x; i < x + width; i++) {
        for(int j = y; j < y + height; j++) {
            if(i == x || i == x + width - 1 || j == y || j == y + height - 1) {
                // We're on the border. Set a border tile if there's not ile set already
                if(!map.count(std::make_pair(i, j))) {
                    setTile(i, j, Tile('#', false));
                }
            } else {
                // We need to carve out a passable place
                setTile(i, j, Tile('.', true));
            }
        }
    }
}
Esempio n. 15
0
void PathView::drawBackground(QPainter *painter, const QRectF &rect)
{
	if ((_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
	  || !_map) {
		painter->fillRect(rect, Qt::white);
		return;
	}

	qreal scale = mapScale(_zoom);
	QRectF rr(rect.topLeft() * scale, rect.size());
	QPoint tile = mercator2tile(QPointF(rr.topLeft().x(), -rr.topLeft().y()),
	  _zoom);
	QPointF tm = tile2mercator(tile, _zoom);
	QPoint tl = mapToScene(mapFromScene(QPointF(tm.x() / scale,
	  -tm.y() / scale))).toPoint();

	QList<Tile> tiles;
	for (int i = 0; i <= rr.size().width() / Tile::size() + 1; i++) {
		for (int j = 0; j <= rr.size().height() / Tile::size() + 1; j++) {
			tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom));
		}
	}

	_map->loadTiles(tiles, _plot);

	for (int i = 0; i < tiles.count(); i++) {
		Tile &t = tiles[i];
		QPoint tp(tl.x() + (t.xy().x() - tile.x()) * Tile::size(),
		  tl.y() + (t.xy().y() - tile.y()) * Tile::size());
		painter->drawPixmap(tp, t.pixmap());
	}
}
Esempio n. 16
0
/*!
 * \param File The file in which load the map
 * \param Table The file in which load the correspondence table of the tiles
 */
void Map::Reload(const std::string &File, const std::string &Table)
{
    std::map < char, TileAttributes > m;
    std::string s;

    // Loading the correspondence table <Tile id>/<Tile informations>
    std::ifstream table(Table.c_str(), std::ios::in | std::ios::binary);
    while (std::getline(table, s, '\n'))
        if (s.length() > 2)
            m.insert(std::make_pair(s[0], TileAttributes(s.substr(2), s[1])));
    table.close();

    // Loading the map itself from the file
    size_t y = 0, x;
    std::ifstream file(File.c_str(), std::ios::in | std::ios::binary);
    while (std::getline(file, s))
    {
        x = 0;
        for (std::string::const_iterator i = s.begin() ; i != s.end() ; ++i)
        {
            if (*i == 'M')
            {
                myMarioPosX = x;
                myMarioPosY = y;
            }
            myTiles.push_back(Tile(m[*i].Filename, m[*i].Attributes, x
                    * TILES_WIDTH, y * TILES_HEIGHT));
            ++x;
        }
        ++y;
    }
    file.close();
    myMaxX = x - 1;
    myMaxY = y - 1;
}
void GoogleMapWidget::paintGL()
{
	glClearColor(0, 0, 0, 0);
	glClear(GL_COLOR_BUFFER_BIT);

	BitmapCoordinate tileIterator = center - QPoint(width() / 2, height() / 2);
	for(int y=0; y<gridHeight; ++y) {
		for(int x=0; x<gridWidth; ++x) {
			GLint bindId = 0;
			QString tileId = Tile(tileIterator).id();

			if(boundTiles.contains(tileId))
				bindId = boundTiles.value(tileId);
			else if(!tileCache.isTileLoading(tileId))
				tileCache.retrieveBitmap(tileId);

			if(bindId != 0) {
				glBindTexture(GL_TEXTURE_2D, bindId);
				glDrawArrays(GL_TRIANGLE_STRIP, (x + (y * gridWidth)) * 4, 4);
			}

			tileIterator.rx() += Tile::SIZE;
		}

		tileIterator.ry() += Tile::SIZE;
		tileIterator.rx() -= Tile::SIZE * gridWidth;
	}
}
Esempio n. 18
0
int main(void){
	std::srand(time(NULL));
	printf("{");
	for(unsigned int i=0;i<10;i++){
		for(unsigned int j=0;j<10;j++){
			printf("%d,",rand()%2);
		}
		printf("\n");
	}
	printf("}");
	unsigned int myArray[10][10]=  {1,0,0,0,0,1,1,1,1,0,
									0,0,1,0,1,1,1,0,1,0,
									1,0,0,1,1,1,0,0,0,1,
									0,0,0,1,0,0,0,0,1,1,
									0,1,1,1,0,1,0,1,1,0,
									1,0,0,0,1,1,1,1,1,1,
									1,0,1,1,1,0,1,1,0,0,
									0,0,1,0,1,1,1,0,1,0,
									0,0,0,0,0,1,1,1,0,0,
									1,1,0,0,0,1,0,1,0,0,
									};
	Tile gameLevel[10][10];
	for(unsigned int i=0;i<10;i++){
		for(unsigned int j=0;j<10;j++){
			gameLevel[i][j]=Tile(myArray[i][j]);
		}
	}
	printf("Done");

	return 0;
}
Esempio n. 19
0
	World::World(const int &ROWS, const int &COLS, const int &SMOOTH_LEVEL, const int &GRASS_CHANCE) :
		Map(ROWS, COLS), 
		SMOOTH_LEVEL(SMOOTH_LEVEL), 
		GRASS_CHANCE(GRASS_CHANCE)
	{	
		for(int y = 0; y < ROWS; y++)
		{
			for(int x = 0; x < COLS; x++)
			{
				Tile::TileType type = GetRandomTileType();
				At(x, y) = Tile(x, y, type);
			}
		}

		for(int i = 0; i < SMOOTH_LEVEL; i++)
		{
			if(i == SMOOTH_LEVEL - 1)
			{
				CreateBorder();
			}
			CellularAutomata();
		}

		int numDungeonsToCreate = GameMath::Random(ROWS/2, ROWS/3);
		for (int i = 0; i < numDungeonsToCreate; i++)
		{
			Vector2 newDungeonCoords;
			bool otherDungeonNear = true;

			while(otherDungeonNear)
			{
				otherDungeonNear = false;
				newDungeonCoords = *GetFreeTileCoords(COLS, ROWS);

				const int DUNGEON_PADDING = 3;
				int x = newDungeonCoords.x - DUNGEON_PADDING;
				int y = newDungeonCoords.y - DUNGEON_PADDING;
				int xMax = newDungeonCoords.x + DUNGEON_PADDING;
				int yMax = newDungeonCoords.y + DUNGEON_PADDING;

				for (; y < yMax; y++)
				{
					for (; x < xMax; x++)
					{
						if(!IsOutOfBounds(x, y) && At(x, y).type == Tile::DOOR 
							&& (x != newDungeonCoords.x && y != newDungeonCoords.y))
						{
							otherDungeonNear = true;
							break;
						}
					}
				}
			}

			At(newDungeonCoords).type = Tile::DOOR;
		}

		entryCoords = GetFreeTileCoords(COLS, ROWS);
		spawnCoords = entryCoords;
	}
Esempio n. 20
0
EXPORT_C void CEikScrollBarFrame::Tile(TEikScrollBarModel* aVModel, TRect& aVScrollBarRect)
    {
	Tile(aVModel);
	TRect tempRect(aVScrollBarRect);
    if(aVScrollBarRect.Height() < 0 )
        {
        aVScrollBarRect.iTl.iY = aVScrollBarRect.iBr.iY;
        aVScrollBarRect.iBr.iY = tempRect.iTl.iY;
        }
    if(aVScrollBarRect.Width() < 0 )
        {
        aVScrollBarRect.iTl.iX = aVScrollBarRect.iBr.iX;
        aVScrollBarRect.iBr.iX = tempRect.iTl.iX;
        }
    if (iV.iBar && TypeOfVScrollBar() == EDoubleSpan && iV.iExternalScrollBarAttached==EFalse )
        {
        CAknDoubleSpanScrollBar* scrollbar = static_cast <CAknDoubleSpanScrollBar*> (iV.iBar);
        // check if fixed layout has been set
        if (scrollbar->FixedLayoutRect().Size() == TSize(0,0))
            {
            if (aVScrollBarRect != TRect(iV.iBar->Position(), iV.iBar->Size()))
                {
                iV.iBar->SetRect(aVScrollBarRect);
                }
            }
        }
    }
Esempio n. 21
0
bool TILEMAP::PlaceFree(const sf::FloatRect& rect) const
{
    if ( (rect.left+rect.width <= 0.f) || (rect.top+rect.height <= 0.f) )
        return true;

    int left = static_cast<int>(rect.left);
    int top = static_cast<int>(rect.top);
    int right = static_cast<int>(rect.left + rect.width);
    int bottom = static_cast<int>(rect.top + rect.height);

    if (right < (rect.left + rect.width))
        right++;
    if (bottom < (rect.top + rect.height))
        bottom++;

    int xstart = left / tileSize;
    int xend = (right-1) / tileSize;
    int ystart = top / tileSize;
    int yend = (bottom-1) / tileSize;

    for (int x=xstart; x<=xend; x++)
    {
        for (int y=ystart; y<=yend; y++)
        {
            if (Tile(x,y) > 0)
            {
                return false;
            }
        }
    }
    return true;
}
const GenericTiledMap::Tile &GenericTiledMap::getTile(const int cell_x, const int cell_y, const int layer)
{
    if( layer < 0 || layer >= v_layers.size() )
        return Tile(cell_x, cell_y, 0);

    return v_layers[layer].getTile(cell_x, cell_y);
}
Esempio n. 23
0
void Map::generate(TCODRandom* random) {
    // Generate a random map
    
    // Throw out the old map
    map.clear();
    
    int numRooms = random->getInt(20, 30);
    
    for(int i = 0; i < numRooms; i++) {
        // Make some rooms
        make_rectangle(random->getInt(0, 20), random->getInt(0, 20), random->getInt(3, 10), random->getInt(3, 10));
    }
    
    // Flood fill from a single point and delete everything else.
    std::set<std::pair<int, int>> reachable;
    
    // We need to remember what we already queued
    std::set<std::pair<int, int>> tested;
    // Start at a random place and flood fill from there.
    std::list<std::pair<int, int>> queue = {findEmpty(random)};
    
    while(queue.size() > 0) {
        // Grab a random place
        auto toVisit = queue.front();
        queue.pop_front();
        
        if(getTile(toVisit.first, toVisit.second).isPassable()) {
            // We can go here!
            
            // This tile is reachable
            reachable.insert(toVisit);
            
            std::vector<std::pair<int, int>> offsets = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
            for(auto offset : offsets) {
                auto nextToVisit = std::make_pair(toVisit.first + offset.first, toVisit.second + offset.second);
                
                if(!tested.count(nextToVisit)) {
                
                    // Try this potentially reachable spot next.
                    queue.push_back(nextToVisit);
                    // Don't queue it again
                    tested.insert(nextToVisit);   
                }
                
            }
        }
    }
    
    for(auto& kv : map) {
        if(!reachable.count(kv.first) && kv.second.isPassable()) {
            // This is a passable place that isn't reachable.
            
            // Make it impassable as a hack. The player will never know because
            // they can never get there, but it won't be chosen when we ask for
            // a passable spot.
            kv.second = Tile(kv.second.getCharacter(), false);
        }
    }
    
}
Esempio n. 24
0
void Board::slideRight() {
	for (int i = 0; i < 2; i++) {

		Tile boardCopy[boardWidth][boardHeight];
		std::copy(&board[0][0], &board[0][0] + boardWidth*boardHeight, &boardCopy[0][0]);

		for (int x = 0; x < 4; x++) {
			for (int y = 3; y >= 0; y--) {
				if (boardCopy[x][y].value == 0) {
					for (int k = y - 1; k >= 0; k--) {
						if (boardCopy[x][k].value != 0) {
							boardCopy[x][y] = boardCopy[x][k];

							boardCopy[x][y].xPos = x;
							boardCopy[x][y].yPos = y;

							boardCopy[x][k] = Tile(Tile::TileColor::EMPTY, x, k, 0);
							break;

						}
					}
				}
			}
		}

		std::copy(&boardCopy[0][0], &boardCopy[0][0] + boardWidth*boardHeight, &board[0][0]);

		if (i == 0) {
			mergeRight();
		}

	}
}
Esempio n. 25
0
void Board::slideUp() {
	for (int i = 0; i < 2; i++) {

		Tile boardCopy[boardWidth][boardHeight];
		std::copy(&board[0][0], &board[0][0] + boardWidth*boardHeight, &boardCopy[0][0]);

		for (int y = 0; y < 4; y++) {
			for (int x = 0; x < 4; x++) {
				if (boardCopy[x][y].value == 0) {
					for (int k = x + 1; k < 4; k++) {
						if (boardCopy[k][y].value != 0) {
							boardCopy[x][y] = boardCopy[k][y];

							boardCopy[x][y].xPos = x;
							boardCopy[x][y].yPos = y;

							boardCopy[k][y] = Tile(Tile::TileColor::EMPTY, k, y, 0);
							break;

						}
					}
				}
			}
		}

		std::copy(&boardCopy[0][0], &boardCopy[0][0] + boardWidth*boardHeight, &board[0][0]);

		if (i == 0) {
			mergeUp();
		}

	}
}
Esempio n. 26
0
Tile OublietteLevel::tile(int x, int y) const
{
    if (y < 0 || x < 0 || y >= m_size.height() || x >= m_size.width())
        return Tile(); // bit of a lie, but it makes gereneration easier...

    return m_map[y * m_size.width() + x];
}
Esempio n. 27
0
void ObstacleMapper::mapObstacles()
{
	const int tilesWide = img->w / 16;
	const int tilesHigh = img->h / 16;

	int currentTile;
	TileKeeper* myTiles = new TileKeeper();

	bool isObstacle;
	ofstream obstacles;
	obstacles.open("hannah.txt", ios::app);

	/* iterates through all the image's 16x16 tiles and feeds their boolean value (isObstacle == 1 or isObstacle == 0)
	 to a txt file for processing */
	for (int y = 0; y < tilesHigh; y++)
	{
		for (int x = 0; x < tilesWide; x++)
		{
			isObstacle = calculateTile(x, y);

			// records the map tile in TileKeeper's map and the obstacles.txt file
			myTiles->recordTile(Tile(isObstacle, x, y), std::pair<int, int>(x, y));
			obstacles << isObstacle;

			if (x == tilesWide - 1)
			{
				obstacles << "\n";
			}
		}
	}

	// clean up
	delete myTiles;
	obstacles.close();
}
void MapParser::Stretch3 (int tx, int ty, int x, int y, int w, int h)
{
    //printf("\'St\' function called with arguments %d, %d, %d, %d, %d and %d.\n", tx, ty, x, y, w, h);

    keep_last_added_tile = false;

    Tile (tx, ty, x, y);
    Row (tx + 1, ty, x + TILE_SIZE, y, w - 2);
    Tile (tx + 2, ty, x + (w - 2)*TILE_SIZE, y);
    Col (tx, ty + 1, x, y + TILE_SIZE, h - 2);
    Tile (tx, ty + 2, x, y + (h - 2)*TILE_SIZE);
    Row (tx + 1, ty + 2, x + TILE_SIZE, y + (h - 2)*TILE_SIZE, w - 3);
    Col (tx + 2, ty + 1, x + (w - 2)*TILE_SIZE, y + TILE_SIZE, h - 3);
    Tile (tx + 2, ty + 2, x + (w - 2)*TILE_SIZE, y + (h - 2)*TILE_SIZE);
    Rect (tx + 1, ty + 1, x + TILE_SIZE, y + TILE_SIZE, w - 3, h - 3);
};
Esempio n. 29
0
void Board::slideDown() {
	for (int i = 0; i < 2; i++) {

		Tile boardCopy[boardWidth][boardHeight];
		//std::copy(std::begin(board), std::end(board), std::begin(boardCopy));
		std::copy(&board[0][0], &board[0][0] + boardWidth*boardHeight, &boardCopy[0][0]);

		for (int y = 0; y < 4; y++) {
			for (int x = 3; x >0; x--) {
				if (boardCopy[x][y].value == 0) {
					for (int k = x - 1; k >= 0; k--) {
						if (boardCopy[k][y].value != 0) {
							boardCopy[x][y] = boardCopy[k][y];

							boardCopy[x][y].xPos = x;
							boardCopy[x][y].yPos = y;

							boardCopy[k][y] = Tile(Tile::TileColor::EMPTY, k, y, 0);
							break;

						}
					}
				}
			}
		}

		std::copy(&boardCopy[0][0], &boardCopy[0][0] + boardWidth*boardHeight, &board[0][0]);

		if (i == 0) {
			mergeDown();
		}

	}
}
Esempio n. 30
0
void TileManager::set_tiles()
{
	int resolution = state.resolution;
	int image_w = max(1, params.width/resolution);
	int image_h = max(1, params.height/resolution);
	int tile_w = (tile_size >= image_w)? 1: (image_w + tile_size - 1)/tile_size;
	int tile_h = (tile_size >= image_h)? 1: (image_h + tile_size - 1)/tile_size;
	int sub_w = image_w/tile_w;
	int sub_h = image_h/tile_h;

	state.tiles.clear();

	for(int tile_y = 0; tile_y < tile_h; tile_y++) {
		for(int tile_x = 0; tile_x < tile_w; tile_x++) {
			int x = tile_x * sub_w;
			int y = tile_y * sub_h;
			int w = (tile_x == tile_w-1)? image_w - x: sub_w;
			int h = (tile_y == tile_h-1)? image_h - y: sub_h;

			state.tiles.push_back(Tile(x, y, w, h));
		}
	}

	state.buffer.width = image_w;
	state.buffer.height = image_h;

	state.buffer.full_x = params.full_x/resolution;
	state.buffer.full_y = params.full_y/resolution;
	state.buffer.full_width = max(1, params.full_width/resolution);
	state.buffer.full_height = max(1, params.full_height/resolution);
}