void BulletSys::checkBullet(const RenderWindow &window) { bullet_it = bullet_vector.begin(); bool something_happened = false; while(bullet_it != bullet_vector.end()) { if((*bullet_it).getPosition().x > window.getSize().x || (*bullet_it).getPosition().x < 0) { bullet_it = bullet_vector.erase(bullet_it); something_happened = true; } else if((*bullet_it).getPosition().y > window.getSize().y || (*bullet_it).getPosition().y < 0) { bullet_it = bullet_vector.erase(bullet_it); something_happened = true; } else { bullet_it++; } } if(something_happened) { bullet_vector.shrink_to_fit(); } }
void SetBoost(Car & car, RenderWindow & window) { if (car.SpritePriora.getPosition().x >= window.getSize().x / 2 - car.Priora.getSize().x && car.Boost > 0) { car.Boost = car.Boost * (-1); } else if ((car.SpritePriora.getPosition().x < window.getSize().x / 2 - car.Priora.getSize().x && car.Boost < 0)) { car.Boost = car.Boost * (-1); } }
void Board::drawRocks(RenderWindow &app) { for(int i= 0; i < shoots; ++i) { rockSprite.setPosition(Vector2f(app.getSize().x - i * 30, app.getSize().y - 30)); app.draw(rockSprite); } }
///Камера/// Kamera::Kamera(Hero &hero, lv::Level &level, RenderWindow &window) { this->hero = &hero; this->level = &level; this->window = &window; view.reset(FloatRect(0.0, 0.0, window.getSize().x, window.getSize().y)); // камера по размеру окна MapRect.height = level.GetMapSize().y*level.GetTileSize().y; MapRect.width = level.GetMapSize().x*level.GetTileSize().x; // данные о размере карты L_W_H_Size.x = level.GetMapSize().x*level.GetTileSize().x; L_W_H_Size.y = level.GetMapSize().y*level.GetTileSize().y; }
Pause::Pause(RenderWindow &window): _window(window), _resume(L"Продолжить",window.getView().getSize().x/2.5,window.getView().getSize().y/2.5), _quit(L"Выйти",window.getView().getSize().x/2.5,window.getView().getSize().y/2.1) { _focus_button = resume; // Сперва выделена кнопка возврата _back.setFillColor(Color(0,0,0,200)); _back.setSize(Vector2f(window.getView().getSize().x,window.getView().getSize().y)); _menu.setSize( Vector2f(window.getView().getSize().x,window.getView().getSize().y/2.5)); _menu.setPosition(0,window.getView().getSize().y/3); _menu.setFillColor(Color(25,40,160,120)); view.reset(FloatRect(0, 0, window.getSize().x, window.getSize().y));// Камера для вида( иначе не видит меню так как в классе игрока тоже есть камера) }
bool MenuState::FrameRender(RenderWindow& window, float frametime) { mText.setString("Menu"); mText.setCharacterSize(40); mText.setPosition(window.getSize().x / 2 - mText.getGlobalBounds().width / 2, 50); window.draw(mText); mText.setString("F1 - Breakout | F2 - About Breakout"); mText.setCharacterSize(20); mText.setPosition(window.getSize().x / 2 - mText.getGlobalBounds().width / 2, 120); window.draw(mText); return false; }
bool Environment::LoadBackgroundFile(string filepath, RenderWindow &win) { if (!BackgroundTexture.loadFromFile( filepath)) { cout << "Error While Loading the Image from the path " << &err() << endl; return false; } BackgroundTexture.setRepeated(true); BackgroundSprite.setTexture(BackgroundTexture); BackgroundSprite.setScale(win.getSize().x / 600.f, win.getSize().y / 600.f); BackgroundSprite.setOrigin(0, 0); return true; }
void Entity::updateView(View &view , Listener &listener , RenderWindow &window) { Vector2u sizeWindow = window.getSize(); //sizeWindow.x /= 1.f;//SCALE_VIEW //sizeWindow.y /= 1.f;// TODO : increase zoom for camera, reason: small image view.setSize(Vector2f(sizeWindow)); float tempX = getXPos(); float tempY = getYPos(); listener.setPosition(tempX, tempY, 0); float x = getXPos(); float y = getYPos(); int leftBorder = sizeWindow.x / 2; int rightBorder = SIZE_BLOCK * (WIDTH_MAP - BORDER1) - sizeWindow.x / 2; int topBorder = sizeWindow.y / 2; int lowBorder = SIZE_BLOCK * LONG_MAP - sizeWindow.y / 2; if (int(x) < leftBorder) tempX = float(leftBorder); else if (int(x) > rightBorder) tempX = float(rightBorder); if (int(y) < topBorder) tempY = float(topBorder); else if (int(y) > lowBorder) tempY = float(lowBorder); view.setCenter(tempX, tempY); }
void Toolbar::drawBar(RenderWindow & window) { int width = TILE_SIZE*(drawTools.size()+ mainTools.size()) + 40 + 5 * (drawTools.size() - 1); //build framework RectangleShape framework; framework.setPosition((window.getSize().x - width) / 2, 0); framework.setSize(Vector2f(width, TILE_SIZE+10)); framework.setFillColor(Color(140,140,140,255)); window.draw(framework); //Add tools for (int i = 0; i < drawTools.size()+mainTools.size(); i++) { if (i < drawTools.size()) { drawTools[i]->setPosition(framework.getPosition().x + 10 + (TILE_SIZE + 5)*i, 5); window.draw(*drawTools[i]); } else { mainTools[i- drawTools.size()]->setPosition(framework.getPosition().x + 30 + (TILE_SIZE + 5)*i, 5); window.draw(*mainTools[i - drawTools.size()]); } } }
void RoomPanel::setSlider(int diff) { RenderWindow *window = RenderWindow::getInstance(); float x = 0; float xbase = (window->getSize()._x / 2) - (window->_ressources->_slide->getSize()._x / 2); switch (diff) { case 1: { x = window->_ressources->_sliderNormal->getSize()._x / 3; break; } case 2: { x = window->_ressources->_slide->getSize()._x / 2; break; } case 3: { x = window->_ressources->_slide->getSize()._x - window->_ressources->_sliderNormal->getSize()._x / 3; break; } default: { x = window->_ressources->_slide->getSize()._x / 2; break; } } static_cast<RoomPanel*>(window->getPanels().top())->getDifficulty()->setPosX(xbase + x); }
void Entity::CheckForCollisions(RenderWindow & window) { //----------------- Коллизии -------------------------- // если уходит за экран, то прекращает свое существование if (sprite->getPosition().x < 0 - width) { isLife = false; } if (sprite->getPosition().y < 0 - height) { isLife = false; } if (sprite->getPosition().x >= window.getSize().x + width) { isLife = false; } if (sprite->getPosition().y >= window.getSize().y + height) { isLife = false; } }
void InitiationCar(RenderWindow & window, Car & car, Config & config) { car.Priora.loadFromFile(config.CarImage); car.SpritePriora.setTexture(car.Priora); car.SpritePriora.setPosition(10, float(window.getSize().y / 2)); car.Wheel.loadFromFile(config.WheelImage); car.SpriteFrontWheel.setTexture(car.Wheel); car.SpriteBackWheel.setTexture(car.Wheel); car.SpriteFrontWheel.setTextureRect(config.WHEEL_RECT); car.SpriteBackWheel.setTextureRect(config.WHEEL_RECT); car.Radius = config.WHEEL_RADIUS; car.SpriteFrontWheel.setOrigin(car.Radius, car.Radius); car.SpriteBackWheel.setOrigin(car.Radius, car.Radius); SetWheels(car, config); car.CarSpeed = 0; car.Boost = 0.00001f; car.Road.setSize(config.ROAD_SIZE); car.Road.setPosition(0, car.SpriteBackWheel.getPosition().y + car.Radius); car.Road.setFillColor(Color::Black); }
Vector2f AdaptToWindowSize(int x, int y, const RenderWindow &window, int original_width = 1920, int original_height = 1080) { Vector2f pos; pos.x = static_cast<double>(x) * window.getSize().x / original_width; pos.y = static_cast<double>(y) * window.getSize().y / original_height; return pos; }
void Board::checkClick(Vector2i clickPosition, RenderWindow &app) { IntRect controlsArea = IntRect(app.getSize().x - 100, 10, 100, 30); if(controlsArea.contains(clickPosition)) { showHelp = !showHelp; } }
GraphicsRunner::GraphicsRunner(RenderWindow& window) : window_(window), windowSize_(window.getSize()), builder_(objects_, Vector2f(window.getSize().x - 2 * BARRIER_BUFFER - 2 * BARRIER_WIDTH, window.getSize().y - BANNER_HEIGHT - BARRIER_BUFFER - BARRIER_WIDTH), Vector2f(BARRIER_BUFFER + BARRIER_WIDTH, BANNER_HEIGHT + BARRIER_BUFFER + BARRIER_WIDTH), BRICK_HEIGHT, BRICK_SEPARATION), status_('\0'), timerLength_(0), level_(0) // nextLevel() increments this before loading the level (so 0 -> start at level 1) { float windowWidth = window_.getSize().x; float windowHeight = window_.getSize().y; // Add objects. If more objects are added/order is changed, make sure to update getters appropriately // Also, the first object cannot not be deletable objects_.push_back(new Paddle(*this, windowWidth / 2, windowHeight - 40, PADDLE_WIDTH, PADDLE_HEIGHT)); objects_.push_back(new Barrier(windowWidth, windowHeight, BARRIER_WIDTH, BARRIER_BUFFER)); // Record the index of the first safety brick indexOfFirstSafetyBrick_ = int(objects_.size()); // Load the font and base text objects loadFont(); addText("Level 0", DEFAULT_COLOR, (unsigned int)(BANNER_HEIGHT-2*BARRIER_BUFFER), false, 'l'); addText("Brick Breaker", Color(25,200,229), (unsigned int)(BANNER_HEIGHT-2*BARRIER_BUFFER), false, 'm'); addText("00:00", DEFAULT_COLOR, (unsigned int)(BANNER_HEIGHT-2*BARRIER_BUFFER), false, 'r'); baseNumTextObjects_ = text_.size(); // Populate the scores_ data member with high score data from file loadHighScores(); // Load the first level, no need to clear the stage first nextLevel(false); // Instead of showing "Level 1" show the intro text, also mark that this text is displayed by setting timerLength_ timerLength_ = -1; addText("Brick Breaker", Color(25,200,229), 54); addText("by gustebeast", DEFAULT_COLOR, 34, false); addText("Use J/L to move, A/D to rotate, and space to release a ball", DEFAULT_COLOR, 34, false); }
void RoomPanel::updatePlayers(std::vector<std::string> &vector, int from) { (void)from; RenderWindow *window = RenderWindow::getInstance(); unsigned int i = 0; while (i < vector.size() - 2) { getPlayers().at(i)->setUsername(vector.at(i)); _backgrounds.at(i + 1).setTexture(*_spaceShipsTextures.at(i + 1)); getLabels().at(i + 2).setString(vector.at(i)); getLabels().at(i + 2).setOrigin(_labels.at(i + 2).getText().getGlobalBounds().width / 2, _labels.at(i + 2).getText().getGlobalBounds().height / 2); _nbPlayers++; i++; } i--; _players.at(i)->setCurrentClient(true); _currentPlayer = i + 1; switch (i) { case 0: getLabels().at(i + 2).setColor(Color::BLUE); break; case 1: getLabels().at(i + 2).setColor(Color::RED); break; case 2: getLabels().at(i + 2).setColor(Color::GREEN); break; case 3: getLabels().at(i + 2).setColor(Color::YELLOW); break; default: getLabels().at(i + 2).setColor(Color::WHITE); break; } _idRoom = vector.at(vector.size() - 2); _labels.at(6).setString(_idRoom); _labels.at(6).setOrigin(_labels.at(6).getText().getGlobalBounds().width / 2, _labels.at(6).getText().getGlobalBounds().height / 2); _labels.at(6).setPosition(Vector2(0.5 * window->getSize()._x, 0.95 * window->getSize()._y)); }
bool BreakoutAboutState::FrameRender(RenderWindow& window, float frametime) { text.setString("About Breakout"); text.setCharacterSize(20); text.setPosition(window.getSize().x / 2 - text.getGlobalBounds().width / 2, 120); window.draw(text); return false; }
void JoinPanel::updateOnTextEntered(int key) { RenderWindow *window = RenderWindow::getInstance(); if (_room.size() < 4) { if (key >= sf::Keyboard::A && key <= sf::Keyboard::Z) _room += static_cast<char>(key + 65); if (key >= sf::Keyboard::Num0 && key <= sf::Keyboard::Num9) _room += static_cast<char>(key + 22); } if (key == sf::Keyboard::BackSpace && _room.size() > 0) _room.pop_back(); if (key == sf::Keyboard::Return) if (_room.size() == 4) this->join(); _labels.at(2).setString(_room); _labels.at(2).setOrigin(_labels.at(2).getText().getGlobalBounds().width / 2, _labels.at(2).getText().getGlobalBounds().height / 2); _labels.at(2).setPosition(Vector2(window->getSize()._x * 0.5, window->getSize()._y * 0.5)); }
//--------------------------- void BouncingThing::Update(const RenderWindow &w) { Rotate(); m_centrePos += m_velocity; m_shape.setPosition(m_centrePos); //keep the object on the screen /*if(m_centrePos.x >= w.getSize().x || m_centrePos.x <= 0) m_velocity.x *= -1; if(m_centrePos.y >= w.getSize().y || m_centrePos.y <= 0) m_velocity.y *= -1;*/ //updated to stop object getting stuck and jittering on the edge of the screen if((m_centrePos.x >= w.getSize().x && m_velocity.x > 0) || (m_centrePos.x <= 0 && m_velocity.x < 0)) m_velocity.x *= -1; if((m_centrePos.y >= w.getSize().y && m_velocity.y > 0) || (m_centrePos.y <= 0 && m_velocity.y < 0)) m_velocity.y *= -1; checkedIDs.clear(); //clear for next round of collision tests }
void UserInterface::CreateADialog(string Text , int fontsize, Font font, RenderWindow &win) { sf::Text text; text.setFont(font); text.setString(Text); text.setCharacterSize(fontsize); DialogSprite.setPosition(0 + 5, win.getSize().y - DialogSprite.getGlobalBounds().height); text.setPosition(DialogSprite.getGlobalBounds().left + 20, DialogSprite.getGlobalBounds().top + 30); win.draw(DialogSprite); win.draw(text); win.display(); win.clear(); }
void Board::drawText(RenderWindow &app) { std::ostringstream sPoints; sPoints << points; text.setString("Puntos: " + sPoints.str()); text.setPosition(10, 10); app.draw(text); text.setString("Controles"); text.setPosition(app.getSize().x - 100, 10); app.draw(text); }
Vector2f Border(Entity & object, RenderWindow & window) { Vector2f limit(0.f, 0.f); float heigth = object.height, width = object.width, X = object.x, Y = object.y; Vector2f posObject = object.sprite->getPosition(); if (window.getSize().x <= posObject.x + width / 2) { X = -BORDER; } if (0 >= posObject.x - width / 2) { X = BORDER; } if (window.getSize().y <= posObject.y + heigth / 2) { Y = -BORDER; } if (0 >= posObject.y - heigth / 2) { Y = BORDER; } limit.x = X; limit.y = Y; return limit; }
bool UserInterface::LoadSptireFiles(string SpritesheetPath, RenderWindow &win ) { if (!SptireSheet.loadFromFile( SpritesheetPath)) { cout << "Error While Loading The Png" << endl; return false; } DialogSprite.setTexture(SptireSheet); NextarrowSprite.setTexture(SptireSheet); MenuSprite.setTexture(SptireSheet); dialog_box_Rect = IntRect( 2 , 2 , 578 , 96 ); combobox_default_Rect = IntRect( 582 , 2 , 288 , 112 ); confirm_bg_Rect = IntRect( 872 , 2 , 192 , 64 ); slider_default_Rect = IntRect( 1066 , 2 , 199 , 52 ); listbox_default_Rect = IntRect( 1267 , 2 , 143 , 84 ); button_default_Rect = IntRect( 1412 , 2 , 130 , 110 ); button_small_Rect = IntRect( 1544 , 2 , 63 , 110 ); button_x_Rect = IntRect( 1609 , 2 , 24 , 94 ); input_Rect = IntRect( 872 , 68 , 130 , 40 ); bar_hp_mp_Rect = IntRect( 1066 , 56 , 106 , 33 ); menu_xp_Rect = IntRect( 2 , 100 , 106 , 10 ); scrollbar_default_Rect = IntRect( 1174 , 56 , 75 , 15 ); checkbox_default_Rect = IntRect( 1004 , 68 , 22 , 38 ); arrowsright_Rect = IntRect( 1028 , 91 , 94 , 22 ); arrowsleft_Rect = IntRect( 1124 , 91 , 94 , 22 ); arrowsup_Rect = IntRect( 1220 , 88 , 92 , 24 ); arrowsdown_Rect = IntRect( 1314 , 88 , 92 , 24 ); DialogSprite.setTextureRect(dialog_box_Rect); NextarrowSprite.setTextureRect(arrowsdown_Rect); MenuSprite.setTextureRect(confirm_bg_Rect); //Resizing DialogSprite.setScale((win.getSize().x - 10) / DialogSprite.getGlobalBounds().width * 1.f, 2); return true; }
void OutputText(RenderWindow & window, Game & game) { Racket & racket = game.racket; Racket & racket2 = game.racket2; Font font; font.loadFromFile("myFont.otf"); Text pointLeft("", font, SIZE_POINT_TEXT), pointRigth("", font, SIZE_POINT_TEXT), textWin("", font, SIZE_TEXT_WIN); ostringstream pointLeftString, pointRigthString; // объявили переменную pointLeftString << racket.count; //занесли в нее число очков, то есть формируем строку pointLeft.setString("" + pointLeftString.str()); pointLeft.setPosition(SCREEN_WIDTH / 2 - 35, 20); pointRigthString << racket2.count; //занесли в нее число очков, то есть формируем строку pointRigth.setString("" + pointRigthString.str()); pointRigth.setPosition(SCREEN_WIDTH / 2 + 15, 20); if (racket.count == game.ball.pointWin) { textWin.setString(L"Player 1 WIN!"); textWin.setPosition(textWin.getCharacterSize(), textWin.getCharacterSize()); } if (racket2.count == game.ball.pointWin) { textWin.setString(L"Player 2 WIN!"); textWin.setPosition(window.getSize().x/1.5 - textWin.getCharacterSize(), textWin.getCharacterSize()); } if (textWin.getString().isEmpty()) { window.draw(pointLeft); window.draw(pointRigth); } else { game.gameState.isPayse = false; window.draw(textWin); } }
//////////////////////////////////////////////////////////////////// // Обновление камеры void MainPerson::updateView(RenderWindow & window) { Vector2u sizeWindow = window.getSize(); view->setSize(Vector2f(sizeWindow));// ИСПРАВЬ float tempX = getXPos(); float tempY = getYPos();//считываем коорд игрока и проверяем их, чтобы убрать края float x = getXPos(); float y = getYPos(); int leftBorder = sizeWindow.x / 2; int rightBorder = SIZE_BLOCK * (WIDTH_MAP - BORDER1) - sizeWindow.x / 2; int topBorder = sizeWindow.y / 2; int lowBorder = SIZE_BLOCK * LONG_MAP - sizeWindow.y / 2; if (x < leftBorder) tempX = leftBorder;//убираем из вида левую сторону else if (x > rightBorder) tempX = rightBorder;//убираем из вида левую сторону if (y < topBorder) tempY = topBorder;//верхнюю сторону else if (y > lowBorder) tempY = lowBorder;//нижнюю сторону view->setCenter(tempX, tempY); }
OITRenderComponent::OITRenderComponent (RenderWindow& window, int layer, std::string expression) : HeavyComponent(window, math::Vec3f(window.getView().getPosition().x, window.getView().getPosition().y, layer), math::Vec3f(window.getView().getSize().x, window.getView().getSize().y, 0), math::Vec3f(window.getView().getSize().x + window.getView().getSize().x * 0.5f, window.getView().getPosition().y + window.getView().getSize().y * 0.5f, layer)), view(window.getView()), expression(expression) { update = false; sf::Vector3i resolution ((int) window.getSize().x, (int) window.getSize().y, window.getView().getSize().z); depthBuffer = std::make_unique<RenderTexture>(); frameBuffer = std::make_unique<RenderTexture>(); specularTexture = std::make_unique<RenderTexture>(); bumpTexture = std::make_unique<RenderTexture>(); refractionTexture = std::make_unique<RenderTexture>(); depthBuffer->create(resolution.x, resolution.y,window.getSettings()); frameBuffer->create(resolution.x, resolution.y,window.getSettings()); specularTexture->create(resolution.x, resolution.y,window.getSettings()); bumpTexture->create(resolution.x, resolution.y,window.getSettings()); refractionTexture->create(resolution.x, resolution.y,window.getSettings()); frameBuffer->setView(window.getView()); depthBuffer->setView(window.getView()); specularTexture->setView(window.getView()); bumpTexture->setView(window.getView()); refractionTexture->setView(window.getView()); frameBuffer->clear(sf::Color::Transparent); depthBuffer->clear(sf::Color::Transparent); specularTexture->clear(sf::Color::Transparent); bumpTexture->clear(sf::Color::Transparent); frameBufferTile = std::make_unique<Tile>(&frameBuffer->getTexture(), math::Vec3f(0, 0, 0), math::Vec3f(window.getView().getSize().x, window.getView().getSize().y, 0), IntRect(0, 0, window.getView().getSize().x, window.getView().getSize().y)); depthBufferTile = std::make_unique<Tile>(&depthBuffer->getTexture(), math::Vec3f(0, 0, 0), math::Vec3f(window.getView().getSize().x, window.getView().getSize().y, 0), IntRect(0, 0, window.getView().getSize().x, window.getView().getSize().y)); if (Shader::isAvailable()) { frameBufferGenerator = std::make_unique<Shader>(); depthBufferGenerator = std::make_unique<Shader>(); specularTextureGenerator = std::make_unique<Shader>(); bumpTextureGenerator = std::make_unique<Shader>(); refractionTextureGenerator = std::make_unique<Shader>(); simpleShader = std::make_unique<Shader>(); const std::string vertexShader = "#version 130 \n" "out mat4 projMat;" "void main () {" "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;" "gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;" "gl_FrontColor = gl_Color;" "projMat = gl_ProjectionMatrix;" "}"; const std::string specularGenFragShader = "#version 130 \n" "uniform sampler2D specularTexture;" "uniform sampler2D texture;" "uniform vec3 resolution;" "uniform float maxM;" "uniform float maxP;" "uniform float m;" "uniform float p;" "uniform float haveTexture;" "in mat4 projMat;" "void main() {" "vec2 position = ( gl_FragCoord.xy / resolution.xy );" "vec4 color = texture2D(specularTexture, position);" "vec4 pixel = (haveTexture==1) ? gl_Color * texture2D(texture, gl_TexCoord[0].xy) : gl_Color;" "float z = (gl_FragCoord.w != 1.f) ? (inverse(projMat) * vec4(0, 0, 0, gl_FragCoord.w)).w : gl_FragCoord.z;" "if(z >= color.z && pixel.a >= color.a) {" "float intensity = (maxM != 0.f) ? m / maxM : 0.f;" "float power = (maxP != 0.f) ? p / maxP : 0.f;" "gl_FragColor = vec4(intensity, power, z, pixel.a);" "} else {" "gl_FragColor = color;" "}" "}"; const std::string depthGenFragShader = "#version 130 \n" "uniform sampler2D depthBuffer;" "uniform sampler2D texture;" "uniform vec3 resolution;" "uniform float haveTexture;" "in mat4 projMat;" "void main () {" "vec2 position = ( gl_FragCoord.xy / resolution.xy );" "vec4 previous_depth_alpha = texture2D(depthBuffer, position);" "vec4 texel = texture2D(texture, gl_TexCoord[0].xy);" "vec4 colors[2];" "colors[1] = texel * gl_Color;" "colors[0] = gl_Color;" "bool b = (haveTexture == 1);" "float current_alpha = colors[int(b)].a;" "float current_depth = (gl_FragCoord.w != 1.f) ? (inverse(projMat) * vec4(0, 0, 0, gl_FragCoord.w)).w : gl_FragCoord.z;" "colors[1] = vec4(current_depth, current_alpha, current_depth, current_alpha);" "colors[0] = vec4(current_depth, current_alpha, previous_depth_alpha.z, previous_depth_alpha.a);" "b = (current_depth >= previous_depth_alpha.z && current_alpha != 0);" "gl_FragColor = colors[int(b)];" "}"; const std::string frameBufferGenFragShader = "#version 130 \n" "uniform sampler2D depthBuffer;" "uniform sampler2D frameBuffer;" "uniform sampler2D texture;" "uniform vec3 resolution;" "uniform float haveTexture;" "in mat4 projMat;" "void main () {" "vec2 position = ( gl_FragCoord.xy / resolution.xy );" "vec4 previous_depth_alpha = texture2D(depthBuffer, position);" "vec4 previous_color = texture2D(frameBuffer, position);" "vec4 texel = texture2D(texture, gl_TexCoord[0].xy);" "vec4 colors[2];" "colors[1] = texel * gl_Color;" "colors[0] = gl_Color;" "bool b = (haveTexture == 1);" "vec4 current_color = colors[int(b)];" "float current_depth = (gl_FragCoord.w != 1.f) ? (inverse(projMat) * vec4(0, 0, 0, gl_FragCoord.w)).w : gl_FragCoord.z;" "colors[1] = current_color * current_color.a + previous_color * (1 - current_color.a);" "colors[1].a = current_color.a + previous_color.a * (1 - current_color.a);" "colors[0] = previous_color * previous_depth_alpha.a + current_color * (1 - previous_depth_alpha.a);" "colors[0].a = previous_color.a + current_color.a * (1 - previous_color.a);" "b = (current_depth >= previous_depth_alpha.z);" "gl_FragColor = colors[int(b)];" "}"; const std::string bumpGenFragShader = "#version 130 \n" "uniform sampler2D bumpTexture;" "uniform sampler2D texture;" "uniform vec3 resolution;" "uniform float haveTexture;" "in mat4 projMat;" "void main() {" "vec2 position = ( gl_FragCoord.xy / resolution.xy );" "vec4 bump1 = texture2D(bumpTexture, position);" "vec4 bump2 = (haveTexture==1) ? texture2D(texture, gl_TexCoord[0].xy) : vec4(0, 0, 0, 0);" "float z = (gl_FragCoord.w != 1.f) ? (inverse(projMat) * vec4(0, 0, 0, gl_FragCoord.w)).w : gl_FragCoord.z;" "if (z >= bump1.a) {" "gl_FragColor = vec4(bump2.xyz, z);" "} else {" "gl_FragColor = bump1;" "}" "}"; const std::string refractionGenFragShader = "#version 130 \n" "uniform sampler2D refractionTexture;" "uniform vec3 resolution;" "uniform float refractionFactor;" "in mat4 projMat;" "void main() {" "vec2 position = ( gl_FragCoord.xy / resolution.xy );" "vec4 refraction = texture2D(refractionTexture, position);" "float z = (gl_FragCoord.w != 1.f) ? (inverse(projMat) * vec4(0, 0, 0, gl_FragCoord.w)).w : gl_FragCoord.z;" "if (z >= refraction.a) {" "gl_FragColor = vec4(refractionFactor, 0, z, 0);" "} else {" "gl_FragColor = refraction;" "}" "}"; if (!depthBufferGenerator->loadFromMemory(vertexShader, depthGenFragShader)) throw core::Erreur(50, "Failed to load depth buffer generator shader", 0); if (!frameBufferGenerator->loadFromMemory(vertexShader, frameBufferGenFragShader)) throw core::Erreur(51, "Failed to load frame buffer generator shader", 0); if (!specularTextureGenerator->loadFromMemory(vertexShader, specularGenFragShader)) throw core::Erreur(52, "Failed to load specular texture generator shader", 0); if (!bumpTextureGenerator->loadFromMemory(vertexShader, bumpGenFragShader)) throw core::Erreur(53, "Failed to load bump texture generator shader", 0); if (!refractionTextureGenerator->loadFromMemory(vertexShader, refractionGenFragShader)) throw core::Erreur(54, "Failed to load refraction texture generator shader", 0); frameBufferGenerator->setParameter("resolution",resolution.x, resolution.y, resolution.z); frameBufferGenerator->setParameter("depthBuffer", depthBuffer->getTexture()); frameBufferGenerator->setParameter("frameBuffer", frameBuffer->getTexture()); frameBufferGenerator->setParameter("texture", Shader::CurrentTexture); depthBufferGenerator->setParameter("resolution",resolution.x, resolution.y, resolution.z); depthBufferGenerator->setParameter("depthBuffer", depthBuffer->getTexture()); depthBufferGenerator->setParameter("texture", Shader::CurrentTexture); specularTextureGenerator->setParameter("resolution",resolution.x, resolution.y, resolution.z); specularTextureGenerator->setParameter("specularTexture",specularTexture->getTexture()); specularTextureGenerator->setParameter("texture",Shader::CurrentTexture); specularTextureGenerator->setParameter("maxM", Material::getMaxSpecularIntensity()); specularTextureGenerator->setParameter("maxP", Material::getMaxSpecularPower()); bumpTextureGenerator->setParameter("resolution",resolution.x, resolution.y, resolution.z); bumpTextureGenerator->setParameter("bumpTexture",bumpTexture->getTexture()); bumpTextureGenerator->setParameter("texture",Shader::CurrentTexture); refractionTextureGenerator->setParameter("resolution",resolution.x, resolution.y, resolution.z); refractionTextureGenerator->setParameter("bumpTexture",bumpTexture->getTexture()); core::FastDelegate<bool> signal (&OITRenderComponent::needToUpdate, this); core::FastDelegate<void> slot (&OITRenderComponent::drawNextFrame, this); core::Command cmd(signal, slot); getListener().connect("UPDATE", cmd); backgroundColor = sf::Color::Transparent; } else { throw core::Erreur(55, "Shader not supported!", 0); } }
void JoinPanel::setUserInterface() { RenderWindow *window = RenderWindow::getInstance(); _type = PanelFactory::JOIN_PANEL; window->getSettings()->dumpBinds(); getInputManager().setInputType(InputType::JOIN_INPUT); Sprite *backgroundSpace = new Sprite; Sprite *earth = new Sprite; Sprite *cockpit = new Sprite; Sprite *logo = new Sprite; Sprite *black = new Sprite; earth->setOrigin((RenderWindow::getInstance())->_ressources->_earth->getSize()._x / 2, (RenderWindow::getInstance())->_ressources->_earth->getSize()._y / 2); logo->setOrigin((RenderWindow::getInstance())->_ressources->_logo->getSize()._x / 2, (RenderWindow::getInstance())->_ressources->_logo->getSize()._y / 2); backgroundSpace->setTexture(*((RenderWindow::getInstance())->_ressources->_backgroundStartPanel)); earth->setTexture(*((RenderWindow::getInstance())->_ressources->_earth)); cockpit->setTexture(*((RenderWindow::getInstance())->_ressources->_cockpit)); logo->setTexture(*((RenderWindow::getInstance())->_ressources->_logo)); black->setTexture(*((RenderWindow::getInstance())->_ressources->_backgroundBlack)); backgroundSpace->setPosition(0, 0); earth->setPosition(window->getSize()._x + (RenderWindow::getInstance())->_ressources->_earth->getSize()._x / 6, window->getSize()._y + (RenderWindow::getInstance())->_ressources->_earth->getSize()._y / 6); cockpit->setPosition(0, 0); black->setPosition(0, 0); logo->setPosition(window->getSize()._x / 2, window->getSize()._y / 6); logo->scale(0.5); backgroundSpace->scale(1.1); _backgrounds.push_back(*backgroundSpace); _backgrounds.push_back(*earth); _backgrounds.push_back(*cockpit); _backgrounds.push_back(*logo); _backgrounds.push_back(*black); // Button std::string name = "BACK"; ButtonFactory::create(Vector2(window->getSize()._x * 0.25, window->getSize()._y * 0.7), name); name = "ACCESS"; ButtonFactory::create(Vector2(window->getSize()._x * 0.75, window->getSize()._y * 0.7), name); _functions.push_back((APanel::funcs)&JoinPanel::back); _functions.push_back((APanel::funcs)&JoinPanel::join); Text *id = new Text(); id->setString(""); id->setSize(60); id->setStyle(1); id->setOrigin(id->getText().getGlobalBounds().width / 2, id->getText().getGlobalBounds().height / 2); id->setPosition(Vector2(window->getSize()._x * 0.5, window->getSize()._y * 0.5)); id->setFont(*((RenderWindow::getInstance())->_ressources->_fontSecond)); id->setColor(Color::WHITE); _labels.push_back(*id); Text *text = new Text(); text->setString("ENTER ROOM ID TO JOIN :"); text->setSize(80); text->setStyle(1); text->setOrigin(text->getText().getGlobalBounds().width / 2, text->getText().getGlobalBounds().height / 2); text->setPosition(Vector2(window->getSize()._x * 0.5, window->getSize()._y * 0.3)); text->setColor(Color::WHITE); _labels.push_back(*text); Text *error = new Text(); error->setString(""); error->setSize(40); error->setStyle(1); error->setOrigin(text->getText().getGlobalBounds().width / 2, text->getText().getGlobalBounds().height / 2); error->setFont(*((RenderWindow::getInstance())->_ressources->_fontSecond)); error->setPosition(Vector2(window->getSize()._x * 0.5, window->getSize()._y * 0.4)); error->setColor(Color::RED); _labels.push_back(*error); _alpha = 0; }
//map<color, Color> colors = { // { Black, Color::Black }, // { White, Color::White }, // { Red, Color::Red }, // { Green, Color::Green }, // { Blue, Color::Blue }, // { Yellow, Color::Yellow }, // { Magenta, Color::Magenta }, // { Cyan, Color::Cyan }, // { Transparent, Color::Transparent }, // { Orange, Color(255, 128, 0) } //}; ////////////////////////// this returns a lambda ////////////////////////// function<void()> ////////////////////////// TYPE APP NAME ON LINE BELOW ////////////////////////// mine_solver (RenderWindow&window, ui &UI) { return [&window, &UI]() { #ifndef COMMON_INITS //void smoothmouse(RenderWindow&window, ui &UI){ // tidy code organization, here we predeclare methods just like a header would, it's redundant but necessary function<void()> draw, loop, init, update; function<void(Vec2 pos)> mousemoved; function<void(sf::Mouse::Button button)> mouseclick, mouserelease; function<void(Event&e)> treatotherevent; function<void(Keyboard::Key k)> treatkeyevent; // we don't have a class/interface/struct with data, everything is local to this function, like a classic stack that all programs are anyway. Texture cursor_tx; Sprite cursor; configfile cfg; cfg.init("bedlab.cfg"); Color background = cfg.getvar<Color>("background"); if (!cursor_tx.loadFromFile(cfg.getstr("cursor"))) cout << "did not load cursor" << endl; cursor.setTexture(cursor_tx); cursor.setOrigin(3, 3); window.setMouseCursorVisible(false); Vec2 mpos; bool leftclicked = false, rightclicked = false; // view and zoom View view, ui_view; ui_view = view = window.getDefaultView(); float zoomlevel = 1; Vec2 mpos_abs; #endif // COMMON_INITS // ************************ CODE BEGIN ************************ barstack bst(FONT, FONTSIZE); slider_finder sl; randgenfloat cell_rnd(0, 16); //grd. vector<string> mines_str = { " ", " 21114X411 ", " 3X22XX212 ", " X3--4433X ", " 23--4XX3X ", " 1X4---433 ", " 12X4--4X2 ", " 123X3XX3X ", " 2X2122221 ", " " }; int w = mines_str[0].length(); int h = mines_str.size(); vector<int> mine_states(h*w); grid grd; grd.screen_init(Vec2u(window.getSize()), Vec2u( w,h ), true); /* 1-8: surrounding mines 0 no mine, "clear" -1: unknown -2 mine */ map<char, int> lookup = { { '-',-1 }, { 'X',-2 }, { ' ',0 } }; int i = 0; logfile lg("minelog.txt"); lg.logw(to_str("i", "j", "index", "value")); for (auto&a : mines_str) { int j = 0; for (auto&b : a) { int value = -10; //value = // lookup.count(b) ? // lookup[b] // : (b > '0' || b <= '9') ? // int(b - '0') // : value; //msg(value); if (lookup.count(b)) value = lookup[b]; else if (b > '0' || b <= '9')value = int(b - '0'); int index = getat(j, i, w); mine_states[index] = value; //msgm(i,j,index, value); lg.logw(to_str(i,j,index, value)); ++j; } ++i; } map<int, Color> mine_colors = { { -2,Color::Red }, { -1,Color::Cyan }, { 0,Color::Black } }; msg(mine_states); i = 0; for (auto&a : mine_states) { if(a > 0) grd.texts[i].setString(to_str(a)); else grd.cells[i].setFillColor(mine_colors[a]); //grd.texts2[i].setString(to_str(i)); //grd.texts3[i].setString(to_str(getat(i,w))); ++i; } auto analyse = [&mine_states, w, h, &grd]() { vector<Vec2i> offsets = { { -1,-1 }, { 1,-1 }, { -1,1 }, { 1,1 }, { 0,-1 }, { -1,0 }, { 0,1 }, { 1,0 } }; int i = 0; for (auto&a : mine_states) { auto pos = getat(i, w); int unknown = 0, is_mine = 0; for (auto&off : offsets) { auto cell = pos + off; int cell_index = getat(cell,w); if (cell_index < 0 || cell_index >= mine_states.size() || cell.x < 0 || cell.x > w) continue; switch (mine_states[cell_index]) { case -1: ++is_mine; break; //unknown case -2: ++unknown; break; //mine } } int mine_left = a - is_mine; float prob = mine_left / unknown; ++i; } }; auto nearest_pt = mkcircle({ 0, 0 }, Color::Transparent, 10); nearest_pt.setOutlineThickness(2); // ************************ INITS END ********************** //then we actually define the functions, note how all function captures the local context by reference #ifndef LOOP_LAMBDAS draw = [&]() { window.setView(view); // object draw, AFTER normal view //////////////// obj draw START //////////////// for (auto&a : glob_pts)window.draw(a); for (auto&a : glob_rects)window.draw(a); for (auto&a : glob_vert)window.draw(a); for (auto&a : glob_texts)window.draw(a); window.draw(nearest_pt); grd.draw(window); //////////////// obj draw END //////////////// // UI draw, AFTER ui view and BEFORE other draw window.setView(ui_view); bst.draw(window); // nothing after here please UI.draw(window); window.draw(cursor); }; update = [&]() { }; treatkeyevent = [&](Keyboard::Key k) { switch (k) { case Keyboard::BackSpace: glob_pts.clear(); glob_texts.clear(); glob_rects.clear(); glob_vert.clear(); break; case Keyboard::Space: break; case Keyboard::Q: break; } }; mousemoved = [&](Vec2 pos) { cursor.setPosition(pos); if (leftclicked) sl.mouse_callback(pos); }; mouseclick = [&](sf::Mouse::Button button) { if (button == Mouse::Button::Left) leftclicked = true; if (button == Mouse::Button::Right) rightclicked = true; }; mouserelease = [&](sf::Mouse::Button button) { if (button == Mouse::Button::Left) leftclicked = false; if (button == Mouse::Button::Right) rightclicked = false; sl.release(); }; loop = [&]() { while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { switch (event.type) { case sf::Event::KeyPressed: if (event.key.code == sf::Keyboard::Escape) window.close(); treatkeyevent(event.key.code); break; case sf::Event::Closed: window.close(); break; case sf::Event::MouseButtonPressed: mouseclick(event.mouseButton.button); break; case sf::Event::MouseButtonReleased: mouserelease(event.mouseButton.button); break; case sf::Event::MouseMoved: mpos = Vec2(event.mouseMove.x, event.mouseMove.y); mousemoved(mpos); break; default: treatotherevent(event); break; } } window.clear(background); update(); draw(); window.display(); } }; treatotherevent = [&](Event&e) { if (e.type == Event::MouseWheelMoved && e.mouseWheel.delta) { mpos_abs = window.mapPixelToCoords(Vec2i(mpos), view); //view = window.getView(); if (e.mouseWheel.delta < 0) { zoomlevel *= 2.f; view.setSize(view.getSize()*2.f); view.setCenter(interp(mpos_abs, view.getCenter(), 2.f)); //view.setCenter(interp(mpos_abs, view.getCenter(), 2.f)); } if (e.mouseWheel.delta > 0) { zoomlevel *= 0.5; view.setSize(view.getSize()*.5f); view.setCenter(.5f*(view.getCenter() + mpos_abs)); //view.setCenter(.5f*(view.getCenter() + mpos_abs)); } window.setView(view); } }; loop(); #endif // LOOP_LAMBDAS }; }
void RoomPanel::setUserInterface() { RenderWindow *window = RenderWindow::getInstance(); Sprite *background = new Sprite; getInputManager().setInputType(InputType::ROOM_INPUT); background->setTexture(*((RenderWindow::getInstance())->_ressources->_backgroundRoomPanel)); background->setPosition(0, 0); _backgrounds.push_back(*background); std::string name = "BACK"; ButtonFactory::create(Vector2(window->getSize()._x * 0.1, window->getSize()._y * 0.95), name); name = "LAUNCH"; ButtonFactory::create(Vector2(window->getSize()._x * 0.9, window->getSize()._y * 0.95), name); // _userInterface.at(1)->getSprite().getSprite().setColor(sf::Color(255, 255, 255, 0)); // _labels.at(1).getText().setColor(sf::Color(255, 255, 255, 255)); _functions.push_back((APanel::funcs)&RoomPanel::back); _functions.push_back((APanel::funcs)&RoomPanel::launchGame); _spaceShipsTextures.push_back(((RenderWindow::getInstance())->_ressources->_blackShip)); _spaceShipsTextures.push_back(((RenderWindow::getInstance())->_ressources->_blueShip)); _spaceShipsTextures.push_back(((RenderWindow::getInstance())->_ressources->_redShip)); _spaceShipsTextures.push_back(((RenderWindow::getInstance())->_ressources->_greenShip)); _spaceShipsTextures.push_back(((RenderWindow::getInstance())->_ressources->_yellowShip)); this->createPlayers(); name = "difficulty"; float x; std::string diff; if (window->getSettings()->getDefaultDifficulty() == Settings::EASY_MODE) { diff = std::to_string(E_EASY); x = window->_ressources->_sliderNormal->getSize()._x / 3; } else if (window->getSettings()->getDefaultDifficulty() == Settings::MEDIUM_MODE) { diff = std::to_string(E_MEDIUM); x = window->_ressources->_slide->getSize()._x / 2; } else { diff = std::to_string(E_HARD); x = window->_ressources->_slide->getSize()._x - window->_ressources->_sliderNormal->getSize()._x / 3; } Text *easy = new Text(); easy->setString("EASY"); easy->setSize(15); easy->setStyle(1); easy->setOrigin(easy->getText().getGlobalBounds().width / 2, easy->getText().getGlobalBounds().height / 2); easy->setPosition(Vector2((window->getSize()._x / 2) - (window->_ressources->_slide->getSize()._x / 2), window->getSize()._y * 0.27)); easy->setColor(Color::WHITE); _labels.push_back(*easy); Text *medium = new Text(); medium->setString("MEDIUM"); medium->setSize(15); medium->setStyle(1); medium->setOrigin(medium->getText().getGlobalBounds().width / 2, medium->getText().getGlobalBounds().height / 2); medium->setPosition(Vector2((window->getSize()._x / 2), window->getSize()._y * 0.27)); medium->setColor(Color::WHITE); _labels.push_back(*medium); Text *hard = new Text(); hard->setString("HARD"); hard->setSize(15); hard->setStyle(1); hard->setOrigin(hard->getText().getGlobalBounds().width / 2, hard->getText().getGlobalBounds().height / 2); hard->setPosition(Vector2((window->getSize()._x / 2) + (window->_ressources->_slide->getSize()._x / 2), window->getSize()._y * 0.27)); hard->setColor(Color::WHITE); _labels.push_back(*hard); Text *difficulty = new Text(); difficulty->setString("DIFFICULTY"); difficulty->setSize(40); difficulty->setStyle(1); difficulty->setOrigin(difficulty->getText().getGlobalBounds().width / 2, difficulty->getText().getGlobalBounds().height / 2); difficulty->setPosition(Vector2(window->getSize()._x * 0.5, window->getSize()._y * 0.14)); difficulty->setColor(Color::WHITE); _labels.push_back(*difficulty); Sprite *slideDifficulty = new Sprite; slideDifficulty->setTexture(*((window)->_ressources->_slide)); slideDifficulty->setPosition((window->getSize()._x / 2) - (window->_ressources->_slide->getSize()._x / 2), window->getSize()._y * 0.2); // x = 0; _difficulty = ButtonFactory::createSlider(Vector2(slideDifficulty->getPosX() + x, window->getSize()._y * 0.2 + (window->_ressources->_sliderNormal->getSize()._y / 2)), name, slideDifficulty->getPosX(), slideDifficulty->getPosX() + window->_ressources->_slide->getSize()._x); ANetwork *net = Client::getNetwork(); ANetwork::t_frame sender; // setSlider(window->getSettings()->getDefaultDifficulty() + 1); sender = CreateRequest::create((unsigned char)C_CHANGE_SETTINGS, CRC::calcCRC(diff), 0, diff); net->write(sender); _backgrounds.push_back(*slideDifficulty); }
void RoomPanel::createPlayers() { RenderWindow *window = RenderWindow::getInstance(); unsigned int i = 0; std::string empty = ""; while (i < 4) { Text *username = new Text(); Sprite *blackShip = new Sprite; Player *player = new Player; player->setUsername(empty); player->setCurrentClient(false); blackShip->setTexture(*_spaceShipsTextures.at(0)); blackShip->setPosition(0.2 * (i + 1) * window->getSize()._x, 0.6 * window->getSize()._y); blackShip->getSprite().setOrigin(_spaceShipsTextures.at(0)->getSize()._x / 2, _spaceShipsTextures.at(0)->getSize()._y / 2); blackShip->scale(0.4); username->setString(player->getUsername()); username->setSize(40); username->setStyle(1); username->setOrigin(username->getText().getGlobalBounds().width / 2, username->getText().getGlobalBounds().height / 2); username->setPosition(Vector2(0.2 * (i + 1) * window->getSize()._x, 0.8 * window->getSize()._y)); username->setColor(Color::WHITE); window->getPanels().top()->getBackgrounds().push_back(*blackShip); window->getPanels().top()->getLabels().push_back(*username); _players.push_back(player); i++; } Text *roomID = new Text(); roomID->setString(_idRoom); roomID->setSize(60); roomID->setStyle(1); roomID->setOrigin(roomID->getText().getGlobalBounds().width / 2, roomID->getText().getGlobalBounds().height / 2); roomID->setPosition(Vector2(0.5 * window->getSize()._x, 0.03 * window->getSize()._y)); roomID->setFont(*((RenderWindow::getInstance())->_ressources->_fontSecond)); roomID->setColor(Color::WHITE); _labels.push_back(*roomID); _nbPlayers = 0; i = 0; while (i < 4) { Sprite *fireShip = new Sprite; fireShip->setTexture(*((RenderWindow::getInstance())->_ressources->_reactor)); fireShip->setPosition(220 + 0.2 * (i + 1) * window->getSize()._x, 0.765 * window->getSize()._y); fireShip->getSprite().setOrigin(_spaceShipsTextures.at(0)->getSize()._x / 2, _spaceShipsTextures.at(0)->getSize()._y / 2); fireShip->getSprite().setColor(sf::Color(255, 255, 255, 0)); window->getPanels().top()->getBackgrounds().push_back(*fireShip); i++; } }