Charmander::Charmander(Level* level,Tile* tile, float speed,int health, const char* textureFile) : Player(level, textureFile), m_Texture(NULL) { m_Speed = speed; m_Health = health; setCurrentTile(tile); }
void Player::update(double aDelta) { if(m_DestinationTile != NULL) { setCurrentTile(m_DestinationTile); } }
void TileSystem::addTile(Tile *tile) { if (getProjectData()) { // Id // // QString name = tile->getName(); QString id = getUniqueId(tile->getID(), name); if (id != tile->getID()) { tile->setID(id); if (name != tile->getName()) { tile->setName(name); } } } // Insert // // tile->setTileSystem(this); tiles_.insert(tile->getID(), tile); addTileSystemChanges(TileSystem::CTS_TileChange); setCurrentTile(tile); }
void TilesetEditor::currentChanged(const QModelIndex &index) { if (!index.isValid()) return; auto model = static_cast<const TilesetModel*>(index.model()); setCurrentTile(model->tileAt(index)); }
void TilesetEditor::tilesetChanged() { auto *tilesetDocument = static_cast<TilesetDocument*>(sender()); auto *tilesetView = mViewForTileset.value(tilesetDocument); auto *model = tilesetView->tilesetModel(); if (tilesetDocument == mCurrentTilesetDocument) setCurrentTile(nullptr); // It may be gone tilesetView->updateBackgroundColor(); model->tilesetChanged(); }
void TilesetEditor::removeTiles() { TilesetView *view = currentTilesetView(); if (!view) return; if (!view->selectionModel()->hasSelection()) return; const QModelIndexList indexes = view->selectionModel()->selectedIndexes(); const TilesetModel *model = view->tilesetModel(); QList<Tile*> tiles; for (const QModelIndex &index : indexes) if (Tile *tile = model->tileAt(index)) tiles.append(tile); auto matchesAnyTile = [&tiles] (const Cell &cell) { if (Tile *tile = cell.tile()) return tiles.contains(tile); return false; }; QList<MapDocument *> mapsUsingTiles; for (MapDocument *mapDocument : mCurrentTilesetDocument->mapDocuments()) if (hasTileReferences(mapDocument, matchesAnyTile)) mapsUsingTiles.append(mapDocument); // If the tileset is in use, warn the user and confirm removal if (!mapsUsingTiles.isEmpty()) { QMessageBox warning(QMessageBox::Warning, tr("Remove Tiles"), tr("Tiles to be removed are in use by open maps!"), QMessageBox::Yes | QMessageBox::No, mMainWindow->window()); warning.setDefaultButton(QMessageBox::Yes); warning.setInformativeText(tr("Remove all references to these tiles?")); if (warning.exec() != QMessageBox::Yes) return; } for (MapDocument *mapDocument : mapsUsingTiles) removeTileReferences(mapDocument, matchesAnyTile); mCurrentTilesetDocument->undoStack()->push(new RemoveTiles(mCurrentTilesetDocument, tiles)); // todo: make sure any current brushes are no longer referring to removed tiles setCurrentTile(nullptr); }
void Player::update(double aDelta) { std::string ammoCount = ""; std::stringstream ammoAmount; ammoAmount << m_Ammo; ammoAmount >> ammoCount; m_Font->setText(ammoCount.c_str()); //update the projectile for(int i = 0; i < m_Projectiles.size(); i++) { if(m_Projectiles.at(i)->getIsActive() == true) { m_Projectiles.at(i)->update(aDelta); } } //Tower1 for(int i = 0; i < m_Level->getNumberOfTiles(); i++) { if(m_Level->getTileTypeForIndex(i) == TileTypeTower) { TowerTile* temp = (TowerTile*) m_Level->getTileForIndex(i); for(int location = 0; location < temp->getProjecticle().size(); location++) { if (temp->getProjecticle().at(location)->getIsActive()) temp->getProjecticle().at(location)->update(aDelta); } } } //remove aby inactive projectiles from the projectiles vectors int index = 0; while(index != m_Projectiles.size()) { if(m_Projectiles.at(index)->getIsActive() == false) { //delete the projectile and remove it from the vector delete m_Projectiles.at(index); m_Projectiles.erase(m_Projectiles.begin() + index); } else { index++; } } if (m_PathFinder->isSearchingPath() == true) { m_PathFinder->update(aDelta); } if (isAnimating() && m_AnimationPathNodeIndex > -1) { PathNode* pathNode = m_PathFinder->getPathNodeAtIndex(m_AnimationPathNodeIndex); Tile* tile = pathNode != NULL ? pathNode->getTile() : NULL; if(tile) { float centerX = tile->getX() + (tile->getWidth() - getWidth()) / 2.0f; float centerY = tile->getY() + (tile->getHeight() - getHeight()) / 2.0f; Tile * playerTile = m_Level->getTileForPosition(getX(), getY()); float speed = playerTile->getTileSpeed(); float playerX = animate(getX(), centerX, aDelta, speed); float playerY = animate(getY(), centerY, aDelta, speed); setPosition(playerX, playerY); //change G as float for slower and faster tiles if (playerX == centerX && playerY == centerY) { m_AnimationPathNodeIndex++; m_CurrentTile->setIsPath(false); setCurrentTile(tile); if (m_AnimationPathNodeIndex >= m_PathFinder->getPathSize()) { stopAnimating(); m_CurrentTile->setIsPath(false); } if(m_AbortAnimation) { m_AbortAnimation = false; findPath(); } } else { if(m_AbortAnimation == true) { m_AbortAnimation =false; findPath(); } } } } }