本文整理汇总了C++中TileLayer类的典型用法代码示例。如果您正苦于以下问题:C++ TileLayer类的具体用法?C++ TileLayer怎么用?C++ TileLayer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TileLayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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());
}
示例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;
}
示例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());
}
}
示例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);
}
示例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();
}
}
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}