void WindowCreateThing::init(sf::RenderWindow &window) { rectTitle.setSize(sf::Vector2f(window.getSize().x*0.45, window.getSize().y*0.07)); rectTitle.setPosition(sf::Vector2f(window.getSize().x/2-(rectTitle.getSize().x/2), window.getSize().x/4-(rectTitle.getSize().y/2))); rectTitle.setFillColor(sf::Color(158, 158, 158)); rectTitle.setOutlineColor(sf::Color::Black); rectTitle.setOutlineThickness(1.f); rectMain.setSize(sf::Vector2f(window.getSize().x*0.45,window.getSize().y*0.45)); rectMain.setPosition(sf::Vector2f(rectTitle.getPosition().x, rectTitle.getPosition().y+rectTitle.getSize().y)); rectMain.setFillColor(sf::Color::White); rectMain.setOutlineColor(sf::Color::Black); rectMain.setOutlineThickness(1.f); load(); starting_position = sf::Mouse::getPosition(window); textTitle.setFont(font); textTitle.setString("CreateThings.txt"); textTitle.setCharacterSize(24); textTitle.setColor(sf::Color::White); textTitle.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x*0.3, rectTitle.getPosition().y+rectTitle.getSize().y*0.1)); //textTitle.setPosition(sf::Vector2f(400,10)); textClose.setFont(font); textClose.setString("X"); textClose.setStyle(sf::Text::Bold); textClose.setCharacterSize(35); textClose.setColor(sf::Color::White); textClose.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x-30, rectTitle.getPosition().y+rectTitle.getSize().y*0.05)); ///// FOLDER ICONE textureFolder.setSmooth(true); spriteFodler.setTexture(textureFolder); sf::Vector2f targetSize(25.0f, 25.0f); spriteFodler.setScale( targetSize.x / spriteFodler.getLocalBounds().width, targetSize.y / spriteFodler.getLocalBounds().height); spriteFodler.setPosition(sf::Vector2f(textTitle.getPosition().x-targetSize.x, textTitle.getPosition().y)); ///// CLOSE ICONE /*textureClose.setSmooth(true); spriteClose.setTexture(textureClose); sf::Vector2f targetSize2(window.getSize().y*0.07, window.getSize().y*0.07); spriteClose.setScale( targetSize2.x / spriteClose.getLocalBounds().width, targetSize2.y / spriteClose.getLocalBounds().height); spriteClose.setPosition(rectTitle.getPosition().x+rectTitle.getSize().x-targetSize2.x, rectTitle.getPosition().y);*/ }
void Sprited::draw(sf::RenderWindow *window) { // Scroll sprite sf::Vector2i shift = this->currentAnimation->frames[this->currentFrame]; this->sprite.setTextureRect(sf::IntRect(shift.x, shift.y, this->width, this->height)); this->sprite.setRotation((this->getWRotation() - this->camera->getWRotation()) / (2 * M_PI) * 360); // + this->wRotation / (2 * M_PI) * 360); if (this->camera) { // Transform sprite wPosition based on camera wPosition & wRotation this->sprite.setPosition(this->applyCameraTransformation(this->getWPosition())); } else { // No camera set, meaning this object's wPosition is not affected by camera. this->sprite.setPosition(this->getWPosition().x, this->getWPosition().y); } window->draw(this->sprite); Movable::draw(window); #ifdef DEBUG static sf::RectangleShape origin; origin.setOrigin(2, 2); origin.setSize(sf::Vector2f(5, 5)); origin.setPosition(this->sprite.getPosition()); origin.setFillColor(sf::Color(255, 0, 0, 128)); window->draw(origin); static sf::RectangleShape rect; rect.setFillColor(sf::Color::Transparent); rect.setOutlineThickness(1); rect.setOutlineColor(sf::Color::Blue); rect.setOrigin(this->sprite.getOrigin()); rect.setPosition(this->sprite.getPosition()); rect.setRotation(this->sprite.getRotation()); rect.setSize(sf::Vector2f(this->sprite.getTextureRect().width, this->sprite.getTextureRect().height)); window->draw(rect); sf::FloatRect wHitbox = this->getWHitbox(); static sf::RectangleShape hitboxRect; hitboxRect.setFillColor(sf::Color::Transparent); hitboxRect.setOutlineThickness(1); hitboxRect.setOutlineColor(sf::Color::Red); hitboxRect.setOrigin(sf::Vector2f(wHitbox.width / 2, wHitbox.height / 2)); hitboxRect.setSize(sf::Vector2f(wHitbox.width, wHitbox.height)); hitboxRect.setPosition(this->applyCameraTransformation(this->getWPosition())); hitboxRect.setRotation(-this->camera->getWRotation() / M_PI * 180); window->draw(hitboxRect); #endif }
inline TextSquare(Ctx& mCtx, const Vec2f& mPos) : Base{mCtx, mPos} { text = &create<Text>(ssvs::zeroVec2f); bg.setSize(Vec2f{65, 65}); bg.setOutlineColor(sf::Color::White); bg.setOutlineThickness(3); }
void PongGame::setUpBall(int const mainWindowWidth, int const mainWindowHeight, sf::RectangleShape &ball) { ball.setPosition(mainWindowWidth / 2, mainWindowHeight / 2); ball.setSize(sf::Vector2f(20, 20)); ball.setFillColor(sf::Color::Red); ball.setOutlineColor(sf::Color::Yellow); ball.setOutlineThickness(2); }
void init(const sf::Vector2f& position, const string filename) { _event = Event::NONE; _shape->setPosition(position); _shape->setSize(sf::Vector2f(TAILLE_SQUARE, TAILLE_SQUARE)); _shape->setFillColor(sf::Color::Black); _shape->setOutlineColor(sf::Color::White); _shape->setOutlineThickness(1); }
// Post battle update inline void set_info(int str) { info_str.setString(std::to_string(str)); health_bar_bg.setSize(sf::Vector2f(get_max_hp()/scale, 10)); health_bar_bg.setOutlineColor(sf::Color(125,125,125)); health_bar_bg.setOutlineThickness(1); health_bar_current.setSize(sf::Vector2f(str/scale, 10)); health_bar_current.setFillColor(get_life_color(str)); }
// Set some information about the object inline void set_info(int str, sf::Font *font, int size) { info_str.setString(std::to_string(str)); info_str.setFont(*font); info_str.setCharacterSize(size); info_str.setColor(sf::Color::Black); health_bar_bg.setSize(sf::Vector2f(get_max_hp()/scale, 10)); health_bar_bg.setOutlineColor(sf::Color(125,125,125)); health_bar_bg.setOutlineThickness(1); health_bar_current.setSize(sf::Vector2f(str/scale, 10)); health_bar_current.setFillColor(get_life_color(str)); }
Info(sf::String& text) { box.setPosition(100,100); box.setFillColor(sf::Color(245,248,6)); box.setSize(sf::Vector2f(300,300)); box.setOutlineColor(sf::Color::Red); box.setOutlineThickness(3); InfoText.setString(text); InfoText.setPosition(110,110); InfoText.setFillColor(sf::Color::White); }
// Constructeur & destructeur Observer(const sf::Vector2f& center) { //sf::Font font; assert(_font.loadFromFile("vera.ttf") == true); _text.setColor(sf::Color::White); _text.setFont(_font); _text.setCharacterSize(50); _text.setStyle(sf::Text::Italic); _border.setPosition(center); _border.setOutlineColor(sf::Color::White); _border.setOutlineThickness(2.0); _border.setFillColor(sf::Color::Transparent); }
BroadphaseDemo(sf::RenderWindow &window) : Demo(window), broadphase(100, 100), mouseObject(sf::Vector2f(50, 50)) { // set up our mouse object mouseObject.setOrigin(mouseObject.getSize() / 2.0f); mouseObject.setOutlineThickness(2); mouseObject.setFillColor(sf::Color(0, 200, 0)); // set up some random rectangles for (size_t i = 0; i < 2500; ++i) { sf::RectangleShape *object = new sf::RectangleShape(sf::Vector2f(randb(5, 15), randb(5, 15))); object->setOrigin(object->getSize() / 2.0f); object->setOutlineThickness(2); objects.push_back(object); } }
void Map::spawnFood() // Fix so doesn't spawn on snake { //Generate Random Numbers For Grid Pos For Food srand(time(NULL)); int randomTile = rand() % numTiles; if(foodSpawned != true) { food.setSize(sf::Vector2f(18, 18)); food.setFillColor(sf::Color::Red); sf::Color outlineColour(145, 145, 145); food.setOutlineColor(outlineColour); food.setOutlineThickness(2); food.setPosition(tiles[randomTile].getPosition().x, tiles[randomTile].getPosition().y); foodSpawned = true; } else { food.setPosition(tiles[randomTile].getPosition().x, tiles[randomTile].getPosition().y); } }
Selection(float thickness, sf::Color color) { rect.setFillColor(sf::Color::Transparent); rect.setOutlineThickness(thickness); rect.setOutlineColor(color); }
Player () { PlayerNumber = totalPlayers; Sprite = loadSpriteData("Player " + intToString(PlayerNumber + 1)); //Get Global width, seperate to rotation CharacterWidth = Sprite.getGlobalBounds().width; nameSpacing = 30; healthBarSpacing = nameSpacing + 15; Sprite.setOrigin(Sprite.getGlobalBounds().width/2, Sprite.getGlobalBounds().height/2); Sprite.setPosition((App.getSize().x/2) - (Sprite.getGlobalBounds().width/2), (App.getSize().y/2) - (Sprite.getGlobalBounds().height/2)); //PlayerName.setFont(sf::Font::getDefaultFont()); PlayerName.setCharacterSize(15); PlayerName.setString("Player: " + intToString(PlayerNumber + 1)); PlayerName.setOrigin(PlayerName.getGlobalBounds().width/2, PlayerName.getGlobalBounds().height/2); PlayerName.setPosition(Sprite.getPosition().x, Sprite.getPosition().y + nameSpacing); NameOutline.setSize(sf::Vector2f(PlayerName.getGlobalBounds().width, PlayerName.getGlobalBounds().height)); NameOutline.setOutlineThickness(2); NameOutline.setFillColor(sf::Color(0, 0, 0, 120)); NameOutline.setOutlineColor(sf::Color::Black); NameOutline.setOrigin(NameOutline.getGlobalBounds().width/2, NameOutline.getGlobalBounds().height/2); NameOutline.setPosition(Sprite.getPosition().x + 1.5, Sprite.getPosition().y + nameSpacing + 4); MaxHealth = Health = 100; HealthBarSize = 50; HealthBarRed.setSize(sf::Vector2f(HealthBarSize, 5)); HealthBarRed.setOutlineThickness(1); HealthBarRed.setFillColor(sf::Color::Red); HealthBarRed.setOutlineColor(sf::Color::Black); HealthBarRed.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing); HealthBarGreen.setSize(sf::Vector2f(HealthBarSize, 5)); HealthBarGreen.setOutlineThickness(1); HealthBarGreen.setFillColor(sf::Color::Green); HealthBarGreen.setOutlineColor(sf::Color::Black); HealthBarGreen.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing); if (controllerConnected) { ControlScheme = ControlSchemes::Joystick; Key k; k.InputType = Input::JoystickMovedNeg; k.KeyCode = sf::Joystick::Axis::Y; Bindings["Up"] = k; k.InputType = Input::JoystickMovedPos; k.KeyCode = sf::Joystick::Axis::Y; Bindings["Down"] = k; k.InputType = Input::JoystickMovedNeg; k.KeyCode = sf::Joystick::Axis::X; Bindings["Left"] = k; k.InputType = Input::JoystickMovedPos; k.KeyCode = sf::Joystick::Axis::X; Bindings["Right"] = k; } else { ControlScheme = ControlSchemes::KeyboardMouse; Key k; k.InputType = Input::KeyboardInput; k.KeyCode = sf::Keyboard::W; Bindings["Up"] = k; k.InputType = Input::KeyboardInput; k.KeyCode = sf::Keyboard::S; Bindings["Down"] = k; k.InputType = Input::KeyboardInput; k.KeyCode = sf::Keyboard::A; Bindings["Left"] = k; k.InputType = Input::KeyboardInput; k.KeyCode = sf::Keyboard::D; Bindings["Right"] = k; } totalPlayers++; }
void main() { menu(); while(true){ sf::Clock clock, clockInvincible; score1 = 0; int xBlock, yBlock, x, y, seconds = 0, red, green, blue; int direction = 0, directionOfBack = 0, size; bool checkGameOver = false, outOfBounds = false, restarter = false, breaker = false; size = Robjects.size(); Robjects.erase(Robjects.begin()+0, Robjects.begin()+size); window.clear(); //--------------------------------------------------------------------------- //sf::RenderWindow window(sf::VideoMode(600, 500), "Testing"); //--------------------------------------------------------------------------- event.type = sf::Event::Count; sf::RectangleShape square(sf::Vector2f(sizex, sizey)); square.setFillColor(sf::Color(200, 60, 0)); square.setOutlineThickness(2); square.setOutlineColor(sf::Color(140, 30, 0)); //--------------------------------------------------------------------------- sf::RectangleShape egg(sf::Vector2f(sizex + 2, sizey + 2)); egg.setFillColor(sf::Color(red, green, blue)); egg.setOutlineThickness(2); egg.setOutlineColor(sf::Color(200, 200, 200)); //--------------------------------------------------------------------------- setAll(x, y, xBlock, yBlock); //--------------------------------------------------------------------------- egg.setPosition(xBlock, yBlock); //--------------------------------------------------------------------------- setEgg(red, green, blue); while(window.isOpen()) { if(invincible1 == true){ invincible2(x, y); for(int i = 0; i < Robjects.size(); i++){ Robjects[i].setFillColor(sf::Color(200, 50, 50)); Robjects[i].setOutlineThickness(2); Robjects[i].setOutlineColor(sf::Color(40, 40, 40)); } } else outOfBounds = checkOutOfBounds(x , y); sf::Time elapsed1 = clock.getElapsedTime(); seconds = elapsed1.asMilliseconds(); //--------------------------------------------------------------------------- restarter = updateGame(x, y, xBlock, yBlock, direction, directionOfBack, checkGameOver, seconds, red, green, blue); egg.setFillColor(sf::Color(red, green, blue)); if(restarter == true) clock.restart(); directionOfBack = CreateTail(x, y, direction, checkGameOver, false); //--------------------------------------------------------------------------- if((x % 25 == 0)&&(y % 25 == 0)){ //------------------------------------------------------------ while(window.pollEvent(event)) { if(event.type == sf::Event::Closed){ size = Robjects.size(); Robjects.erase(Robjects.begin()+0, Robjects.begin()+size); window.close(); } //--------------------------------------------------------------------- if((event.key.code == sf::Keyboard::P)&&(event.type == sf::Event::KeyPressed)){ window.draw(square); for(int i = 0; i < Robjects.size(); i++) window.draw(Robjects[i]); if(eggs == true){} else window.draw(egg); window.draw(score); window.display(); while(true){ while(window.pollEvent(event)) { if((event.key.code == sf::Keyboard::P)&&(event.type == sf::Event::KeyPressed)) breaker = true; } if(breaker == true) break; } } breaker = false; event.key.code == sf::Keyboard::Q; if(event.type == sf::Event::KeyPressed){ direction = move(direction, x, y); square.setPosition(x,y); } } } //--------------------------------------------------------------------------- if((checkGameOver == true)||(outOfBounds == true)) { window.clear(); window.draw(square); for(int i = 0; i < Robjects.size(); i++) window.draw(Robjects[i]); window.draw(egg); window.draw(score); window.draw(gameOver); exit(); window.clear(); menu(); break; } //--------------------------------------------------------------------------- square.setPosition(x,y); egg.setPosition(xBlock, yBlock); window.clear(); window.draw(square); for(int i = 0; i < Robjects.size(); i++) window.draw(Robjects[i]); if(eggs == false){ window.draw(egg); } else{ for(int i = 0; i < 120; i++) window.draw(egger[i]); } if(invincible == true) { invincible3.setString("I"); invincible3.setFont(font); invincible3.setCharacterSize(10); invincible3.setColor(sf::Color(255, 255, 255)); invincible3.setPosition(xBlock + 4, yBlock + 4); window.draw(invincible3); } window.draw(score); window.display(); if(eggs == true) sf::sleep(sf::seconds(.0009)); else sf::sleep(sf::seconds(.003)); } } //return 0; }
void PongGame::setUpPlayer(sf::RectangleShape &player) { player.setSize(sf::Vector2f(borderSize, 90)); player.setFillColor(sf::Color(0, 122, 245)); player.setOutlineColor(sf::Color::Red); player.setOutlineThickness(3); }
void PongGame::setUpBorderRectangle(sf::RectangleShape &topRectangle) { const int outlineThickness = 3; topRectangle.setFillColor(sf::Color(100, 100, 100)); topRectangle.setOutlineColor(sf::Color::Blue); topRectangle.setOutlineThickness(outlineThickness); }
int main(){ logger.logNoEndl("Setting up window..."); window.create(sf::VideoMode(430,430), "GL"); logger.continueln(" done!"); logger.logNoEndl("Setting up variables..."); rect1.setFillColor(sf::Color(200,200,200)); rect1.setOutlineColor(sf::Color(0,0,0)); rect1.setOutlineThickness(-2); rect1.setPosition(10,10); rect2.setFillColor(sf::Color(200,200,200)); rect2.setOutlineColor(sf::Color(0,0,0)); rect2.setOutlineThickness(-2); rect2.setPosition(220,10); rect3.setFillColor(sf::Color(200,200,200)); rect3.setOutlineColor(sf::Color(0,0,0)); rect3.setOutlineThickness(-2); rect3.setPosition(10,220); rect4.setFillColor(sf::Color(200,200,200)); rect4.setOutlineColor(sf::Color(0,0,0)); rect4.setOutlineThickness(-2); rect4.setPosition(220,220); sf::Font font; if (!font.loadFromFile("arial.ttf")){ logger.log(Logger::LogType::Error, "Arial font not found. Cannot continue..."); return 1; } sf::Text label1("Solid White", font); label1.setColor(sf::Color::Black); label1.setPosition(rect1.getPosition().x + rect1.getSize().x / 2 - label1.getLocalBounds().width / 2, rect1.getPosition().y + rect1.getSize().y / 2 - label1.getLocalBounds().height / 2 - 10); sf::Text label2("Marquee", font); label2.setColor(sf::Color::Black); label2.setPosition(rect2.getPosition().x + rect2.getSize().x / 2 - label2.getLocalBounds().width / 2, rect2.getPosition().y + rect2.getSize().y / 2 - label2.getLocalBounds().height / 2 - 10); sf::Text label3("Color Cycle", font); label3.setColor(sf::Color::Black); label3.setPosition(rect3.getPosition().x + rect3.getSize().x / 2 - label3.getLocalBounds().width / 2, rect3.getPosition().y + rect3.getSize().y / 2 - label3.getLocalBounds().height / 2 - 10); sf::Text label4("Pew", font); label4.setColor(sf::Color::Black); label4.setPosition(rect4.getPosition().x + rect4.getSize().x / 2 - label4.getLocalBounds().width / 2, rect4.getPosition().y + rect4.getSize().y / 2 - label4.getLocalBounds().height / 2 - 10); unsigned short r = 0, g = 0, b = 0; logger.continueln(" done!"); logger.log("Running until told to stop."); bool running = true; while(running){ sf::Event event; while (window.pollEvent(event)){ if (event.type == sf::Event::Closed){ running = false; } else if (event.type == sf::Event::MouseMoved){ doMouseMove(); } else if (event.type == sf::Event::MouseButtonPressed || event.type == sf::Event::MouseButtonReleased){ doMouseButton(event.mouseButton.button); } } window.clear(sf::Color::White); window.draw(rect1); window.draw(rect2); window.draw(rect3); window.draw(rect4); window.draw(label1); window.draw(label2); window.draw(label3); window.draw(label4); window.display(); } logger.log("Closing..."); }