std::vector<std::shared_ptr<IS::Map::Tile>> &IS::Map::getArround(unitPos const &p) { std::vector<std::shared_ptr<IS::Map::Tile>> _npos; _npos.push_back(p.second > 0 ? _tiles[p + unitPos(0, -1)] : nullptr); _npos.push_back(p.first > _config->getDimension().first - 1 ? _tiles[p + unitPos(1, 0)] : nullptr); _npos.push_back(p.second < _config->getDimension().second - 1 ? _tiles[p + unitPos(0, 1)] : nullptr); _npos.push_back(p.first > 0 ? _tiles[p + unitPos(-1, 0)] : nullptr); return (_npos); }
Math::Point Projector::screenToGL(Point2D point) { Math::Point offset; double orthoDim = Math::minimum( currentDimensions.getX(), currentDimensions.getY()); // offset is the value that translates by half the screen in the X and Y // dimensions. Since due to resizeGL() above the viewport is set // differently when width > height as when height > width, this complex // code is necessary. // // offset is used to change the origin (0, 0) from the upper-left corner // to the centre of the screen as is expected in OpenGL unit coordinates. if(currentDimensions.getX() > currentDimensions.getY() || true) { offset = Math::Point( double(currentDimensions.getX()) / currentDimensions.getY(), -1.0); } else { offset = Math::Point(1.0, -double(currentDimensions.getY()) / currentDimensions.getX()); } Math::Point unitPos( point.getX() / orthoDim, -point.getY() / orthoDim); return 2.0 * unitPos - offset; }
IS::Map::unitPos const IS::Map::ogreToMap(realPos const &pos) { realPos start; unitPos uPos; start.first = _config->getOffset().first - _config->getConverter()(_config->getDimension().first / 2); start.second = _config->getOffset().second - _config->getConverter()(_config->getDimension().second / 2); if (!_config->getConverter()(1)) return (unitPos(-1, -1)); try { uPos.first = static_cast<int8_t>((pos.first - start.first + (_config->getConverter()(1) / 2)) / _config->getConverter()(1)) + 1; uPos.second = static_cast<int8_t>((pos.second - start.second - (_config->getConverter()(1) / 2)) / _config->getConverter()(1)) + 1; return (uPos); } catch (...) { return (unitPos(-1, -1)); } }
int IS::Map::getAt(realPos const &p) { unitPos uPos; uPos = ogreToMap(p); if (uPos == unitPos(-1, -1)) return (-1); try { return (static_cast<int>(_tiles[uPos]->getType())); } catch (...) { return (-1); } }
void IS::Map::createBreakableBlock() { int16_t i; std::random_shuffle(_walkable.begin(), _walkable.end()); i = 0; for (auto empty : _walkable) { i++; if (std::find(_config->getSpawns().begin(), _config->getSpawns().end(), *empty - unitPos(1, 1)) == _config->getSpawns().end()) putTile(*empty, BreakBlock); else i--; if (i > (_walkable.size() * _config->getBlockRate())) break; } _walkable.clear(); }