void sfmlGraphicManager::print(const IMap &map) { int transX; int transY; t_pos pos; char c; ((sf::RenderWindow *)_Window)->Clear(sf::Color::Black); if (_blockSize == 0) { if (WIDTH > HEIGHT) _blockSize = HEIGHT / map.getSize(); else _blockSize = WIDTH / map.getSize(); } transY = map.getSize() / 2; pos.y = 0; while (map.getPos(pos) != -1) { pos.x = 0; transX = map.getSize() / 2; while (map.getPos(pos) != -2) { c = map.getPos(pos); sf::Shape rectangle = sf::Shape::Rectangle(sf::Vector2f((WIDTH / 2) - (transX * _blockSize), (HEIGHT / 2) - (transY * _blockSize)), sf::Vector2f((WIDTH / 2) - (transX * _blockSize) + _blockSize, (HEIGHT / 2) - (transY * _blockSize) + _blockSize), sf::Color(255,255,255)); //rectangle.setPosition((WIDTH / 2) - (transX * _blockSize), (HEIGHT / 2) - (transY * _blockSize)); switch (c) { case 'P': case '0': case 'G': case 'x': case '2': case '#': rectangle.SetColor(sf::Color(0,0,0)); break; case '1': rectangle.SetColor(sf::Color(0,0,255)); break; } ((sf::RenderWindow *)_Window)->Draw(rectangle); for (std::vector<std::pair<const char, sf::Image *>>::iterator itr = _texture.begin(); itr != _texture.end(); ++itr) if (c == (*itr).first) { sf::Sprite sprite; sprite.SetImage((*(*itr).second)); sprite.SetPosition(sf::Vector2f((WIDTH / 2) - (transX * _blockSize), (HEIGHT / 2) - (transY * _blockSize))); sprite.Resize(sf::Vector2f(_blockSize, _blockSize)); ((sf::RenderWindow *)_Window)->Draw(sprite); } pos.x += 1; transX -= 1; } pos.y += 1; transY -= 1; } ((sf::RenderWindow *)_Window)->Display(); }
void Renderer::renderGround() { IMap* map = m_world->getMap(); for (int x = -map->getSize(); x < map->getSize(); x++) { for (int y = -map->getSize(); y < map->getSize(); y++) { MapFieldType texId = map->getTypeForPos(x, y); glTranslated(x, y, 0); switch (texId) { case Grass: setMaterial(&grass); break; case Street: setMaterial(&street); break; case Sand: setMaterial(&sand); break; case Water: setMaterial(&water); break; default: setMaterial(&black); break; } glBegin(GL_QUADS); { glNormal3d(0, 0, 1); glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glVertex3f(1, 1, 0); glVertex3f(0, 1, 0); } glEnd(); glTranslated(-x, -y, 0); } } glColor3ub(255, 255, 255); }
TEST(MapTest, canCreateMapWithNonZeroSize) { IMap* map = new Map(IVector2D(10, 10)); EXPECT_EQ(IVector2D(10, 10), map->getSize()); }
TEST(MapTest, byDefaultMapHaveZeroSize) { IMap* map = new Map(); EXPECT_EQ(IVector2D(0, 0), map->getSize()); }