예제 #1
0
    TestBox(bool isCollidable) :
        sg::Entity(isCollidable)
    {

        r0.setSize(sf::Vector2f(100.0f, 50.0f));
        r0.setOrigin(50.0f, 25.0f);
        this->addDrawable(r0, false);
        bs.addShape(r0);
        r1.setRadius(40.0f);
        r1.setOrigin(40.0f, 40.0f);
        r1.move(100.0f, 0.0f);
        r1.scale(2.0f, 1.0f);
        this->addDrawable(r1, false);
        bs.addShape(r1);
        r2.setSize(sf::Vector2f(250.0f, 10.0f));
        r2.setOrigin(125.0f, 5.0f);
        r2.rotate(-90.0f);
        this->addDrawable(r2, false);
        bs.addShape(r2);
        r3.setRadius(40.0f);
        r3.setOrigin(40.0f, 40.0f);
        r3.move(-100.0f, 0.0f);
        this->addDrawable(r3, false);
        bs.addShape(r3);
        //bs.rotate(-45.0f);
        this->addTransformable(bs);
        //this->rotate(45.0f);

    }
예제 #2
0
	Pong() : gameWindow(sf::VideoMode(600, 480), "Pong")
	{
		ball.setFillColor(sf::Color::Cyan);
		ball.setPosition(100.0, 100.0);
		ball.setRadius(10.f);

		p1Paddle.setFillColor(sf::Color::Green);
		p1Paddle.setPosition(10.0, 100.0);
		p1Paddle.setSize(sf::Vector2f(10.0, 100.0));

		p2Paddle.setFillColor(sf::Color::Red);
		p2Paddle.setPosition(580.0, 100.0);
		p2Paddle.setSize(sf::Vector2f(10.0, 100.0));

		p1MovingUp = false;
		p1MovingDown = false;
		p2MovingUp = false;
		p2MovingDown = false;

		ballMovement = sf::Vector2f(ballSpeed, ballSpeed);
		font.loadFromFile("arial.ttf");

		p1ScoreText.setPosition(150, 10);
		p1ScoreText.setFont(font);
		p1ScoreText.setString(std::to_string(p1Score));
		p1ScoreText.setColor(sf::Color::Red);
		p1ScoreText.setCharacterSize(24);

		p2ScoreText.setPosition(450, 10);
		p2ScoreText.setFont(font);
		p2ScoreText.setString(std::to_string(p2Score));
		p2ScoreText.setColor(sf::Color::Red);
		p2ScoreText.setCharacterSize(24);
	}
예제 #3
0
파일: ogre_obj.hpp 프로젝트: dvbuntu/ogre
 // 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));
 }
예제 #4
0
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);*/
}
예제 #5
0
파일: ogre_obj.hpp 프로젝트: dvbuntu/ogre
 // 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));
 }
예제 #6
0
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
}
예제 #7
0
 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);
 }
예제 #8
0
파일: p04.cpp 프로젝트: Boza-s6/cppcon2014
 // As with the ball, we construct the paddle with
 // arguments for the initial position and initialize
 // the SFML rectangle shape.
 Paddle(float mX, float mY)
 {
     shape.setPosition(mX, mY);
     shape.setSize({defWidth, defHeight});
     shape.setFillColor(defColor);
     shape.setOrigin(defWidth / 2.f, defHeight / 2.f);
 }
예제 #9
0
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);
}
예제 #10
0
    Board(int n, sf::Vector2f pos){

        boardSprite.setSize(sf::Vector2f(n, 2));
        boardSprite.setFillColor(sf::Color::Blue);
        boardSprite.setPosition(pos);

    }
	Player(sf::Vector2f position, sf::Vector2f size)
	{
		once = true;
		rect.setPosition(position);
		rect.setSize(size);
		rect.setFillColor(sf::Color::Green);
	}
예제 #12
0
 obstacle(sf::Vector2f p)
 {
     pos = p;
     r.setPosition(p);
     r.setSize(sf::Vector2f(50,50));
     r.setFillColor(sf::Color(255, 205, 210));
 }
예제 #13
0
 el(sf::Vector2f p)
 {
     r.setSize(sf::Vector2f(50,50));
     r.setFillColor(sf::Color(2,136,209));
     pos = p;
     r.setPosition(pos);
 }
예제 #14
0
 el(int x , int y)
 {
     r.setSize(sf::Vector2f(50,50));
     r.setFillColor(sf::Color(2,136,209));
     pos.x = x;
     pos.y = y;
     r.setPosition(pos);
 }
예제 #15
0
 Particle(sf::Vector2i position)
 {
     rect.setSize(sf::Vector2f(2,2));
     rect.setOrigin( sf::Vector2f(1,1) );
     rect.setFillColor( sf::Color::Red );
     rect.setPosition( (sf::Vector2f)position );
     velocity = sf::Vector2f(0,0);
 }
예제 #16
0
    food()
    {
        srand(time(NULL));
        r.setSize(sf::Vector2f(50,50));
        r.setFillColor(sf::Color(255,193,7));
        generatePos();

    }
예제 #17
0
sf::RectangleShape Spriteeditor::shapeRealBorder(Sprite * sprite, sf::RectangleShape shape)
{
	shape.setPosition(sprite->getPosition().x, sprite->getPosition().y);
	sf::Rect<float> border = sprite->getLocalBounds();
	shape.setSize(sf::Vector2f(border.width, border.height));
	shape.setScale(sprite->getScale());
	shape.setRotation(sprite->getRotation());
	return shape;
}
예제 #18
0
 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);
 }
예제 #19
0
파일: Goomba.hpp 프로젝트: W0Z4/ProjetMario
	Goomba(float i, float j) {
		_rect.setSize(sf::Vector2f(32, 32));
		_rect.setFillColor(sf::Color::Blue);
		if (_textureG.loadFromFile("goomba.png")) {
			_textureG.setSmooth(true);
			_spriteG.setTexture(_textureG);
			_spriteG.setScale(1.9, 1.9);
		}
		_spriteG.setPosition(50, 350);
	}
bool game_init()
{
     r.setPosition(100, 100);
    r.setFillColor(sf::Color(255, 255, 255));
    r.setSize(sf::Vector2f(20, 20));
    color = sf::Color::White;


    return true;
}
예제 #21
0
        void handle () {
            rotate();
            float percentageHealth = float((Health/MaxHealth) * 100);
            HealthBarGreen.setSize(sf::Vector2f(percentageHealth * (HealthBarSize / percentageHealth), 5));

            NameOutline.setPosition(Sprite.getPosition().x + 1.5, Sprite.getPosition().y + nameSpacing + 4);
            PlayerName.setPosition(Sprite.getPosition().x, Sprite.getPosition().y + nameSpacing);
            HealthBarRed.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing);
            HealthBarGreen.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing);
            }
예제 #22
0
    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);
    }
예제 #23
0
 StatusBox(uint _x, uint _y, float _width, float _height, const GuiStyle& _style) :
     BaseBox(_x, _y, _width, _height, _style)
 {
     blackbox = new sf::RectangleShape();
     blackbox->setFillColor(sf::Color::Black);
     blackbox->setSize({_width, _height});
     blackbox->setPosition(sf::Vector2f(_x, _y));
     
     textbox = new sf::Text;
     textbox->setPosition(_x, _y);
     textbox->setFont(*style.font);
     textbox->setCharacterSize(style.fontsize);
 }
예제 #24
0
void cWindow::paintLighting()
{
	float power;
	int tex;
	int lightsDisplayed = 0;
	int priority = 0;

	for (int a = 0; a < 2; a++)
	{
		priority = 0;
		while (priority < LIMIT_PRIORITY_LIGHT && lightsDisplayed < game.unitCounter)
		{
			for (int i = 0; i < game.unitCounter; i++)
			{
				if (game.unit[i].light.priority == priority && game.unit[i].light.power > 0 && game.unit[i].light.texture != -1)
				{
					tex = game.unit[i].light.texture;
					brushRect.setTexture(&visual.gameTex[tex].handle);
					brushRect.setPosition(game.unit[i].pos);
					brushRect.setFillColor(sf::Color(255, 255, 255, max(0.00f, min(255.00f, 300.00f - game.ambientLight))));
					if (!settings.enableDynamicLight) {
						brushRect.setTexture(&visual.gameTex[visual.addTexture("light_white.png")].handle);
						brushRect.setFillColor(sf::Color(255, 255, 255, 50.00f));
					}
					brushRect.setTextureRect(sf::IntRect(0, 0, visual.gameTex[tex].handle.getSize().x, visual.gameTex[tex].handle.getSize().y));
					power = game.unit[i].light.power;
					if (game.unit[i].light.flickerMod != 0.00f) {
						power += power * (game.unit[i].light.flickerMod * abs(game.unit[i].light.flickerCurTime / game.unit[i].light.flickerTime - 1.00f));
						power += math.randf(-5.00f, 5.00f);
					}
					brushRect.setOrigin(sf::Vector2f(power, power));
					brushRect.setSize(sf::Vector2f(power * 2.00f, power * 2.00f));
					// Directional
					brushRect.setRotation(0.00f);
					if (game.unit[i].light.directional) {
						brushRect.setRotation(-game.unit[i].facingAngle);
					}
					// Painting to two textures
					if (settings.enableDynamicLight && a == 0) { window.texHandleLight.draw(brushRect, window.matrixHandle); }
					else if (settings.enableDynamicLight && a == 1) { window.texHandleLightMult.draw(brushRect, window.matrixHandle); }
					else { window.texHandle.draw(brushRect, window.matrixHandle); }
				}
			}
			priority += 1;
		}
		if (!math.intToBool(settings.enableBetterLight)) { break; }
	}
	brushRect.setRotation(0.00f);
	window.texHandleLight.display();
	if (settings.enableBetterLight) { window.texHandleLightMult.display(); }
}
예제 #25
0
파일: Player.cpp 프로젝트: niyazm/2DShooter
void Player::collision(Player & character, Enemy & foe, sf::RectangleShape &Lifebar)
{
	// Bounding box
	sf::FloatRect boundbox = character.player.getGlobalBounds();
	sf::FloatRect enemybox = foe.enemy.getGlobalBounds();

	// Check collision
	if(boundbox.intersects(enemybox))
	{
			character.health = character.health - 30;
			foe.health = foe.health - 20;
            Lifebar.setSize(sf::Vector2f(character.health*character.LifebarRatio, character.LifebarSize));
	}
}
예제 #26
0
파일: Player.cpp 프로젝트: niyazm/2DShooter
void Player::bulletcollision(Player & character, Ebullet &bullet, sf::RectangleShape &Lifebar)
{
	// Bounding box
	sf::FloatRect boundbox = character.player.getGlobalBounds();
	sf::FloatRect bulletbox = bullet.bullets.getGlobalBounds();

	// Check collision
	if(boundbox.intersects(bulletbox))
	{
			character.health = character.health - 10;
			bullet.bullets.setPosition(-40,-40);
			bullet.activeB = false;
            Lifebar.setSize(sf::Vector2f(character.health*character.LifebarRatio, character.LifebarSize));
	}
}
예제 #27
0
	// Rendu
	void draw(sf::RenderTarget& renderer, const sf::Vector2f& center)
	{

		sf::Vector2f position(center);
		_text.setString(_label);
		position.x -= _text.getLocalBounds().width / 2.0f;
		position.y -= _text.getLocalBounds().height / 2.0f;
		_border.setSize(sf::Vector2f(_text.getLocalBounds().width + 10,
									 _text.getLocalBounds().height + 10));
		_border.setPosition(position);

		_text.setPosition(position);
		renderer.draw(_text);
		renderer.draw(_border);
	}
	void Update(sf::RenderWindow &Window)
	{
		if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
		{
			rect.setPosition(selectDown);
			selectCurrent.x = sf::Mouse::getPosition(Window).x - selectDown.x;
			selectCurrent.y = sf::Mouse::getPosition(Window).y - selectDown.y;
			rect.setSize(selectCurrent);
			Window.draw(rect);
		}
		else
		{
			selectDown.x = sf::Mouse::getPosition(Window).x;
			selectDown.y = sf::Mouse::getPosition(Window).y;
		}
	}
예제 #29
0
파일: Player.cpp 프로젝트: niyazm/2DShooter
bool Player::isdead(Player &character,sf::Sound &death, sf::RectangleShape &Lifebar)
{
	deadimg.loadFromFile(resourcePath() + "deadplayer.png");
	if(character.health <= 0)
	{
		if(character.active == true)
		{
			death.play();
		}
		character.player.setTexture(deadimg);
		character.active = false;
        Lifebar.setSize(sf::Vector2f(0,0));
	}

	return character.active;
}
예제 #30
0
void TextBox::Setup(int visible, int charSize, int width, sf::Vector2f screenPos)
{
	_numVisible = visible;

	sf::Vector2f offset(2.0f, 2.0f);

	_font.loadFromFile("arial.ttf");
	_content.setFont(_font);
	_content.setString("");
	_content.setCharacterSize(charSize);
	_content.setColor(sf::Color::White);
	_content.setPosition(screenPos + offset);

	auto backdropHeight = visible * (charSize * 1.2f);
	_backdrop.setSize(sf::Vector2f(width, backdropHeight));
	_backdrop.setFillColor(sf::Color(90, 90, 90, 90));
	_backdrop.setPosition(screenPos);
}