• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ TileLayer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中TileLayer的典型用法代码示例。如果您正苦于以下问题:C++ TileLayer类的具体用法?C++ TileLayer怎么用?C++ TileLayer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TileLayer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: getWidth

bool CollisionObject::isCollisionWithTileRight() {
	// iterate through collision layers
	for (std::vector<TileLayer*>::const_iterator it = m_pCollisionLayers->begin(); it != m_pCollisionLayers->end(); ++it) {
		TileLayer* pTileLayer = (*it);
		std::vector<std::vector<int>> tiles = pTileLayer->getTileIDs();
		// get this layers position
		Vector2D layerPos = pTileLayer->getPosition();
		int x, y, tileColumn, tileRow, tileid = 0;
		// calculate position on tile map
		x = layerPos.getX() / pTileLayer->getTileSize();
		y = layerPos.getY() / pTileLayer->getTileSize();

		if (getVelocity().getX() > 0) //dreta
		{
			tileColumn = ((getPosition().getX() + Camera::Instance()->getPosition().getX() + getWidth()) / pTileLayer->getTileSize());
			tileRow = (getPosition().getY() / pTileLayer->getTileSize());
			tileid = tiles[tileRow+y][tileColumn + x];//Li restem 1 a la y perque quan estiguem asobre la plataforma no ens doni colisio
		}
		if (tileid != 0) // if the tile id not blank then collide
		{
			return true;
		}
	}
	return false;
}
开发者ID:MontseArch,项目名称:BaseCode,代码行数:25,代码来源:CollisionObject.cpp


示例2: flipped

/**
 * Returns a new stamp where all variations have been flipped in the given
 * \a direction.
 */
TileStamp TileStamp::flipped(FlipDirection direction) const
{
    TileStamp flipped(*this);
    flipped.d.detach();

    for (const TileStampVariation &variation : flipped.variations()) {
        TileLayer *layer = variation.tileLayer();

        if (variation.map->isStaggered()) {
            Map::StaggerAxis staggerAxis = variation.map->staggerAxis();

            if (staggerAxis == Map::StaggerY) {
                if ((direction == FlipVertically && !(layer->height() & 1)) || direction == FlipHorizontally)
                    variation.map->invertStaggerIndex();

            } else {
                if ((direction == FlipHorizontally && !(layer->width() & 1)) || direction == FlipVertically)
                    variation.map->invertStaggerIndex();
            }
        }

        if (variation.map->orientation() == Map::Hexagonal)
            layer->flipHexagonal(direction);
        else
            layer->flip(direction);
    }

    return flipped;
}
开发者ID:Shorttail,项目名称:tiled,代码行数:33,代码来源:tilestamp.cpp


示例3: startAnimation

/* ------------------------------------------------------------------------------
 * startAnimation - Attempts to start the next tile in the chained conveyor
 * belt animation.  Returns true if all tiles have been started.  For best
 * results, call this method each time a new screen frame is blitted.
 */
bool ConveyorAnimation::startAnimation() {
    if (this->nextTileToStart >= this->conveyorTiles.size()) {
        return true;
    }

    GridLayer* gl = GridLayer::GetInstance();

    TileLayer* currentTile = NULL;
    if (this->nextTileToStart == 0) {

        // Always start the first tile in the belt.
        TileCoord currentTileCoord = this->conveyorTiles[0];
        currentTile = gl->getTile(currentTileCoord.first, currentTileCoord.second);
        currentTile->getAnimation()->play();
        gl->pushAnimatedTile(currentTile);
        this->nextTileToStart++;

    } else {
        TileCoord currentTileCoord = this->conveyorTiles[this->nextTileToStart-1];
        currentTile = gl->getTile(currentTileCoord.first, currentTileCoord.second);

        if ((currentTile->getAnimation()->getCurrentStill()+1) % 8 == 0) {
            TileCoord tileCoord = this->conveyorTiles[this->nextTileToStart];
            TileLayer* tile = gl->getTile(tileCoord.first, tileCoord.second);
            tile->getAnimation()->play();
            gl->pushAnimatedTile(tile);

            this->nextTileToStart++;
        }
    }

    return (this->nextTileToStart >= this->conveyorTiles.size());

}
开发者ID:,项目名称:,代码行数:39,代码来源:


示例4: stampRegion

void StampBrush::configureBrush(const QVector<QPoint> &list)
{
    if (!mStamp)
        return;

    QRegion reg;
    QRegion stampRegion(mStamp->region());

    Map *map = mapDocument()->map();

    TileLayer *stamp = new TileLayer(QString(), 0, 0,
                                     map->width(), map->height());

    foreach (QPoint p, list) {
        const QRegion update = stampRegion.translated(p.x() - mStampX,
                                                      p.y() - mStampY);
        if (!reg.intersects(update)) {
            reg += update;
            stamp->merge(p, mStamp);
        }
    }

    brushItem()->setTileLayer(stamp);
    delete stamp;
}
开发者ID:Bananattack,项目名称:tiled,代码行数:25,代码来源:stampbrush.cpp


示例5: update

void Level::update()
{
	ObjectLayer * pObjects;
	for (int i = 0; i < m_layers.size(); ++i)
	{
		if (m_pPlayer->getPosition()->getX() + m_pPlayer->getWidth() > 635)
		{
			TileLayer * pTile = dynamic_cast<TileLayer*>(m_layers[i]);
			if (pTile && pTile->getNumColumns() + pTile->getColumnIncrement() < pTile->getTileIDs().at(0).size())
			{
 				pTile->setColumns(20);
				m_pPlayer->setPosition(Vector2D(10, 330));
				BulletHandler::Instance()->clearAll();
				scrollObjects();
			}
			else
			{
				m_pPlayer->setVelocity(Vector2D(0.0, 0.0));
			}
		}
		m_layers[i]->update();
		pObjects = dynamic_cast<ObjectLayer*>(m_layers[i]);
		if (pObjects)
		{
			CollisionManager::Instance()->checkEnemyPlayerBulletCollision(BulletHandler::Instance()->getBulletPlayer(), pObjects->getObjects());
		}
	}
	CollisionManager::Instance()->checkPlayerEnemyBulletCollision(m_pPlayer, BulletHandler::Instance()->getBulletEnemy());
	BulletHandler::Instance()->update();
	if (m_pPlayer->isDead())
	{
		Game::Instance()->getStateMachine()->changeState(new GameOverState());
	}
}
开发者ID:KyryloBR,项目名称:SDLEngine,代码行数:34,代码来源:Level.cpp


示例6: tilesetViewAt

void TilesetDock::deleteTilesetView(int index)
{
    TilesetDocument *tilesetDocument = mTilesetDocuments.at(index);
    tilesetDocument->disconnect(this);

    Tileset *tileset = tilesetDocument->tileset().data();
    TilesetView *view = tilesetViewAt(index);

    QString path = QLatin1String("TilesetDock/TilesetScale/") + tileset->name();
    QSettings *settings = Preferences::instance()->settings();
    if (view->scale() != 1.0)
        settings->setValue(path, view->scale());
    else
        settings->remove(path);

    mTilesets.remove(index);
    mTilesetDocuments.removeAt(index);
    delete view;                    // view needs to go before the tab
    mTabBar->removeTab(index);

    // Make sure we don't reference this tileset anymore
    if (mCurrentTiles && mCurrentTiles->referencesTileset(tileset)) {
        TileLayer *cleaned = mCurrentTiles->clone();
        cleaned->removeReferencesToTileset(tileset);
        setCurrentTiles(cleaned);
    }
    if (mCurrentTile && mCurrentTile->tileset() == tileset)
        setCurrentTile(nullptr);
}
开发者ID:Shorttail,项目名称:tiled,代码行数:29,代码来源:tilesetdock.cpp


示例7: DestroyEntityMsg

/*virtual*/ void Bullet::Update(float dt) /*override*/
{
	SGD::Rectangle rect;
	rect.top = m_ptPosition.y;
	rect.left = m_ptPosition.x;
	rect.Resize(bulletSize*dist);
	TileLayer *layer0 = World::GetInstance()->GetTileLayers()[0];
	if (rect.top < 0.0f
		|| rect.left < 0.0f
		|| rect.bottom >= layer0->layerRows * layer0->GetTileSize().width
		|| rect.right >= layer0->layerColumns * layer0->GetTileSize().height
		)
	{
		return;
	}

	// if this bullet goes outside bullet dropoff range...
	if (owner->GetOwner() && (m_ptPosition - startPoint).ComputeLength() > bulletDropOff)
	{
		// create a message to destroy this bullet
		DestroyEntityMsg* msg = new DestroyEntityMsg(this);

		// dispatch the destroy message
		SGD::MessageManager::GetInstance()->GetInstance()->QueueMessage(msg);
	}

	if (gunActive)
	{
		dist += 0.075f;
		if (dist > 1.75f)
			dist = 1.75f;
	}

	// if bullet collides with tile, play collision sound
	//if (owner->GetGunType() != Weapon::GunType::meleeWeapon)
		
	// if not, update bullet
	Entity::Update(dt);

	TileLayer* collisionLayer = GameplayState::GetInstance()->GetWorld()->GetTileLayers()[1];
	const SGD::Point ref_position = { m_ptPosition.x + m_szSize.width*0.5f, m_ptPosition.y + m_szSize.height*0.5f };
	const int tileSize_width = (int)collisionLayer->GetTileSize().width;
	const int tileSize_height = (int)collisionLayer->GetTileSize().height;
	const int tilesWide = collisionLayer->layerColumns - 1;
	const int tilesHigh = collisionLayer->layerRows - 1;
	SGD::Point index = { Math::Clamp((ref_position.x / (float)tileSize_width), 0.f, (float)tilesWide), Math::Clamp(ref_position.y / (float)tileSize_height, 0.f, (float)tilesHigh) };

	Tile* tile_at = collisionLayer->GetTileAt(int(index.x), int(index.y));

	if (tile_at && !tile_at->isPassable)
	{
		if (tile_at->event != "bp" && owner->GetGunType() != Weapon::GunType::meleeWeapon && owner->GetGunType() != Weapon::GunType::MutantAtk)
		{
			SGD::AudioManager::GetInstance()->PlayAudio(GameplayState::GetInstance()->bulletImpact);
			DestroyEntityMsg* msg = new DestroyEntityMsg(this);
			msg->QueueMessage();
		}
	}
}
开发者ID:DeVonFire27,项目名称:DTW_Desolate,代码行数:59,代码来源:Bullet.cpp


示例8: TileLayer

void LevelParser::parseTileLayer(TiXmlElement* pTileElement, std::vector<Layer*> *pLayers, const std::vector<Tileset>* pTilesets, std::vector<TileLayer*> *m_CollisionsLayer)
{
	TileLayer* pTileLayer = new TileLayer(m_tileSizew, m_tileSizeh, *pTilesets);
	bool collidable = false;

	std::vector<std::vector<int>> data;
	std::string decodedIDs;
	TiXmlElement* pDataNode;
	for (TiXmlElement* e = pTileElement->FirstChildElement(); e != NULL; e = e->NextSiblingElement())
	{
		if (e->Value() == std::string("properties"))
		{
			for (TiXmlElement* property = e->FirstChildElement(); property
				!= NULL; property = property->NextSiblingElement())
			{
				if (property->Value() == std::string("property"))
				{
					if (property->Attribute("name") == std::string("collidable"))
					{
						collidable = true;
					}
				}
			}
		}
		if (e->Value() == std::string("data"))
		{
			pDataNode = e;
		}
	}
	for (TiXmlNode* e = pDataNode->FirstChild(); e != NULL; e = e->NextSibling())
	{
		TiXmlText* text = e->ToText();
		std::string t = text->Value();
		decodedIDs = base64_decode(t);
	}

	uLongf numGids = m_width * m_height * sizeof(int);
	std::vector<unsigned> gids(numGids);
	uncompress((Bytef*)&gids[0], &numGids, (const Bytef*)decodedIDs.c_str(), decodedIDs.size());
	std::vector<int> layerRow(m_width);
	for (int j = 0; j < m_height; j++)
	{
		data.push_back(layerRow);
	}
	for (int rows = 0; rows < m_height; rows++)
	{
		for (int cols = 0; cols < m_width; cols++)
		{
			data[rows][cols] = gids[rows * m_width + cols];
		}
	}

	if (collidable)
	{
		m_CollisionsLayer->push_back(pTileLayer);
	}
	pTileLayer->setTileIDs(data);
	pLayers->push_back(pTileLayer);
}
开发者ID:paubereng,项目名称:BaseCode,代码行数:59,代码来源:LevelParser.cpp


示例9: TileLayer

TileLayer *StampBrush::getRandomTileLayer() const
{
    if (mRandomList.empty())
        return 0;

    TileLayer *ret = new TileLayer(QString(), 0, 0, 1, 1);
    ret->setCell(0, 0, mRandomList.at(rand() % mRandomList.size()));
    return ret;
}
开发者ID:ChicoTeam,项目名称:tiled,代码行数:9,代码来源:stampbrush.cpp


示例10: currentTileLayer

void TerrainBrush::capture()
{
    TileLayer *tileLayer = currentTileLayer();
    Q_ASSERT(tileLayer);

    // TODO: we need to know which corner the mouse is closest to...

    const Cell &cell = tileLayer->cellAt(tilePosition());
    Terrain *t = cell.tile->terrainAtCorner(0);
    setTerrain(t);
}
开发者ID:clintbellanger,项目名称:tiled,代码行数:11,代码来源:terrainbrush.cpp


示例11: flipped

/**
 * Returns a new stamp where all variations have been flipped in the given
 * \a direction.
 */
TileStamp TileStamp::flipped(FlipDirection direction) const
{
    TileStamp flipped(*this);
    flipped.d.detach();

    foreach (const TileStampVariation &variation, flipped.variations()) {
        TileLayer *layer = static_cast<TileLayer*>(variation.map->layerAt(0));
        layer->flip(direction);
    }

    return flipped;
}
开发者ID:dDave,项目名称:tiled,代码行数:16,代码来源:tilestamp.cpp


示例12: TileLayer

void LevelParser::parseTileLayer(TiXmlElement* pTileElement, std::vector<Layer*> *pLayers, const std::vector<Tileset>* pTilesets)
{
	TileLayer* pTileLayer = new TileLayer(m_tileSize, *pTilesets);

	// tile data
	std::vector<std::vector<int>> data;

	std::string decodedIDs;

	TiXmlElement* pDataNode = NULL;

	for (TiXmlElement* e = pTileElement->FirstChildElement(); e != NULL; e = e->NextSiblingElement())
	{
		if (e->Value() == std::string("data"))
		{
			pDataNode = e;
		}		
	}

	for (TiXmlNode* e = pDataNode->FirstChild(); e != NULL; e = e->NextSibling())
	{
		TiXmlText* text = e->ToText();

		std::string t = text->Value();

		decodedIDs = base64_decode(t);
	}

	// uncompress zlib compression
	uLongf numGids = m_width * m_height * sizeof(int);

	std::vector<unsigned> gids(numGids);

	uncompress((Bytef*)&gids[0], &numGids, (const Bytef*)decodedIDs.c_str(), decodedIDs.size());

	std::vector<int> layerRow(m_width);

	for (int j = 0; j < m_height; j++)
	{
		data.push_back(layerRow);
	}
	for (int rows = 0; rows < m_height; rows++)
	{
		for (int cols = 0; cols < m_width; cols++)
		{
			data[rows][cols] = gids[rows * m_width + cols];
		}
	}

	pTileLayer->setTileIDs(data);

	pLayers->push_back(pTileLayer);
}
开发者ID:El-Flexo,项目名称:SDL-game-dev,代码行数:53,代码来源:LevelParser.cpp


示例13: autocropMap

void MapDocument::autocropMap()
{
    if (!mCurrentLayer || !mCurrentLayer->isTileLayer())
        return;

    TileLayer *tileLayer = static_cast<TileLayer*>(mCurrentLayer);

    const QRect bounds = tileLayer->region().boundingRect();
    if (bounds.isNull())
        return;

    resizeMap(bounds.size(), -bounds.topLeft(), true);
}
开发者ID:stt,项目名称:tiled,代码行数:13,代码来源:mapdocument.cpp


示例14: Q_ASSERT

Layer *TileLayer::mergedWith(Layer *other) const
{
    Q_ASSERT(canMergeWith(other));

    const TileLayer *o = static_cast<TileLayer*>(other);
    const QRect unitedBounds = bounds().united(o->bounds());
    const QPoint offset = position() - unitedBounds.topLeft();

    TileLayer *merged = static_cast<TileLayer*>(clone());
    merged->resize(unitedBounds.size(), offset);
    merged->merge(o->position() - unitedBounds.topLeft(), o);
    return merged;
}
开发者ID:LucasGH,项目名称:tiled,代码行数:13,代码来源:tilelayer.cpp


示例15: Render

void Tile::Render()
{
	// For efficiency, we only render from lowest to highest
	// layer index
	for (size_t i=m_iLowLayerIdx; i<=m_iHighLayerIdx; ++i)
	{
		// Some layers may not have been set in between
		TileLayer* pTileLayer = m_tileLayerPtrs[i].get();

		if ( pTileLayer != NULL )
			pTileLayer->Render(m_pos.x, m_pos.y, m_size.w, m_size.h);
	}
}
开发者ID:amaiorano,项目名称:TheTetrisMaster,代码行数:13,代码来源:Tile.cpp


示例16: rotated

/**
 * Returns a new stamp where all variations have been rotated in the given
 * \a direction.
 */
TileStamp TileStamp::rotated(RotateDirection direction) const
{
    TileStamp rotated(*this);
    rotated.d.detach();

    for (const TileStampVariation &variation : rotated.variations()) {
        const QRect mapRect(QPoint(), variation.map->size());
        QSize rotatedSize;

        for (auto layer : variation.map->tileLayers()) {
            TileLayer *tileLayer = static_cast<TileLayer*>(layer);

            // Synchronize tile layer size to map size (assumes map contains all layers)
            if (tileLayer->rect() != mapRect) {
                tileLayer->resize(mapRect.size(), tileLayer->position());
                tileLayer->setPosition(0, 0);
            }

            if (variation.map->orientation() == Map::Hexagonal)
                tileLayer->rotateHexagonal(direction, variation.map);
            else
                tileLayer->rotate(direction);

            rotatedSize = tileLayer->size();
        }

        variation.map->setWidth(rotatedSize.width());
        variation.map->setHeight(rotatedSize.height());
    }

    return rotated;
}
开发者ID:bjorn,项目名称:tiled,代码行数:36,代码来源:tilestamp.cpp


示例17: randomFill

void BucketFillTool::randomFill(TileLayer &tileLayer, const QRegion &region) const
{
    if (region.isEmpty() || mRandomCellPicker.isEmpty())
        return;

    for (const QRect &rect : region.translated(-tileLayer.position()).rects()) {
        for (int _x = rect.left(); _x <= rect.right(); ++_x) {
            for (int _y = rect.top(); _y <= rect.bottom(); ++_y) {
                tileLayer.setCell(_x, _y,
                                  mRandomCellPicker.pick());
            }
        }
    }
}
开发者ID:Bertram25,项目名称:tiled,代码行数:14,代码来源:bucketfilltool.cpp


示例18: currentTileLayer

void StampBrush::endCapture()
{
    if (mBrushBehavior != Capture)
        return;

    mBrushBehavior = Free;

    TileLayer *tileLayer = currentTileLayer();
    Q_ASSERT(tileLayer);

    // Intersect with the layer and translate to layer coordinates
    QRect captured = capturedArea();
    captured.intersect(QRect(tileLayer->x(), tileLayer->y(),
                             tileLayer->width(), tileLayer->height()));

    if (captured.isValid()) {
        captured.translate(-tileLayer->x(), -tileLayer->y());
        TileLayer *capture = tileLayer->copy(captured);
        emit currentTilesChanged(capture);
        // A copy will have been created, so delete this version
        delete capture;
    } else {
        updatePosition();
    }
}
开发者ID:ChicoTeam,项目名称:tiled,代码行数:25,代码来源:stampbrush.cpp


示例19: foreach

void BucketFillTool::updateRandomList()
{
    mRandomList.clear();
    mMissingTilesets.clear();

    foreach (const TileStampVariation &variation, mStamp.variations()) {
        TileLayer *tileLayer = static_cast<TileLayer*>(variation.map->layerAt(0));
        mapDocument()->unifyTilesets(variation.map, mMissingTilesets);
        for (int x = 0; x < tileLayer->width(); x++)
            for (int y = 0; y < tileLayer->height(); y++)
                if (!tileLayer->cellAt(x, y).isEmpty())
                    mRandomList.append(tileLayer->cellAt(x, y));
    }
}
开发者ID:Ju2ender,项目名称:tiled,代码行数:14,代码来源:bucketfilltool.cpp


示例20: if

void CollisionManager::checkPlayerTileCollision(Player* pPlayer, 
        const std::vector<TileLayer*>& collisionLayers) {
    for(auto it = collisionLayers.begin(); 
            it != collisionLayers.end(); ++it) {
        TileLayer* pTileLayer = (*it);
        std::vector<std::vector<int>> tiles = pTileLayer->getTileIDs();
        
        Vector2D layerPos = pTileLayer->getPosition();
        
        int x, y, tileColumn, tileRow, tileid = 0;
        
        x = layerPos.getX() / pTileLayer->getTileSize();
        y = layerPos.getY() / pTileLayer->getTileSize();
        
        if(pPlayer->getVelocity().getX() >= 0 || pPlayer->getVelocity().getY() >= 0) {
            tileColumn = ((pPlayer->getPosition().getX() + 
                pPlayer->getWidth()) / pTileLayer->getTileSize());
            tileRow = ((pPlayer->getPosition().getY() + 
                pPlayer->getHeight()) / pTileLayer->getTileSize());
            tileid = tiles[tileRow + y][tileColumn + x];
        }
        else if(pPlayer->getVelocity().getX() < 0 || 
                pPlayer->getVelocity().getY() < 0) {
            tileColumn = pPlayer->getPosition().getX() / pTileLayer->getTileSize();
            tileRow = pPlayer->getPosition().getY() / pTileLayer->getTileSize();
            tileid = tiles[tileRow + y][tileColumn + x];
        }
        
        if(tileid != 0) { pPlayer->collision(); }
    }
}
开发者ID:WillSams,项目名称:Alien-Attack-Linux,代码行数:31,代码来源:CollisionManager.cpp



注:本文中的TileLayer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ TileMap类代码示例发布时间:2022-05-31
下一篇:
C++ TileKey类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap