本文整理汇总了C++中Tile类的典型用法代码示例。如果您正苦于以下问题:C++ Tile类的具体用法?C++ Tile怎么用?C++ Tile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: Position
/**
* calculateTrajectory.
* @return true when a trajectory is possible.
*/
bool Projectile::calculateTrajectory(double accuracy)
{
Position originVoxel, targetVoxel;
int direction;
int dirYshift[8] = {1, 1, 8, 15, 15, 15, 8, 1 };
int dirXshift[8] = {8, 14, 15, 15, 8, 1, 1, 1 };
// large units : x2
originVoxel = Position(_origin.x*16, _origin.y*16, _origin.z*24);
originVoxel.z += -_save->getTile(_origin)->getTerrainLevel();
BattleUnit *bu = _save->getTile(_origin)->getUnit();
originVoxel.z += bu->isKneeled()?bu->getUnit()->getKneelHeight():bu->getUnit()->getStandHeight();
originVoxel.z -= 3;
if (originVoxel.z >= (_origin.z + 1)*24)
{
_origin.z++;
}
direction = bu->getDirection();
originVoxel.x += dirXshift[direction];
originVoxel.y += 15-dirYshift[direction];
// determine the target voxel.
// aim at the center of the unit, the object, the walls or the floor (in that priority)
// if there is no LOF to the center, try elsewhere (more outward).
// Store this target voxel.
Tile *tile = _save->getTile(_target);
if (tile->getUnit() != 0)
{
if (_origin == _target)
{
targetVoxel = Position(_target.x*16 + 8, _target.y*16 + 8, _target.z*24);
}
else
{
targetVoxel = Position(_target.x*16 + 8, _target.y*16 + 8, _target.z*24 + tile->getUnit()->getUnit()->getStandHeight()/2);
}
}
else if (tile->getMapData(O_OBJECT) != 0)
{
targetVoxel = Position(_target.x*16 + 8, _target.y*16 + 8, _target.z*24 + 10);
}
else if (tile->getMapData(O_NORTHWALL) != 0)
{
targetVoxel = Position(_target.x*16 + 8, _target.y*16 + 16, _target.z*24 + 10);
}
else if (tile->getMapData(O_WESTWALL) != 0)
{
targetVoxel = Position(_target.x*16, _target.y*16 + 8, _target.z*24 + 10);
}
else if (tile->getMapData(O_FLOOR) != 0)
{
targetVoxel = Position(_target.x*16 + 8, _target.y*16 + 8, _target.z*24);
}
else
{
return false; // no line of fire
}
// apply some accuracy modifiers (todo: calculate this)
// This will results in a new target voxel
applyAccuracy(originVoxel, &targetVoxel, accuracy);
// finally do a line calculation and store this trajectory.
_save->getTerrainModifier()->calculateLine(originVoxel, targetVoxel, true, &_trajectory, bu);
return true;
}
开发者ID:UnkLegacy,项目名称:OpenXcom,代码行数:71,代码来源:Projectile.cpp
示例2: if
/**
* Initializes the explosion.
* The animation and sound starts here.
* If the animation is finished, the actual effect takes place.
*/
void ExplosionBState::init()
{
if (_item)
{
_power = _item->getRules()->getPower();
// this usually only applies to melee, but as a concession for modders i'll leave it here in case they wanna make bows or something.
if (_item->getRules()->isStrengthApplied() && _unit)
{
_power += _unit->getBaseStats()->strength;
}
_areaOfEffect = _item->getRules()->getBattleType() != BT_MELEE &&
_item->getRules()->getExplosionRadius() != 0 &&
!_cosmetic;
}
else if (_tile)
{
_power = _tile->getExplosive();
_areaOfEffect = true;
}
else if (_unit && (_unit->getSpecialAbility() == SPECAB_EXPLODEONDEATH || _unit->getSpecialAbility() == SPECAB_BURN_AND_EXPLODE))
{
_power = _parent->getMod()->getItem(_unit->getArmor()->getCorpseGeoscape())->getPower();
_areaOfEffect = true;
}
else
{
_power = 120;
_areaOfEffect = true;
}
Tile *t = _parent->getSave()->getTile(Position(_center.x/16, _center.y/16, _center.z/24));
if (_areaOfEffect)
{
if (_power)
{
int frame = Mod::EXPLOSION_OFFSET;
if (_item)
{
frame = _item->getRules()->getHitAnimation();
}
if (_parent->getDepth() > 0)
{
frame -= Explosion::EXPLODE_FRAMES;
}
int frameDelay = 0;
int counter = std::max(1, (_power/5) / 5);
_parent->getMap()->setBlastFlash(true);
for (int i = 0; i < _power/5; i++)
{
int X = RNG::generate(-_power/2,_power/2);
int Y = RNG::generate(-_power/2,_power/2);
Position p = _center;
p.x += X; p.y += Y;
Explosion *explosion = new Explosion(p, frame, frameDelay, true);
// add the explosion on the map
_parent->getMap()->getExplosions()->push_back(explosion);
if (i > 0 && i % counter == 0)
{
frameDelay++;
}
}
_parent->setStateInterval(BattlescapeState::DEFAULT_ANIM_SPEED/2);
// explosion sound
if (_power <= 80)
_parent->getMod()->getSoundByDepth(_parent->getDepth(), Mod::SMALL_EXPLOSION)->play();
else
_parent->getMod()->getSoundByDepth(_parent->getDepth(), Mod::LARGE_EXPLOSION)->play();
_parent->getMap()->getCamera()->centerOnPosition(t->getPosition(), false);
}
else
{
_parent->popState();
}
}
else
// create a bullet hit
{
_parent->setStateInterval(std::max(1, ((BattlescapeState::DEFAULT_ANIM_SPEED/2) - (10 * _item->getRules()->getExplosionSpeed()))));
int anim = _item->getRules()->getHitAnimation();
int sound = _item->getRules()->getHitSound();
if (_cosmetic) // Play melee animation on hitting and psiing
{
anim = _item->getRules()->getMeleeAnimation();
}
if (anim != -1)
{
Explosion *explosion = new Explosion(_center, anim, 0, false, _cosmetic);
_parent->getMap()->getExplosions()->push_back(explosion);
}
_parent->getMap()->getCamera()->setViewLevel(_center.z / 24);
//.........这里部分代码省略.........
开发者ID:0x90sled,项目名称:OpenXcom,代码行数:101,代码来源:ExplosionBState.cpp
示例3: getTile
/**
* Check if a Tile at position (row,col) has a widget.
* @param row :: The row to check.
* @param col :: The column to check.
*/
bool TiledWindow::hasWidget(int row, int col) const {
Tile *tile = getTile(row, col);
return tile->widget() != NULL;
}
开发者ID:liyulun,项目名称:mantid,代码行数:9,代码来源:TiledWindow.cpp
示例4: switch
QVector<QVector<Tile>> Maze::setTileDistances(QVector<QVector<Tile>> maze) {
// TODO: MACK - dedup some of this with hasNoInaccessibleLocations
// The maze is guarenteed to be nonempty and rectangular
int width = maze.size();
int height = maze.at(0).size();
// Helper lambda for retrieving and adjacent tile if one exists, nullptr if not
// TODO: MACK - this should be in maze utilities too
auto getNeighbor = [&maze, &width, &height](int x, int y, Direction direction) {
switch (direction) {
case Direction::NORTH:
return (y < height - 1 ? &maze[x][y + 1] : nullptr);
case Direction::EAST:
return (x < width - 1 ? &maze[x + 1][y] : nullptr);
case Direction::SOUTH:
return (0 < y ? &maze[x][y - 1] : nullptr);
case Direction::WEST:
return (0 < x ? &maze[x - 1][y] : nullptr);
}
};
// Determine all of the center tiles
// TODO: MACK - use the maze checker function for this
QVector<Tile*> centerTiles;
centerTiles.push_back(&maze[(width - 1) / 2][(height - 1) / 2]);
if (width % 2 == 0) {
centerTiles.push_back(&maze[ width / 2][(height - 1) / 2]);
if (height % 2 == 0) {
centerTiles.push_back(&maze[(width - 1) / 2][ height / 2]);
centerTiles.push_back(&maze[ width / 2][ height / 2]);
}
}
else if (height % 2 == 0) {
centerTiles.push_back(&maze[(width - 1) / 2][ height / 2]);
}
// The queue for the BFS
QQueue<Tile*> discovered;
// Set the distances of the center tiles and push them to the queue
for (Tile* tile : centerTiles) {
tile->setDistance(0);
discovered.enqueue(tile);
}
// Now do a BFS
while (!discovered.empty()){
Tile* tile = discovered.dequeue();
for (Direction direction : DIRECTIONS) {
if (!tile->isWall(direction)) {
Tile* neighbor = getNeighbor(tile->getX(), tile->getY(), direction);
if (neighbor != nullptr && neighbor->getDistance() == -1) {
neighbor->setDistance(tile->getDistance() + 1);
discovered.enqueue(neighbor);
}
}
}
}
return maze;
}
开发者ID:nosirromd,项目名称:mms,代码行数:63,代码来源:Maze.cpp
示例5: playerWeaponCheck
//.........这里部分代码省略.........
chance = (uint32_t)((float)1.2 * std::min<uint32_t>(skill, 74)) + 1;
break;
case 6:
chance = (uint32_t)((float)1.0 * std::min<uint32_t>(skill, 90));
break;
case 7:
chance = (uint32_t)((float)1.0 * std::min<uint32_t>(skill, 90));
break;
default:
chance = hitChance;
break;
}
} else if (maxHitChance == 100) {
switch (distance) {
case 1:
chance = (uint32_t)((float)1.35 * std::min<uint32_t>(skill, 73)) + 1;
break;
case 2:
chance = (uint32_t)((float)3.2 * std::min<uint32_t>(skill, 30)) + 4;
break;
case 3:
chance = (uint32_t)((float)2.05 * std::min<uint32_t>(skill, 48)) + 2;
break;
case 4:
chance = (uint32_t)((float)1.5 * std::min<uint32_t>(skill, 65)) + 2;
break;
case 5:
chance = (uint32_t)((float)1.35 * std::min<uint32_t>(skill, 73)) + 1;
break;
case 6:
chance = (uint32_t)((float)1.2 * std::min<uint32_t>(skill, 87)) - 4;
break;
case 7:
chance = (uint32_t)((float)1.1 * std::min<uint32_t>(skill, 90)) + 1;
break;
default:
chance = hitChance;
break;
}
} else {
chance = maxHitChance;
}
} else {
chance = hitChance;
}
if (item->getWeaponType() == WEAPON_AMMO) {
Item* bow = player->getWeapon(true);
if (bow && bow->getHitChance() != 0) {
chance += bow->getHitChance();
}
}
if (chance >= random_range(1, 100)) {
if (elementDamage != 0) {
int32_t damage = getElementDamage(player, target, item);
CombatParams eParams;
eParams.combatType = elementType;
eParams.isAggressive = true;
eParams.useCharges = true;
Combat::doCombatHealth(player, target, damage, damage, eParams);
}
Weapon::internalUseWeapon(player, item, target, damageModifier);
} else {
//miss target
Tile* destTile = target->getTile();
if (!Position::areInRange<1, 1, 0>(player->getPosition(), target->getPosition())) {
std::vector<std::pair<int32_t, int32_t>> destList;
destList.push_back(std::make_pair(-1, -1));
destList.push_back(std::make_pair(-1, 0));
destList.push_back(std::make_pair(-1, 1));
destList.push_back(std::make_pair(0, -1));
destList.push_back(std::make_pair(0, 0));
destList.push_back(std::make_pair(0, 1));
destList.push_back(std::make_pair(1, -1));
destList.push_back(std::make_pair(1, 0));
destList.push_back(std::make_pair(1, 1));
std::random_shuffle(destList.begin(), destList.end());
Position destPos = target->getPosition();
for (const auto& dir : destList) {
Tile* tmpTile = g_game.getTile(destPos.x + dir.first, destPos.y + dir.second, destPos.z);
// Blocking tiles or tiles without ground ain't valid targets for spears
if (tmpTile && !tmpTile->hasProperty(IMMOVABLEBLOCKSOLID) && tmpTile->ground != NULL) {
destTile = tmpTile;
break;
}
}
}
Weapon::internalUseWeapon(player, item, destTile);
}
return true;
}
开发者ID:bergvall,项目名称:forgottenserver,代码行数:101,代码来源:weapons.cpp
示例6: while
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();
}
}
}
}
//.........这里部分代码省略.........
开发者ID:josp0001,项目名称:FinalProject,代码行数:101,代码来源:Player.cpp
示例7: mouseReleased
bool MainView::mouseReleased(u16 x, u16 y, MouseButton b)
{
//gvm->push(new Blink(1000, Gfx::color(0, 0, 255), {0,0,320,200}, 220));
/*gvm->cityView()->setCity(g->getCities().front());*/
//gvm->switchView(VIEW_ITEM_CRAFT);
Position pos = Viewport::hoveredPosition(g->world, player, x, y);
Tile* t = g->world->get(pos);
if (t)
{
pos = t->position;
City* c = t->city;
Army* a = t->army;
if (b == BUTTON_RIGHT)
{
if (a)
{
bool couldBeSelected = (!c || (c && !a->isPatrolling()));
if (couldBeSelected && a->getOwner() == player)
{
switchToUnitSelection(a);
return true;
}
else if (a->getOwner() != player)
{
gvm->armyView()->open(a);
return true;
}
}
if (c)
{
if (!c->isOutpost())
{
gvm->cityView()->setCity(c);
gvm->switchView(VIEW_CITY);
}
else
{
gvm->outpostView()->setCity(c);
gvm->switchOverview(VIEW_OUTPOST);
}
player->resetArmy();
switchToNormalState();
}
else
{
s16 upperBoundY = pos.y - Viewport::viewportH/2;
s16 lowerBoundY = pos.y + (Viewport::viewportH - Viewport::viewportH/2);
s16 ty = pos.y;
if (upperBoundY < 0)
ty = Viewport::viewportH/2;
else if (lowerBoundY >= g->world->h)
ty = g->world->h - (Viewport::viewportH - Viewport::viewportH/2);
player->setViewport(pos.x, ty);
}
}
else if (b == BUTTON_LEFT)
{
if (substate == SPELL_CAST && player->getSpellTarget() == Target::MAP_TILE)
g->castSpell(t, player);
else if (substate == SPELL_CAST && player->getSpellTarget() == Target::FRIENDLY_UNIT)
{
if (t->army && t->army->getOwner() == player)
{
// TODO: check if unit is just 1 directly cast?
gvm->armyView()->setArmy(t->army);
gvm->armyView()->setAcceptSpellTarget();
gvm->switchOverview(VIEW_ARMY);
}
}
else if (substate == SPELL_CAST && player->getSpellTarget() == Target::FRIENDLY_CITY)
{
if (t->city && t->city->getOwner() == player)
g->castSpell(t->city, player);
}
else
{
const unit_list& selectedUnits = player->getSelectedUnits();;
const auto& route = player->getRoute();
const bool hasSelectedUnits = !selectedUnits.empty();
if (hasSelectedUnits && !route)
player->computeRoute(t->position);
else if (hasSelectedUnits && !route->completed() && route->dx() == t->x() && route->dy() == t->y() && player->selectedAvailMoves() > 0)
{
player->consumeRoute();
//player->push(new anims::UnitMovement(player, army, army->getRoute()->pendingPositions()));
updateBuildButton();
}
else if (hasSelectedUnits)
player->computeRoute(t->position);
//.........这里部分代码省略.........
开发者ID:Jakz,项目名称:openmom,代码行数:101,代码来源:MainView.cpp
示例8: Ceil
bool SceneMgr::save(xs::DataChunk* pDataChunk,bool writeOccupants)
{
int nGridWidth = GRID_WIDTH;
int nGridHeight = GRID_HEIGHT;
if(!isValid())
{
return false;
}
int nGridRow = Ceil(m_nMapHeight, nGridHeight);
int nGridCol = Ceil(m_nMapWidth, nGridWidth);
uint *pOffsetsData = 0;
xs::Stream *pDataStream = 0;
// 地图版本信息;
pDataChunk->beginChunk('MVER',&pDataStream);
m_nMapVersion = SUPPORT_EFFECT_SCALE_AND_ANGLE_ADJUST_MAP_VERSION;
pDataStream->write(&m_nMapVersion, sizeof(m_nMapVersion));
pDataChunk->endChunk();
pDataChunk->beginChunk('MINF',&pDataStream);
pDataStream->write(&m_nMapWidth,sizeof(m_nMapWidth));
pDataStream->write(&m_nMapHeight,sizeof(m_nMapHeight));
pDataChunk->endChunk();
xs::DataChunk::stChunk *pIdxChunk = pDataChunk->beginChunk('MIDX',&pDataStream);
for(int row = 0;row < nGridRow;row++)
for(int col = 0;col < nGridCol;col++)
{
uint offset = 0;
pDataStream->write(&offset,sizeof(offset));
}
pDataChunk->endChunk();
pOffsetsData = (uint*)pIdxChunk->m_pData;
m_bWriteOccupants = writeOccupants;
int nTileRow = nGridHeight / 32;
int nTileCol = nGridWidth / (64 / 2);
xs::Point ptTileLeftTop;
xs::Point ptLeftTop;
for(int row = 0;row < nGridRow;row++)
for(int col = 0;col < nGridCol;col++)
{
pDataChunk->beginChunk('MDAT',&pDataStream);
pOffsetsData[row * nGridCol + col] = pDataChunk->getOffset();
ptLeftTop.x = col * nGridWidth;
ptLeftTop.y = row * nGridHeight;
m_SceneCo.pixel2Tile(ptLeftTop, ptTileLeftTop);
_SaveBlock(pDataStream,ptTileLeftTop,nTileRow,nTileCol);
pDataChunk->endChunk();
}
m_bWriteOccupants = false;
m_pGround->save(pDataChunk);
SceneBlock mb;
int nTileWidth = m_SceneCo.getMatrixWidth();
int nTileHeight = m_SceneCo.getMatrixHeight();
mb.SetMapSize(nTileWidth, nTileHeight);
for (int row = 0; row < nTileHeight; ++row)
{
for (int col = 0; col < nTileWidth; ++col)
{
xs::Point ptTile (col, row);
Tile *pTile = &getTile(ptTile);
if (!pTile->isValid())
{
mb.SetBlock(col, row, true);
}
else
{
mb.SetBlock(col, row, pTile->isBlock() ? true: false);
}
}
}
pDataChunk->beginChunk('MWPT',&pDataStream);
mb.Save(pDataStream);
pDataChunk->endChunk();
return true;
}
开发者ID:lorichen,项目名称:xgame,代码行数:90,代码来源:SceneMgrLS.cpp
示例9: directionToVector
/**
* Get's the TU cost to move from 1 tile to the other(ONE STEP ONLY). But also updates the endPosition, because it is possible
* the unit goes upstairs or falls down while walking.
* @param startPosition
* @param direction
* @param endPosition pointer
* @param unit
* @return TU cost - 255 if movement impossible
*/
int Pathfinding::getTUCost(const Position &startPosition, int direction, Position *endPosition, BattleUnit *unit)
{
_unit = unit;
directionToVector(direction, endPosition);
*endPosition += startPosition;
bool fellDown = false;
bool triedStairs = false;
int size = _unit->getUnit()->getArmor()->getSize() - 1;
int cost = 0;
for (int x = size; x >= 0; x--)
{
for (int y = size; y >= 0; y--)
{
Tile *startTile = _save->getTile(startPosition + Position(x,y,0));
Tile *destinationTile = _save->getTile(*endPosition + Position(x,y,0));
cost = 0;
// this means the destination is probably outside the map
if (!destinationTile)
return 255;
// check if the destination tile can be walked over
if (isBlocked(destinationTile, MapData::O_FLOOR) || isBlocked(destinationTile, MapData::O_OBJECT))
return 255;
if (direction < DIR_UP)
{
// check if we can go this way
if (isBlocked(startTile, destinationTile, direction))
return 255;
if (startTile->getTerrainLevel() - destinationTile->getTerrainLevel() > 8 && x==0 && y==0)
return 255;
}
else
{
// check if we can go up or down through gravlift or fly
if (validateUpDown(unit, startPosition, direction))
{
cost += 4; // vertical movement
}
else
{
return 255;
}
}
// if we are on a stairs try to go up a level
if (startTile->getTerrainLevel() < -12 && x==0 && y==0)
{
endPosition->z++;
destinationTile = _save->getTile(*endPosition);
triedStairs = true;
}
// this means the destination is probably outside the map
if (!destinationTile)
return 255;
// check if we have floor, else fall down
while (canFallDown(destinationTile) && (_movementType != MT_FLY || triedStairs) && x==0 && y==0)
{
endPosition->z--;
destinationTile = _save->getTile(*endPosition);
fellDown = true;
}
// if we don't want to fall down and there is no floor, it ends here
if (!fellDown && destinationTile->hasNoFloor() && x==0 && y==0)
{
if (_movementType != MT_FLY)
return 255;
else
cost = 4;
}
// check if the destination tile can be walked over
if ((isBlocked(destinationTile, MapData::O_FLOOR) || isBlocked(destinationTile, MapData::O_OBJECT)) && !fellDown)
{
return 255;
}
// calculate the cost by adding floor walk cost and object walk cost
cost += destinationTile->getTUCost(MapData::O_FLOOR, _movementType);
if (!fellDown)
{
//.........这里部分代码省略.........
开发者ID:yoyko,项目名称:OpenXcom,代码行数:101,代码来源:Pathfinding.cpp
示例10: main
//.........这里部分代码省略.........
fin.open("level.txt");
int val;
if (fin.fail())
{
cout << "Error couldn't load file" << endl;
}
//***************************************************
//balls:
Ball ball;
std::vector<Ball>::iterator ballIter;
std::vector<Ball> ballArray;
sf::IntRect rectBallSprite(0, 0, 24, 24);
sf::Texture ballText;
sf::Texture largePalletText;
if (!ballText.loadFromFile("Images/pellets.png"))
{
std::cout << "Error\n";
}
if (!largePalletText.loadFromFile("Images/largePellet.png"))
{
std::cout << "Error\n";
}
//***************************************************
// Setting up the tile that represent the walls
//Positioning the walls in the map
std::vector<Tile>::const_iterator tileIter;
std::vector<Tile> tileArray;
Tile tile;
sf::Vector2i Grid(28 * scale, 36 * scale);
for (int y = 0; y < 36; y++)
{
for (int x = 0; x < 28; x++)
{
fin >> val;
cout << val;
if (val == 1)
{
tile.update(x, y);
tileArray.push_back(tile);
}
//setting coordinates for 250 ball objects in array
if (((y >= 4 && y < 12) || (y >= 12 && (x == 6 || x == 21)) || (y >= 23 && y < 34))
&& (val == 0) && (ballIndex < maxBallCount))
{
ball.setXYPosition(x * 24 + 3, y * 24 + 3);
ball.sprite.setTexture(ballText);
ball.sprite.setTextureRect(rectBallSprite);
ball.setLargePellet(false);
ballArray.push_back(ball);
ballIndex++;
}
else if (val == 3)
{
ball.setXYPosition(x * 24 + 3, y * 24 + 3);
开发者ID:MarioMartinezA,项目名称:Pacman,代码行数:67,代码来源:Main.cpp
示例11: drawRect
/**
* Draws the minimap.
*/
void MiniMapView::draw()
{
int _startX = _camera->getCenterPosition().x - ((getWidth() / CELL_WIDTH) / 2);
int _startY = _camera->getCenterPosition().y - ((getHeight() / CELL_HEIGHT) / 2);
InteractiveSurface::draw();
if (!_set)
{
return;
}
drawRect(0, 0, getWidth(), getHeight(), 0);
this->lock();
for (int lvl = 0; lvl <= _camera->getCenterPosition().z; lvl++)
{
int py = _startY;
for (int y = Surface::getY(); y < getHeight() + Surface::getY(); y += CELL_HEIGHT)
{
int px = _startX;
for (int x = Surface::getX(); x < getWidth() + Surface::getX(); x += CELL_WIDTH)
{
MapData * data = 0;
Tile * t = 0;
Position p (px, py, lvl);
t = _battleGame->getTile(p);
if (!t)
{
px++;
continue;
}
if (t->isDiscovered(2))
{
for (int i = 0; i < 4; i++)
{
data = t->getMapData(i);
Surface * s = 0;
if (data && data->getMiniMapIndex())
{
s = _set->getFrame (data->getMiniMapIndex()+35);
}
if (s)
{
s->blitNShade(this, x, y, t->getShade());
}
}
}
// alive units
if (t->getUnit() && t->getUnit()->getVisible())
{
int frame = t->getUnit()->getMiniMapSpriteIndex();
int size = t->getUnit()->getArmor()->getSize();
frame += (t->getPosition().y - t->getUnit()->getPosition().y) * size;
frame += t->getPosition().x - t->getUnit()->getPosition().x;
frame += _frame * size * size;
Surface * s = _set->getFrame(frame);
s->blitNShade(this, x, y, 0);
}
// perhaps (at least one) item on this tile?
if (t->isDiscovered(2) && !t->getInventory()->empty())
{
int frame = 9 + _frame;
Surface * s = _set->getFrame(frame);
s->blitNShade(this, x, y, 0);
}
px++;
}
py++;
}
}
this->unlock();
int centerX = getWidth() / 2 - 1;
int centerY = getHeight() / 2 - 1;
Uint8 color = 1 + _frame * 3;
int xOffset = CELL_WIDTH / 2;
int yOffset = CELL_HEIGHT / 2;
drawLine(centerX - CELL_WIDTH, centerY - CELL_HEIGHT,
centerX - xOffset, centerY - yOffset,
color); // top left
drawLine(centerX + xOffset, centerY - yOffset,
centerX + CELL_WIDTH, centerY - CELL_HEIGHT,
color); // top right
drawLine(centerX - CELL_WIDTH, centerY + CELL_HEIGHT,
centerX - xOffset, centerY + yOffset,
color); // bottom left
drawLine(centerX + CELL_WIDTH, centerY + CELL_HEIGHT,
centerX + xOffset, centerY + yOffset,
color); //bottom right
}
开发者ID:PerpetualOXC,项目名称:OpenXcom,代码行数:92,代码来源:MiniMapView.cpp
示例12: fprintf
void Tileset::Parse(const tinyxml2::XMLNode *tilesetNode, const std::string& file_path)
{
const tinyxml2::XMLElement *tilesetElem = tilesetNode->ToElement();
// Read all the attributes into local variables.
// The firstgid and source attribute are kept in the TMX map,
// since they are map specific.
first_gid = tilesetElem->IntAttribute("firstgid");
// If the <tileset> node contains a 'source' tag,
// the tileset config should be loaded from an external
// TSX (Tile Set XML) file. That file has the same structure
// as the <tileset> element in the TMX map.
const char* source_name = tilesetElem->Attribute("source");
tinyxml2::XMLDocument tileset_doc;
if ( source_name )
{
std::string fileName = file_path + source_name;
tileset_doc.LoadFile( fileName.c_str() );
if ( tileset_doc.ErrorID() != 0)
{
fprintf(stderr, "failed to load tileset file '%s'\n", fileName.c_str());
return;
}
// Update node and element references to the new node
tilesetNode = tileset_doc.FirstChildElement("tileset");
tilesetElem = tilesetNode->ToElement();
}
tile_width = tilesetElem->IntAttribute("tilewidth");
tile_height = tilesetElem->IntAttribute("tileheight");
margin = tilesetElem->IntAttribute("margin");
spacing = tilesetElem->IntAttribute("spacing");
name = tilesetElem->Attribute("name");
// Parse the tile offset, if it exists.
const tinyxml2::XMLNode *tileOffsetNode = tilesetNode->FirstChildElement("tileoffset");
if (tileOffsetNode)
{
tileOffset = new TileOffset();
tileOffset->Parse(tileOffsetNode);
}
// Parse the terrain types if any.
const tinyxml2::XMLNode *terrainTypesNode = tilesetNode->FirstChildElement("terraintypes");
if (terrainTypesNode)
{
TerrainArray terrainArray;
terrainArray.Parse(&terrainTypes, terrainTypesNode);
}
// Parse the image.
const tinyxml2::XMLNode *imageNode = tilesetNode->FirstChildElement("image");
if (imageNode)
{
image = new Image();
image->Parse(imageNode);
}
// Iterate through all of the tile elements and parse each.
const tinyxml2::XMLNode *tileNode = tilesetNode->FirstChildElement("tile");
for (int tId = 0; tileNode; ++tId)
{
Tile* tile = new Tile(tId);
tile->Parse(tileNode);
tiles.push_back(tile);
tileNode = tileNode->NextSiblingElement("tile");
}
// Parse the properties if any.
const tinyxml2::XMLNode *propertiesNode = tilesetNode->FirstChildElement("properties");
if (propertiesNode)
{
properties.Parse(propertiesNode);
}
}
开发者ID:HaoDrang,项目名称:GD,代码行数:80,代码来源:TmxTileset.cpp
示例13: while
void IOMapBin::loadOTM(Map* map)
{
int op;
bool end = false;
while(!feof(fh) || !end)
{
op = fgetc(fh);
switch(op)
{
case 0x10: // Information of the map
{
char name[100], author[100];
int pos;
int len;
// Map Name
len = fgetc(fh);
for (pos = 0; pos < len; pos++)
name[pos] = fgetc(fh);
name[pos] = '\0';
std::cout << ":: Map Name: " << name << std::endl;
// Map Author
len = fgetc(fh);
for (pos = 0; pos < len; pos++)
author[pos] = fgetc(fh);
author[pos] = '\0';
std::cout << ":: Map Author: " << author << std::endl;
} break;
case 0x20: // Map dimensions
{
int width, height;
width = fgetc(fh);
width += fgetc(fh)<<8;
height = fgetc(fh);
height += fgetc(fh)<<8;
map->mapwidth = width;
map->mapheight = height;
std::cout << ":: Map dimensions: " << width << "x" << height << std::endl;
} break;
case 0x30: // Global Temple Position
{
PositionEx templePos;
templePos.x = fgetc(fh);
templePos.x += fgetc(fh); // X
templePos.y = fgetc(fh);
templePos.y += fgetc(fh); // Y
templePos.z = fgetc(fh); // Z
int radius = fgetc(fh); // Radius
// TODO: use the temple point and radius
std::cout << ":: Global Temple Position: " << templePos.x << " " << templePos.y << " " << templePos.z << " Radius: " << radius << std::endl;
} break;
case 0x40: // Tiles and items
{
Tile *t;
int x, y, z, id, total = 0;
while(true)
{
// tile pos
x = fgetc(fh); x += fgetc(fh) << 8;
y = fgetc(fh); y += fgetc(fh) << 8;
z = fgetc(fh);
// end the loop
if (x == 0xFFFF && y == 0xFFFF && z == 0xFF)
break;
id = fgetc(fh) + 100;
id += fgetc(fh) << 8;
total += 1;
map->setTile(x, y, z, id);
t = map->getTile(x, y, z);
// check if the tile is pz
if (fgetc(fh) == 1)
t->setPz();
int op2;
int tmpid;
do
{
op2 = fgetc(fh);
switch (op2)
{
case 0x10: // Action Id
fgetc(fh); // len
tmpid = fgetc(fh);
tmpid += fgetc(fh) << 8;
// t->ground->setActionId(tmpid);
break;
case 0x20: // Unique Id
fgetc(fh); // len
tmpid = fgetc(fh);
tmpid += fgetc(fh) << 8;
//t ->ground->setUniqueId(tmpid);
//.........这里部分代码省略.........
开发者ID:divinity76,项目名称:server,代码行数:101,代码来源:iomapbin.cpp
示例14: __D_REF
void Build::_updatePreviewTiles( bool force )
{
__D_REF(d,Build);
Tile* curTile = _camera()->at( _lastCursorPos(), true );
if( !curTile )
return;
if( !force && d.lastTilePos == curTile->epos() )
return;
if( !d.multiBuilding )
{
_setStartCursorPos( _lastCursorPos() );
d.startTilePos = curTile->pos();
}
d.lastTilePos = curTile->epos();
_discardPreview();
d.money4Construction = 0;
if( d.borderBuilding )
{
Tile* startTile = _camera()->at( d.startTilePos ); // tile under the cursor (or NULL)
Tile* stopTile = _camera()->at( _lastCursorPos(), true );
TilesArray pathTiles = RoadPropagator::createPath( _city()->tilemap(),
startTile->epos(), stopTile->epos(),
d.roadAssignment, d.kbShift );
Tilemap& tmap = _city()->tilemap();
TilePos leftUpCorner = pathTiles.leftUpCorner();
TilePos rigthDownCorner = pathTiles.rightDownCorner();
TilePos leftDownCorner( leftUpCorner.i(), rigthDownCorner.j() );
TilesArray ret;
int mmapSize = std::max<int>( leftUpCorner.j() - rigthDownCorner.j() + 1,
rigthDownCorner.i() - leftUpCorner.i() + 1 );
for( int y=0; y < mmapSize; y++ )
{
for( int t=0; t <= y; t++ )
{
TilePos tpos = leftDownCorner + TilePos( t, mmapSize - 1 - ( y - t ) );
if( pathTiles.contain( tpos ) )
ret.push_back( &tmap.at( tpos ) );
}
}
for( int x=1; x < mmapSize; x++ )
{
for( int t=0; t < mmapSize-x; t++ )
{
TilePos tpos = leftDownCorner + TilePos( x + t, t );
if( pathTiles.contain( tpos ) )
ret.push_back( &tmap.at( tpos ) );
}
}
pathTiles = ret;
for( auto tile : pathTiles )
_checkPreviewBuild( tile->epos() );
}
else
{
TilesArray tiles = _getSelectedArea( d.startTilePos );
for( auto tile : tiles )
_checkPreviewBuild( tile->epos() );
}
d.sortBuildTiles();
d.text.image.fill( ColorList::clear, Rect() );
d.text.font.setColor( ColorList::red );
d.text.font.draw( d.text.image, fmt::format( "{} Dn", d.money4Construction ), Point() );
}
开发者ID:dalerank,项目名称:caesaria-game,代码行数:76,代码来源:build.cpp
示例15: loadItem
bool IOMapSerialize::loadItem(PropStream& propStream, Cylinder* parent)
{
uint16_t id;
if (!propStream.read<uint16_t>(id)) {
return false;
}
Tile* tile = nullptr;
if (parent->getParent() == nullptr) {
tile = parent->getTile();
}
const ItemType& iType = Item::items[id];
if (iType.moveable || !tile) {
//create a new item
Item* item = Item::CreateItem(id);
if (item) {
if (item->unserializeAttr(propStream)) {
Container* container = item->getContainer();
if (container && !loadContainer(propStream, container)) {
delete item;
return false;
}
parent->internalAddThing(item);
item->startDecaying();
} else {
std::cout << "WARNING: Unserialization error in IOMapSerialize::loadItem()" << id << std::endl;
delete item;
return false;
}
}
} else {
// Stationary items like doors/beds/blackboards/bookcases
Item* item = nullptr;
if (const TileItemVector* items = tile->getItemList()) {
for (Item* findItem : *items) {
if (findItem->getID() == id) {
item = findItem;
break;
} else if (iType.isDoor() && findItem->getDoor()) {
item = findItem;
break;
} else if (iType.isBed() && findItem->getBed()) {
item = findItem;
break;
}
}
}
if (item) {
if (item->unserializeAttr(propStream)) {
Container* container = item->getContainer();
if (container && !loadContainer(propStream, container)) {
return false;
}
g_game.transformItem(item, id);
} else {
std::cout << "WARNING: Unserialization error in IOMapSerialize::loadItem()" << id << std::endl;
}
} else {
//The map changed since the last save, just read the attributes
std::unique_ptr<Item> dummy(Item::CreateItem(id));
if (dummy) {
dummy->unserializeAttr(propStream);
Container* container = dummy->getContainer();
if (container) {
if (!loadContainer(propStream, container)) {
return false;
}
} else if (BedItem* bedItem = dynamic_cast<BedItem*>(dummy.get())) {
uint32_t sleeperGUID = bedItem->getSleeper();
if (sleeperGUID != 0) {
g_game.removeBedSleeper(sleeperGUID);
}
}
}
}
}
return true;
}
开发者ID:HeavenIsLost,项目名称:forgottenserver,代码行数:82,代码来源:iomapserialize.cpp
示例16: if
Tile* Tile::queryDestination(int32_t&, const Thing&, Item** destItem, uint32_t& flags)
{
Tile* destTile = nullptr;
*destItem = nullptr;
if (floorChangeDown()) {
uint16_t dx = tilePos.x;
uint16_t dy = tilePos.y;
uint8_t dz = tilePos.z + 1;
Tile* southDownTile = g_game.map.getTile(dx, dy - 1, dz);
if (southDownTile && southDownTile->floorChange(DIRECTION_SOUTH_ALT)) {
dy -= 2;
destTile = g_game.map.getTile(dx, dy, dz);
} else {
Tile* eastDownTile = g_game.map.getTile(dx - 1, dy, dz);
if (eastDownTile && eastDownTile->floorChange(DIRECTION_EAST_ALT)) {
dx -= 2;
destTile = g_game.map.getTile(dx, dy, dz);
} else {
Tile* downTile = g_game.map.getTile(dx, dy, dz);
if (downTile) {
if (downTile->floorChange(DIRECTION_NORTH)) {
++dy;
}
if (downTile->floorChange(DIRECTION_SOUTH)) {
--dy;
}
if (downTile->floorChange(DIRECTION_SOUTH_ALT)) {
dy -= 2;
}
if (downTile->floorChange(DIRECTION_EAST)) {
--dx;
}
if (downTile->floorChange(DIRECTION_EAST_ALT)) {
dx -= 2;
}
if (downTile->floorChange(DIRECTION_WEST)) {
++dx;
}
destTile = g_game.map.getTile(dx, dy, dz);
}
}
}
} else if (floorChange()) {
uint16_t dx = tilePos.x;
uint16_t dy = tilePos.y;
uint8_t dz = tilePos.z - 1;
if (floorChange(DIRECTION_NORTH)) {
--dy;
}
if (floorChange(DIRECTION_SOUTH)) {
++dy;
}
if (floorChange(DIRECTION_EAST)) {
++dx;
}
if (floorChange(DIRECTION_WEST)) {
--dx;
}
if (floorChange(DIRECTION_SOUTH_ALT)) {
dy += 2;
}
if (floorChange(DIRECTION_EAST_ALT)) {
dx += 2;
}
destTile = g_game.map.getTile(dx, dy, dz);
}
if (destTile == nullptr) {
destTile = this;
} else {
flags |= FLAG_NOLIMIT; //Will ignore that there is blocking items/creatures
}
if (destTile) {
Thing* destThing = destTile->getTopDownItem();
if (destThing) {
*destItem = destThing->getItem();
}
}
return destTile;
}
开发者ID:Blaggo,项目名称:forgottenserver,代码行数:97,代码来源:tile.cpp
示例17: getSpottingUnits
void CivilianBAIState::setupEscape()
{
int unitsSpottingMe = getSpottingUnits(_unit->getPosition());
int currentTilePreference = 15;
int tries = 0;
bool coverFound = false;
selectNearestTarget();
int dist = _aggroTarget ? _save->getTileEngine()->distance(_unit->getPosition(), _aggroTarget->getPosition()) : 0;
int bestTileScore = -100000;
int score = -100000;
Position bestTile(0, 0, 0);
Tile *tile = 0;
// weights of various factors in choosing a tile to which to withdraw
const int EXPOSURE_PENALTY = 10;
const int FIRE_PENALTY = 40;
const int BASE_SYSTEMATIC_SUCCESS = 100;
const int
|
请发表评论