Beispiel #1
0
Image::Image(Menu* parent, const sf::Texture& img, float x, float y):
	Widget(parent, false)
{
	m_texture.setTexture(img);
	setPosition(x, y);
	Resize(img.getSize().x, img.getSize().y);
}
Beispiel #2
0
Sprite::Sprite(sf::Texture& texture, int width, int height, int frameCount, int speed, float offsetX, float offsetY, bool loop):
    sprite(texture),
    w(width),
    h(height),
    frame(0),
    numFrames(frameCount),
    timer(0),
    speed(speed),
    angle(0),
    scaleX(1.0),
    scaleY(1.0),
    offset(offsetX, offsetY),
    flipped(false),
    reverse(false),
    frozen(false),
    loop(loop),
    done(false)
{
    sprite.setOrigin(w/2, h/2);
    sprite.setTextureRect(sf::IntRect(0, 0, w, h));
    if(w > (int)(texture.getSize().x))
    {
        w = texture.getSize().x;
    }
    if( h > (int)(texture.getSize().y))
    {
        h = texture.getSize().y;
    }
    rows = texture.getSize().y / h;
    cols = texture.getSize().x / w;
    if(numFrames == -1)
    {
        numFrames = rows * cols;
    }
}
Beispiel #3
0
void HUD::init(const sf::Texture &healthBar, const sf::Texture &healthBarBackground, const std::vector<Entity*> *players, FontManager &fontManager, int mode)
{
	scoreText.setFont(*fontManager.getResource("Config/Content/Fonts/calibri.ttf"));
	scoreText.setPosition(20,40);
	scoreText.setColor(sf::Color::Black);
	this->mode = mode;

	for(unsigned int i = 0; i < players->size(); i++)
	{
		Player *playerPtr = dynamic_cast<Player*>(players->at(i)) ;

		if(playerPtr != NULL)
		{
			this->players.push_back(playerPtr);

			healthRecs.push_back(HealthBars(sf::RectangleShape(sf::Vector2f((float)healthBar.getSize().x, (float)healthBar.getSize().y)),
				sf::RectangleShape(sf::Vector2f((float)healthBarBackground.getSize().x, (float)healthBarBackground.getSize().y))));

			healthRecs.at(i).healthBar.setTexture(&healthBar);
			healthRecs.at(i).healthBarBackground.setTexture(&healthBarBackground);

			//hardcoded
			healthRecs.at(i).healthBar.setPosition(15, 15);
			healthRecs.at(i).healthBarBackground.setPosition(10, 10);

			/*healthRecs.push_back(sf::RectangleShape(this->players->at(i)->getPlayerBars().health.getSize()));
			healthRecs.at(i).setTexture(this->players->at(i)->getPlayerBars().health.getTexture());
			healthRecs.at(i).setTextureRect(this->players->at(i)->getPlayerBars().health.getTextureRect());*/
		}
	}

	pClock.restart();
}
Beispiel #4
0
void menu::f_addMenuItem(sf::RenderWindow &app, sf::Texture &texture, sf::Texture &hoverTexture, std::string menuType, std::string newMenu, std::string location, sf::Vector2f position, float scaleX, float scaleY)
{
	/* Setting texture and sprite */
	m_item.setTexture(texture);
	m_item.setTextureRect(sf::IntRect(0, 0, hoverTexture.getSize().x, hoverTexture.getSize().y));
	std::cout << m_item.getTexture() << std::endl;
	m_item.setScale(scaleX, scaleY);
	f_setMenuPosition(location, position, app);
	m_menuItem.resize(m_menuItem.size() + 1);
	/* Add item */
	m_menuItem.at(m_menuItem.size() - 1).push_back(m_item);
	m_item.setTexture(hoverTexture);
	m_item.setTextureRect(sf::IntRect(0, 0, hoverTexture.getSize().x, hoverTexture.getSize().y));
	m_item.setScale(1.0f, 1.0f);
	m_item.setScale(scaleX, scaleY);
	m_menuItem[m_menuItem.size() - 1].push_back(m_item);
	std::cout << m_menuItem.size() << std::endl;
	/* Setting data into the menulist */

	m_menuList.resize(m_menuItem.size());
	m_menuList[m_menuItem.size() - 1].push_back(menuType);
	m_menuList[m_menuItem.size() - 1].push_back(location);
	m_menuList[m_menuItem.size() - 1].push_back("variable");
	m_menuList[m_menuItem.size() - 1].push_back(newMenu);
	m_menuList[m_menuItem.size() - 1].push_back("none");
}
Beispiel #5
0
Slider::Slider(const sf::Font& font, const sf::Texture& texture, float length, float maxValue)
    : m_maxValue    (maxValue),
    m_length        (length),
    m_direction     (Direction::Horizontal),
    m_handleSprite  (texture),
    m_slotShape     ({ length, thickness }),
    m_text          ("", font, 36u),
    m_valueText     ("0", font, 36u),
    m_borderColour  (borderColour),
    m_activeColour  (255u, 255u, 255u, 120u)
{
    sf::IntRect subrect(0, 0, texture.getSize().x, texture.getSize().y / 2u);
    m_subRects.push_back(subrect);
    subrect.top += subrect.height;
    m_subRects.push_back(subrect);

    m_handleSprite.setTextureRect(m_subRects[State::Normal]);

    Util::Position::centreOrigin(m_handleSprite);
    m_slotShape.setOrigin(0.f, thickness / 2.f);
    m_slotShape.setFillColor(fillColour);
    m_slotShape.setOutlineColor(m_borderColour);
    m_slotShape.setOutlineThickness(thickness / 2);

    m_valueChanged.push_back(std::bind(&Slider::valueChanged, this, std::placeholders::_1));
}
StaticPlatform::StaticPlatform(sf::Texture& texture, float initX, float initY, float rotation)
{
	_sprite.setTexture( texture );
	
	_sprite.setOrigin( texture.getSize().x / 2.f, texture.getSize().y / 2.f);

	_sprite.setRotation( rotation );

	_bodyDef.position.Set( MathHelper::ToUnit( initX ), MathHelper::ToUnit( initY ) ); 

	_bodyDef.angle = MathHelper::DegreeToRadian( rotation );

	_bodyDef.type = b2_staticBody;

	_bodyShape.SetAsBox( 
		MathHelper::ToUnit( texture.getSize().x / 2.f ),
		MathHelper::ToUnit( texture.getSize().y / 2.f )
	);

	cout << "(" << _bodyDef.position.x << "," << _bodyDef.position.y << ")" << endl;
	
	_fixtureDef.shape = &_bodyShape;
	_fixtureDef.density = 1.f;
	_fixtureDef.friction = 0.5f;
	_fixtureDef.restitution = 0.5f;

}
Beispiel #7
0
void Sprite::setTexture(const sf::Texture& texture, bool resetRect)
{
    // Recompute the texture area if requested, or if there was no valid texture & rect before
    if (resetRect || (!m_texture && (m_textureRect == sf::IntRect())))
        setTextureRect(sf::IntRect(0, 0, texture.getSize().x, texture.getSize().y));

    // Assign the new texture
    m_texture = &texture;
}
Beispiel #8
0
void Bouton::setIcone (sf::Texture& texture ){

    // on applique la texture
    m_icone.setTexture  ( &texture );

    // on reajuste la taille du textureRect à la nouvelle texture
    m_icone.setTextureRect( {0,0,texture.getSize().x, texture.getSize().y} );
    m_icone.setSize ( { texture.getSize().x, texture.getSize().y } );

}
Beispiel #9
0
void SpriteBody::setTexture(sf::Texture& texture, int sizeW, int sizeH, int frames, int msTime )
{
    if(sizeW <= 0)
        sizeW = texture.getSize().x;
    if(sizeH <= 0)
        sizeH = texture.getSize().y;

    m_animation.setAnimation(texture, sizeW, sizeH, frames, msTime);
    m_animation.getSprite().setOrigin(sizeW/2, sizeH/2);
}
Beispiel #10
0
Actor::Actor(sf::RenderWindow &window, b2World *world, b2FixtureDef &fixture, sf::Texture &texture, int current_index, int body_type, int shape_type)
{
	this->robot_base = new Object( window, world, fixture, texture, current_index, body_type, shape_type );

	this->jump_limit = 1.0; //the player is able to jump as often as this (in seconds)

	sf::Vector2f size( texture.getSize().x * 1.5, texture.getSize().y );
	sf::Vector2f pos( this->robot_base->getSprite()->getPosition() );

	this->healthbar = new Health( size, pos, 100, 100 );
}
TalkingSprite::TalkingSprite(const sf::Texture& texture, sf::Vector2f position, std::vector<sf::FloatRect>& collisionList, DNode* text)
: collisionBoxList(collisionList), whatItSays(text)
{
    setOrigin(texture.getSize().x/2, texture.getSize().y/2);
    for (auto && it : collisionBoxList) {
        it.left += position.x;
        it.top += position.y;
    }
    setTexture(texture);
    setPosition(position);

}
Beispiel #12
0
Player::Player(sf::Texture &texture, sf::Vector2f position)
{
	this->position = position;
	this->width = texture.getSize().x;
	this->height = texture.getSize().y;
	this->origin = sf::Vector2f(position.x + (width / 2), position.y + (height / 2));

	sprite.setTexture(texture);
	sprite.setPosition(position);

	moveSpeed = 7.0f;
}
Beispiel #13
0
Object::Object(sf::Texture &_texture
               , int _type
               , sf::Vector2f _position
               , bool _collidable
               , float _lifespan
               , float _value1
               , float _value2
               , float _value3
              )
    : texture(_texture)
    , type(_type)
    , sprite()
    , collidable(_collidable)
    , lifespan(_lifespan)
    , value1(_value1)
    , value2(_value2)
    , value3(_value3)
{
    sprite.setTexture(_texture);

    int x_width = _texture.getSize().x / 32;

    sf::Vector2u offset;

    offset.x = type % x_width;
    offset.y = type / x_width;

    sprite.setTextureRect(sf::IntRect(offset.x * 32, offset.y * 32, 32, 32));

    sprite.setPosition(_position);
    sprite.setOrigin(sprite.getLocalBounds().width / 2, sprite.getLocalBounds().height / 2);
    bounding_box = sf::IntRect(sprite.getLocalBounds().top, sprite.getLocalBounds().left, sprite.getLocalBounds().width, sprite.getLocalBounds().height);
}
Beispiel #14
0
void Ring::setTexture(const sf::Texture& texture, const bool resetRect)
{
    const bool textureWasNull{ (m_texture == nullptr) };
    m_texture = &texture;
    if (textureWasNull || resetRect)
        setTextureRect({ { 0, 0 }, sf::Vector2i(texture.getSize()) });
}
 void setSpriteSheet (sf::Texture* t, int frameWidth, std::vector <sf::Time> framesDur) {
     spriteSheet = t;
     width = frameWidth;
     frames = spriteSheet->getSize().x/width;
     height = spriteSheet->getSize().y;
     frameDurations = framesDur;
 }
Beispiel #16
0
Car::Car(sf::Texture &tex, float maxSpeed)
{
	m_acceleration = 0;
	m_rotation = 0;

	m_sprite.setTexture(tex);

	sf::Vector2u texSize(tex.getSize());
	m_sprite.setOrigin(float(texSize.x)/2.f, float(texSize.y)/2.f);

	m_hitBoxRadius = 93/2;

	m_maxSpeed = maxSpeed;
	m_speed = 0;

	m_font.loadFromFile("gameData/fonts/CANON.ttf");
	m_speedIndicator.setFont(m_font);

	std::stringstream stream;
	stream<< int(m_speed);
	std::string indicatorString;
	stream>> indicatorString;
	std::cout<< indicatorString<< '\n';

	m_speedIndicator.setString(indicatorString);
	m_speedIndicator.setCharacterSize(64);
	

	m_physicTimer.setDuration(sf::seconds(1./60.)); //60 fps
	m_physicTimer.restart();

}
Beispiel #17
0
	void DrawQuad(sf::Texture &Texture)
	{
		float halfWidth = Texture.getSize().x / 2.0f;
		float halfHeight = Texture.getSize().y / 2.0f;

		// Bind the texture
		Texture.bind();

		// Have to render upside-down because SFML loads the Textures upside-down
		glBegin(GL_QUADS);
			glTexCoord2i(0, 0); glVertex3f(-halfWidth, -halfHeight, 0.0f);
			glTexCoord2i(1, 0); glVertex3f(halfWidth, -halfHeight, 0.0f);
			glTexCoord2i(1, 1); glVertex3f(halfWidth, halfHeight, 0.0f);
			glTexCoord2i(0, 1); glVertex3f(-halfWidth, halfHeight, 0.0f);
		glEnd();
	}
 void setSpriteSheet (sf::Texture* t, int frameWidth, sf::Time dur) {
     spriteSheet = t;
     width = frameWidth;
     frames = spriteSheet->getSize().x/width;
     height = spriteSheet->getSize().y;
     frameDurations.resize(frames, dur);
 }
Beispiel #19
0
Selection::Selection(const sf::Font& font, const sf::Texture& texture, float length)
    : m_length          (length),
    m_selectedIndex     (0u),
    m_selectedText      ("", font, 36),
    m_prevArrow         (texture),
    m_nextArrow         (texture),
    m_background        ()
{
    sf::IntRect subrect({ 0, 0 }, sf::Vector2i(texture.getSize()));
    subrect.height /= State::Count;

    for (auto i = 0; i < State::Count; ++i)
    {
        m_subRects.push_back(subrect);
        subrect.top += subrect.height;
    }

    m_prevArrow.setTextureRect(m_subRects[State::Normal]);
    
    //flip one of the sprite arrows
    m_nextArrow.setScale(-1.f, 1.f);
    m_nextArrow.setPosition(length, 0.f);
    m_nextArrow.setTextureRect(m_subRects[State::Normal]);

    m_bounds.width = m_length;
    m_bounds.height = static_cast<float>(subrect.height);

    //m_background.setFillColor(sf::Color::Black);
    //m_background.setOutlineColor(borderColour);
    //m_background.setOutlineThickness(-borderThickness);
    //m_background.setSize({ m_length - static_cast<float>(subrect.width * 2.f), m_bounds.height - (borderThickness * 2.f) });
    //m_background.setOrigin(m_background.getSize() / 2.f);
    //m_background.setPosition(m_bounds.width / 2.f, m_bounds.height / 2.f);
}
Beispiel #20
0
	Player(const sf::Texture& tex, const sf::IntRect& rect, int hp,
		  float speed, bool invincibility, int lives) :
		lives(lives),
		Entity(tex, rect, hp, speed, invincibility)
	{
		frames = tex.getSize().x / rect.width;
		middle_frame = frames / 2;
	};
Beispiel #21
0
	void SpriteRenderer::changeTexture(const sf::Texture& texture){
		this->sprite = sf::Sprite(texture);
		this->size.x = texture.getSize().x * this->scale.x;
		this->size.y = texture.getSize().y * this->scale.y;

		setOrigin(this->origin);
		setSpritePosition(this->position);
		this->sprite.setScale(this->scale.x, this->scale.y);
	}
Beispiel #22
0
CheckBox::CheckBox(const sf::Font& font, const sf::Texture& t)
    : m_texture (t),
    m_text      ("", font, 36u),
    m_checked   (false),
    m_alignment (Alignment::TopLeft)
{
    sf::IntRect subRect(0, 0, t.getSize().x, t.getSize().y / 4);
    for (auto i = 0u; i < 4u; ++i)
    {
        m_subRects.push_back(subRect);
        subRect.top += subRect.height;
    }

    m_sprite.setTexture(t);
    m_sprite.setTextureRect(m_subRects[State::Normal]);

    m_text.setPosition(static_cast<float>(m_sprite.getLocalBounds().width) + textPadding, -6.f);
}
Beispiel #23
0
//public
void LineSegment::setTexture(const sf::Texture& texture)
{
	m_texture = &texture;

	sf::Vector2f texSize = static_cast<sf::Vector2f>(texture.getSize());
	m_vertexArray[1].texCoords = sf::Vector2f(texSize.x, 0.f);
	m_vertexArray[2].texCoords = texSize;
	m_vertexArray[3].texCoords = sf::Vector2f(0.f, texSize.y);
}
Beispiel #24
0
sf::Rect<float> GameGrid::InteractBounds() const
{
	return sf::Rect<float>(
		margin_left,
		margin_top,
		drive_tex.getSize().x - margin_right - margin_left,
		drive_tex.getSize().y - margin_bot - margin_top);

}
Beispiel #25
0
void Image(const sf::Texture& texture, const sf::Vector2f& size, const sf::FloatRect& textureRect,
    const sf::Color& tintColor, const sf::Color& borderColor)
{
    sf::Vector2f textureSize = static_cast<sf::Vector2f>(texture.getSize());
    ImVec2 uv0(textureRect.left / textureSize.x, textureRect.top / textureSize.y);
    ImVec2 uv1((textureRect.left + textureRect.width) / textureSize.x,
        (textureRect.top + textureRect.height) / textureSize.y);
    ImGui::Image((void*)texture.getNativeHandle(), size, uv0, uv1, tintColor, borderColor);
}
Beispiel #26
0
Animation::Animation(int frameWidth, int frameHeight, sf::Time frameTime, sf::Sprite& sprite, const sf::Texture& spriteSheet)
: sprite(sprite)
{
	this->nFrameWidth = frameWidth;
	this->nFrameHeight = frameHeight;

	this->frameTime = frameTime;
	this->currentFrameTime = sf::Time::Zero;
	this->nCurrentFrame = 0;

	this->nFramesPerRow = spriteSheet.getSize().x / nFrameWidth;
	this->nFramesTotal =
		spriteSheet.getSize().y / nFrameHeight *
		spriteSheet.getSize().x / nFrameWidth - 1;

	this->bIsPaused = false;
	this->bLoop = false;

	updateSourceRect();
}
Beispiel #27
0
  void draw (sf::RenderTarget& target, sf::RenderStates states) const
  {
    sf::Sprite toDraw(*texture);

    sf::Vector2u drawSize = texture->getSize();
    toDraw.setOrigin(drawSize.x / 2, drawSize.y);

    sf::Vector2u targetSize = target.getSize();
    toDraw.setPosition(targetSize.x / 2, targetSize.y);

    target.draw(toDraw, states);
  }
TimedSpikes::TimedSpikes(sf::Texture& texture, float initX, float initY, int repeatTimes,float restitution)
{
	//StaticPlatform(texture, initX, initY, repeatTimes);
	
	_sprite.setTexture( texture );

	//texture will be repeated 'repeatTimes' times along X-direction
	_sprite.setTextureRect( IntRect( 0, 0, repeatTimes * texture.getSize().x, texture.getSize().y ) ) ;

	texture.setRepeated( true );
	
	_sprite.setOrigin( repeatTimes * texture.getSize().x / 2.f, texture.getSize().y / 2.f);

	_bodyDef.position.Set( MathHelper::ToUnit( initX ), MathHelper::ToUnit( initY ) ); 

	//_bodyDef.angle = MathHelper::DegreeToRadian( rotation );

	_bodyDef.type = b2_staticBody;

	_bodyShape.SetAsBox( 
		MathHelper::ToUnit( repeatTimes * texture.getSize().x / 2.f ),
		MathHelper::ToUnit( texture.getSize().y / 2.f )
	);

	//cout << "(" << _bodyDef.position.x << "," << _bodyDef.position.y << ")" << endl;
	
	_fixtureDef.shape = &_bodyShape;
	_fixtureDef.density = 1.f;
	_fixtureDef.friction = 0.5f;
	_fixtureDef.restitution = restitution;
	
	cycleClock.restart();

}
SFMLColorPalette::SFMLColorPalette(const sf::Window& window, const sf::Image& colorImage, const sf::Texture& colorTexture)
	:SFMLGUIElement(window),
	 m_colorImage(&colorImage), m_display(colorTexture), 
	 m_backing(sf::Vector2f(static_cast<float>(colorTexture.getSize().x + 27.0f), static_cast<float>(colorTexture.getSize().y-1))), 
	 m_colorMagnify(sf::Vector2f(50.0f,50.0f)),
	 m_brightnessRect(sf::Vector2f(15.0f, colorTexture.getSize().y - 5.0f)),
	 m_selectedColor(sf::Color::White),
	 m_brightnessQuad(sf::TrianglesFan, 4),
	 m_brightness(1.0f),
	 m_brightnessSlider(sf::Vector2f(15.0f, 2.0f))
{
	m_backing.setFillColor(sf::Color::Blue);

	m_colorMagnify.setOutlineThickness(5.0f);
	m_colorMagnify.setOutlineColor(sf::Color::Black);

	m_brightnessRect.setOutlineThickness(2.0f);
	m_brightnessRect.setOutlineColor(sf::Color::White);
	m_brightnessRect.setPosition(colorTexture.getSize().x + 10.0f, 2.0f);
	m_brightnessRect.setFillColor(sf::Color::Black);

	
	m_brightnessQuad[0].position = m_brightnessRect.getPosition() + sf::Vector2f(m_brightnessRect.getSize().x, 0);
	m_brightnessQuad[1].position = m_brightnessRect.getPosition();
	m_brightnessQuad[2].position = m_brightnessRect.getPosition() + sf::Vector2f(0,m_brightnessRect.getSize().y);
	m_brightnessQuad[3].position = m_brightnessRect.getPosition()  + sf::Vector2f(m_brightnessRect.getSize().x, m_brightnessRect.getSize().y);

	m_brightnessQuad[0].color = sf::Color::White;
	m_brightnessQuad[1].color = sf::Color::White;
	m_brightnessQuad[2].color = sf::Color::Black;
	m_brightnessQuad[3].color = sf::Color::Black;

	m_brightnessSlider.setPosition(m_brightnessRect.getGlobalBounds().left + m_brightnessRect.getOutlineThickness(), 0.0f);
	m_brightnessSlider.setFillColor(sf::Color(static_cast<sf::Uint8>((1.0f-m_brightness)*255),
		static_cast<sf::Uint8>((1.0f-m_brightness)*255),static_cast<sf::Uint8>((1.0f-m_brightness)*255), 255));

	addMouseRolloverFunction(std::make_shared<TFunctor<SFMLColorPalette>>(this, &SFMLColorPalette::updateColorMagnify));
	addMouseLeftClickedFunction(std::make_shared<TFunctor<SFMLColorPalette>>(this, &SFMLColorPalette::onLeftClick));
}
Beispiel #30
0
//ctor
UISlider::UISlider(const sf::Font& font, const sf::Texture& t, float length, float maxValue)
	: m_maxValue		(maxValue),
	m_direction			(Direction::Horizontal),
	m_slotShape			(sf::Vector2f(length, thickness)),
	m_handleSprite		(t),
	m_length			(length),
	m_font				(font),
	m_text				("", font, 20u),
	m_localBounds		(0.f, -static_cast<float>(t.getSize().y / 2), length, static_cast<float>(t.getSize().y))
{
	sf::IntRect subrect(0, 0, t.getSize().x, t.getSize().y / 2u);
	m_subrects[State::Normal] = subrect;
	subrect.top += subrect.height;
	m_subrects[State::Selected] = subrect;
	m_handleSprite.setTextureRect(m_subrects[State::Normal]);


	Helpers::Position::CentreOrigin(m_handleSprite);
	m_slotShape.setOrigin(0.f, thickness / 2.f);
	m_slotShape.setFillColor(sf::Color::Black);
	m_slotShape.setOutlineColor(border);
	m_slotShape.setOutlineThickness(3.f);
}