void Chest::DrawBoundingBox(sf::RenderTarget & window)
{
	boundingBox.setPosition(sf::Vector2f(getGlobalBounds().left, getGlobalBounds().top));
	boundingBox.setSize(sf::Vector2f(getGlobalBounds().width, getGlobalBounds().height));
	boundingBox.setRotation(getRotation());
	window.draw(boundingBox);
}
Exemple #2
0
//public
void Ticker::update(float dt)
{
    //move all messages
    for (auto i = m_messages.begin(); i != m_messages.end(); ++i)
    {
        if (i == m_messages.begin())
        {
            i->move(-m_speed * dt, 0.f);
        }
        else
        {
            auto j = std::prev(i);
            if (!j->getGlobalBounds().intersects(i->getGlobalBounds()))
            {
                i->move(-m_speed * dt, 0.f);
            }
        }

        auto lb = i->getLocalBounds();
        if (i->getPosition().x + lb.width < 0)
        {
            i->move(std::max(m_size.width, m_totalWidth) + lb.width, 0.f);
        }
    }

}
Exemple #3
0
void RenderSystem::update(float iDelay)
{
    // Clear screen
    _window->clear();

    for (std::shared_ptr<Entity> theEntity : _managedEntities)
    {
        YAB_ASSERT(theEntity);

		auto display = theEntity->accessComponent<RenderComponent>();
		auto position = theEntity->accessComponent<PositionComponent>(); // Position is centered on the object; but SFML one is on top left corner

        YAB_ASSERT(display);
        YAB_ASSERT(position);

        // ugly casts
        auto sprite = std::dynamic_pointer_cast<sf::Sprite>(display->_drawable);
        if (sprite)
			sprite->setPosition(sf::Vector2f(position->_xPos - (sprite->getGlobalBounds().width / 2), position->_yPos - (sprite->getGlobalBounds().height / 2)));

        auto text = std::dynamic_pointer_cast<sf::Text>(display->_drawable);
        if (text)
			text->setPosition(sf::Vector2f(position->_xPos - (text->getGlobalBounds().width / 2), position->_yPos - (text->getGlobalBounds().height / 2)));

        _window->draw(*display->_drawable);
    }

    // Update the window
	_sfgui.Display(*_window);
    _window->display();
}
Exemple #4
0
void Ship::shoot(float angle = 0, Chunk<Entity>* chunk=NULL)
{
	Projectile test_projectile(20, 10000);
	sf::Vector2f pos(getPosition().x + cosf(TO_RADIANS * angle) * getGlobalBounds().width * 1.5f,
					 getPosition().y + sinf(TO_RADIANS * angle) * getGlobalBounds().height * 1.5f);
	test_projectile.setOrigin(test_projectile.getCenter());
	test_projectile.setPosition(pos);
	test_projectile.apply(Force(Angle(angle), 1.0f));
	test_projectile.setTexture(Board<Entity>::texture_map.get("projectile"));
	chunk->add(std::make_shared<Projectile>(test_projectile));
	shooting = false;
}
//SETTER
void PersonnageJoueur::setDestination(sf::Vector2i destination)
{
    if(getPosition() == m_destination)
    {
        setTilePosition(getTilePosition()+destination);
        m_destination = sf::Vector2f( getMapOrigin().x + getTilePosition().x * getGlobalBounds().width,
                                      getMapOrigin().y + getTilePosition().y * getGlobalBounds().height );
        std::cout<<"PJ tp:"<<getTilePosition().x<<"/"<<getTilePosition().y<<
                      " p:"<<getPosition().x<<"/"<<getPosition().y<<
                      " d:"<<m_destination.x<<"/"<<m_destination.y<<std::endl;
    }
}
Exemple #6
0
void                         Player::move(int xAxis, int yAxis) {

	sf::Vector2f               movement(static_cast<float>(static_cast<int>(_speed * xAxis)), static_cast<float>(static_cast<int>(_speed * yAxis)));
	sf::Vector2f               nextPosition = getPosition() + movement;

	if (nextPosition.x < (WIN_W - getGlobalBounds().width - 50) &&
		nextPosition.x > 50 &&
		nextPosition.y > 10 &&
		nextPosition.y < (WIN_H - getGlobalBounds().height - 10))
			setPosition(nextPosition);
	_shield.setPosition(sf::Vector2f(getGlobalBounds().left + getGlobalBounds().width / 2.0f - _shield.getGlobalBounds().width / 2.0f, getGlobalBounds().top + getGlobalBounds().height / 2.0f - _shield.getGlobalBounds().height / 2.0f));
	if (requestGameEngine._mode == GameEngine::online)
		requestNetwork.sendPlayerPosition();
}
Exemple #7
0
void EnemyBoss::movement(float deltaTime, Background *bg){

        if(_dir == direction::none)     getNewDirection();
        if(_dir == direction::up)       _vel.y = -ENEMSPEED*deltaTime*_movementScaler;
        if(_dir == direction::left)     _vel.x = -ENEMSPEED*deltaTime*_movementScaler;
        if(_dir == direction::down)     _vel.y =  ENEMSPEED*deltaTime*_movementScaler;
        if(_dir == direction::right)    _vel.x =  ENEMSPEED*deltaTime*_movementScaler;

        _movementScaler += deltaTime;
        if(_movementScaler > 1.5) {
            if(_movementScaler < 1.6 && rand()%3 == 0) getNewDirection();
            _movementScaler = 1.6;
        }

        sf::Vector2f dest(_vel.x, _vel.y);

        //colide on y
        sf::FloatRect desrect = getGlobalBounds();
        desrect.top += _vel.y;
        if(bg->rectangleColision( desrect )){
            _vel.y = 0; _dir = direction::none;
        } else move(0, dest.y);
        desrect.top -= _vel.y;
        desrect.left += _vel.x;
        //colide on x
        if(bg->rectangleColision( desrect )){
            _vel.x = 0; _dir = direction::none;
        } else move(dest.x, 0);
}
Exemple #8
0
void ACharacter::drawLife(sf::RenderWindow& win, bool const& up) {

	sf::Sprite					s;
	sf::RectangleShape	r;
	float							lifeRatio;

	s.setTexture(*requestAssetManager.getTexture("lifebar.png"));
	s.setScale(sf::Vector2f(0.5f, 0.5f));
	s.setPosition(sf::Vector2f(getGlobalBounds().left + getGlobalBounds().width / 2 - s.getGlobalBounds().width / 2,
		getGlobalBounds().top + (up == true ? -s.getGlobalBounds().height : getGlobalBounds().height)));
	lifeRatio = static_cast<float>(_health.x) / static_cast<float>(_health.y);
	r.setSize(sf::Vector2f((s.getGlobalBounds().width / 20 * 19) * lifeRatio, s.getGlobalBounds().height / 10 * 9));
	r.setFillColor(lifeRatio < 0.3 ? sf::Color(160, 0, 0) : (lifeRatio < 0.6 ? sf::Color(200, 150, 0) : sf::Color(0, 255, 0)));
	r.setPosition(s.getPosition());
	win.draw(r);
	win.draw(s);
}
void ofxBKDoubleSlider::mousePressed(ofMouseEventArgs &e)
{
	currentDraggingValue = getNearestValueIndex(getValueForPosition(getMousePosition().x));
	mouseDragOffset = getValueForPosition(getMousePosition().x) - (currentDraggingValue == 1?value:value2);
	ofHideCursor();

	#ifdef _WIN32

	LPPOINT pt = LPPOINT();
	int x = ofGetWindowPositionX()+getGlobalBounds().x + (currentDraggingValue == 1?value:value2)*width;
	int y = ofGetWindowPositionY()+getGlobalBounds().y+getMousePosition().y;
	SetCursorPos(x,y);
	mouseDragOffset = 0;
	#endif

	isDragging = true;
}
void Starship::Update(sf::Time &time) {
	sf::FloatRect Bounds = getGlobalBounds();
	Top = Bounds.top;
	Bottom = Bounds.top - Bounds.height;
	Left = Bounds.left;
	Right = Bounds.left + Bounds.width;

	KeyboarEvent(time);
}
Exemple #11
0
void ACharacter::die()
{
	if (_deathFX.getAnimationName().size() > 0)
	{
		sf::FloatRect		r = getGlobalBounds();
		sf::Vector2i	d = requestGameEngine.getAnimation(_deathFX.getAnimationName()).getFrameDimensions();
		sf::Vector2f	p(r.left + r.width / 2 - d.x / 2, r.top + r.height / 2 - d.y / 2);
		_deathFX.trigger(p);
	}

}
Exemple #12
0
void TextButton::update(sf::RenderWindow &window)
{
    m_text_shadow=m_text;
    sf::Vector2i pos=sf::Mouse::getPosition(window);
    if(getGlobalBounds().contains(pos.x, pos.y)) {
        m_text_shadow.move(2,2);
        m_text_shadow.setColor(sf::Color(50,50,50,150));
    } else {
        m_text_shadow.setColor(sf::Color::Transparent);
    }
}
Exemple #13
0
void                      ACharacter::shoot(unsigned int shotOriginVertexIndex) {

	GameEngine&             engine = GameEngine::instanciate();
	Ammunition*             shot = new Ammunition(_weapon);

	shot->setPosition(getPosition() + _shotVertexes[shotOriginVertexIndex % _shotVertexes.size()]);
	shot->setTargetPosition(Vf(WIN_W * 2, getPosition().y + getGlobalBounds().height / 2));
	engine.addAmmo(shot);
	SoundSystem::instanciate().pushEffect("speedBonus.wav");
//	SoundSystem::instanciate().pushEffect("pulseShot.wav");
}
Exemple #14
0
Gadget* Bouton::testerSurvol (sf::Vector2i posSouris)
//std::shared_ptr<Gadget> Bouton::testerSurvol (sf::Vector2i posSouris)
{

    // si non visible on renvois nullptr
    if (! estVisible () ) return nullptr;

    // Si on survol le gadget on renvois son pointeur, sinon on renvois pointeur vide
    if ( getGlobalBounds().contains( posSouris.x, posSouris.y ) ) return this;
    else  return nullptr;

}
void Character::loadEntityFromNode(Node& root)
{
    DrawableEntity::loadEntityFromNode(root);

    Hitbox* hitbox(NULL);
    try
    {
        Node& areaNode = root.firstChild("hitbox");
        sf::FloatRect area = static_cast<sf::FloatRect>(loadAreaFromNode(areaNode));
        hitbox = new BoundingBoxHitbox(getPosition(), area);
        Log::write(Log::LOG_INFO, "Entity's hitbox creation : " + toString(area));
    }
    catch(std::runtime_error& e)
    {
        Log::write(Log::LOG_WARNING, "No hitbox defined for Entity : " + toString(e.what()));
        // when there isn't hitbox, we assign the entity's global bounds as a hitbox
        hitbox = new BoundingBoxHitbox(getPosition(), getGlobalBounds());
        Log::write(Log::LOG_INFO, "Entity's hitbox creation : " + toString(getGlobalBounds()));
    }
    setHitbox(hitbox);
}
Exemple #16
0
void Player::update(const sf::Time& dt) {
	handleInput(dt);

	if (getPosition().x < 0) {
		move(m_speed * dt.asSeconds(), 0.0f);
	} else if (getPosition().x + getGlobalBounds().width > m_windowSize.x) {
		move(-m_speed * dt.asSeconds(), 0.0f);
	}

	m_spaceKey = sf::Keyboard::isKeyPressed(sf::Keyboard::Space);

	Entity::update(dt);
}
Exemple #17
0
void							Player::indicateCurrentPlayer(sf::RenderWindow& win)
{
	sf::VertexArray		a(sf::Triangles, 4);
	sf::FloatRect			r = getGlobalBounds();
	a[0] = sf::Vector2f(r.left + r.width / 2 - 5, r.top - 5);
	a[1] = sf::Vector2f(r.left + r.width / 2 + 5, r.top - 5);
	a[2] = sf::Vector2f(r.left + r.width / 2, r.top);
	a[3] = sf::Vector2f(r.left + r.width / 2 - 5, r.top - 5);
	a[0].color = sf::Color(255, 170, 0);
	a[1].color = sf::Color(255, 170, 0);
	a[2].color = sf::Color(255, 170, 0);
	win.draw(a);
}
Exemple #18
0
void EnemyLog::movement(float deltaTime, Background *bg){

    _vel.y += +2*deltaTime;

    sf::Vector2f dest(0, _vel.y);

    sf::FloatRect desrect = getGlobalBounds();
    desrect.top += _vel.y;
    if(bg->rectangleColision( desrect )){
        _vel.y = 0;
    } else move(0, dest.y);


}
Exemple #19
0
void Ship::approach()
{
	target_angle = getAngleBetween(getPosition(), target);
	turnTo(Angle(target_angle));

	if (getDistanceBetween(getPosition(), target) < getGlobalBounds().width * 2.0f)
	{
		stop();
		setRotation(target_angle);
	}
	else
	{
		correctSpeed();
	}
}
Exemple #20
0
void Snake::checkEnemyBulletCollisions()
{
	for (auto& spaceship : static_cast<GameScreen*>(game_->getScreens().top().get())->getSpaceships())
	{
		for (auto& bullet : static_cast<Spaceship*>(spaceship.get())->getBullets())
		{
			for (auto it = nodes_.begin(); it != nodes_.end(); ++it)
			{
				if (it->getGlobalBounds().intersects(bullet.getGlobalBounds()))
				{
					hitByBullet(it);
				}
			}
		}
	}
}
Exemple #21
0
Player::Player(EntityManager& entityManager, sf::Vector2f windowSize)
	: m_windowSize{ windowSize } 
	, m_entityManager{ entityManager }
	, m_bulletCount{ 0 } {
	active = 1;
	type = "Player";
	load("player.png");
	setPosition(m_windowSize.x / 2.0f - getGlobalBounds().width / 2.0f, m_windowSize.y - getGlobalBounds().height - 10.0f);

	m_shootSoundBuffer.loadFromFile("audio/shoot.wav");
	m_shootSound.setBuffer(m_shootSoundBuffer);
	m_shootSound.setVolume(20.0f);

	m_explosionSoundBuffer.loadFromFile("audio/explosion.wav");
	m_explosionSound.setBuffer(m_explosionSoundBuffer);
	m_explosionSound.setVolume(20.0f);
}
Exemple #22
0
void                         Player::shoot(unsigned int shotOriginVertexIndex) {

	if (canShot() == true)
	{
		_weapons[_weaponIndex].setType(Ammunition::friendlyShot);
		GameEngine&             engine = GameEngine::instanciate();
		Ammunition*             shot = new Ammunition(_weapons[_weaponIndex]);
		shot->setPosition(getPosition() + _shotVertexes[shotOriginVertexIndex % _shotVertexes.size()]);
		shot->setTargetPosition(Vf(WIN_W * 2, getPosition().y + getGlobalBounds().height / 2));
		engine.addAmmo(shot);
		SoundSystem::instanciate().pushEffect("speedBonus.wav");
		//		SoundSystem::instanciate().playEffect("speedBonus.wav");
		isReloading();
		if (_weapons[_weaponIndex].getCurrentAnimation().getAnimationName() == "plasmaBullet")
			engine.addFX("loadingShot", "r-typesheet1.gif", sf::Vector2f(getPosition().x + _shotVertexes[shotOriginVertexIndex].x, getPosition().y + _shotVertexes[shotOriginVertexIndex].y - engine.getAnimation("loadingShot").getFrameDimensions().y / 2), sf::Color::Black);
		else 
		engine.addFX("fireshot", "fire.png", sf::Vector2f(getPosition().x + _shotVertexes[shotOriginVertexIndex].x, getPosition().y + _shotVertexes[shotOriginVertexIndex].y - engine.getAnimation("fireshot").getFrameDimensions().y / 2), sf::Color::White);
	}
}
bool PlayerBullet::collidesWith(Shield shield) {
    auto bulletBounds = getGlobalBounds();
    auto shieldBounds = shield.getGlobalBounds();
    
    if (PhysicsHelper::getInstance().overlaps(bulletBounds, shieldBounds)) {
        for (int x = bulletBounds.left; x < bulletBounds.left + bulletBounds.width; x++) {
            for (int y = bulletBounds.top; y < bulletBounds.top + bulletBounds.height; y++) {
                int relX = x - shieldBounds.left;
                int relY = y - shieldBounds.top;
                
                if (relY >= 0 && relY < shieldBounds.height && shield.getPixel(relX, relY)) {
                    return true;
                }
            }
        }
    }
    
    return false;
}
Exemple #24
0
void GuiColorPickerCtrl::setSelectorPos(const ColorF & color)
{
   if (mBitmap && !mPositionChanged)
   {
      Point2I resolution = getRoot() ? getRoot()->getExtent() : Point2I(1024, 768);
      RectI rect(getGlobalBounds());
      Point2I pos = findColor(color, rect.point, resolution, *mBitmap);
      mSetColor = mSetColor.BLACK;
      mSelectColor = false;

      setSelectorPos(pos);
   }
   else
   {
      mSetColor = color;
      mSelectColor = true;
      mPositionChanged = true;
   }
}
Exemple #25
0
void Player::handleInput(const sf::Time& dt) {
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
		move(-m_speed * dt.asSeconds(), 0.0f);
	}
	
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
		move(m_speed * dt.asSeconds(), 0.0f);
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && !m_spaceKey) {
		sf::Vector2f position = getPosition();
		position.x += getGlobalBounds().width / 2.0f - 4.0f;

		std::unique_ptr<Projectile> projectile(new Projectile(m_windowSize, position, true));
		m_entityManager.add("PlayerProjectile" + std::to_string(m_bulletCount), std::move(projectile));
		m_bulletCount++;

		m_shootSound.play();
	}
}
Exemple #26
0
void Renderer::drawBar(const cpShape* shape) {
  const auto p1 = cpSegmentShapeGetA(shape);
  const auto p2 = cpSegmentShapeGetB(shape);
  const auto radius = static_cast<float>(cpSegmentShapeGetRadius(shape));
  auto rect = RoundedBar(radius);
  rect.setOutlineColor(sf::Color::Green);
  rect.setOutlineThickness(1.0f);
  rect.setFillColor(sf::Color::Transparent);
  const auto sfp1 = Utils::toSfv(p1, mTargetSize);
  const auto sfp2 = Utils::toSfv(p2, mTargetSize);
  const auto len = static_cast<float>(cpvdist(p1, p2));

  if (p1.x == p2.x) {
    rect.setLength(len);
    auto y = std::min(sfp1.y, sfp2.y);
    rect.setRotation(90);
    rect.setPosition(sfp1.x, y + len / 2 - radius);
    rect.adjustOrigin();
  } else if (p1.y == p2.y) {
    rect.setLength(len);
    auto x = std::min(sfp1.x, sfp2.x);
    rect.setPosition(x + len / 2 - radius, sfp1.y);
    rect.adjustOrigin();
  }
  {
    for (auto& target : mTargets) {
      auto view = target->getView();
      auto center = view.getCenter();
      auto pieceW = view.getSize().x * 1.0f;
      auto pieceH = view.getSize().y * 1.0f;
      auto x = center.x - pieceW / 2.0f;
      auto y = center.y - pieceH / 2.0f;
      auto vRect = sf::FloatRect(x, y, pieceW, pieceH);
      if (vRect.intersects(rect.getGlobalBounds())) {
        target->draw(rect);
      }
    }
  }
}
Exemple #27
0
void Ship::correctSpeed()
{

	float stopping_distance = sqrt(pow(getStoppingDistance(velocity.x, frame.getAccel()), 2.0f) + pow(getStoppingDistance(velocity.x, frame.getAccel()), 2.0f));
	auto moving_toward = movingToward(target);


	if (stopping_distance < getDistanceBetween(getPosition(), target) - getGlobalBounds().width / 2.0f &&
		moving_toward.first && moving_toward.second)
	{
		accelerate();
	}
	else if (!moving_toward.first)
	{
		if (target.x > getPosition().x)
		{
			velocity.x += frame.getAccel() / 2.0f;
		}
		else
		{
			velocity.x -= frame.getAccel() / 2.0f;
		}
	}
	else if (!moving_toward.second)
	{
		if (target.y > getPosition().y)
		{
			velocity.y += frame.getAccel() / 2.0f;
		}
		else
		{
			velocity.y -= frame.getAccel() / 2.0f;
		}
	}
	else
	{
		decelerate();
	}
}
Exemple #28
0
Obstacle::Obstacle()
{
	//Sets the default Movement variables
	iMaxMoveSpeed = 5;
	iMinMoveSpeed = 3;
	iMoveSpeed = 4;

	//Sets up the collision box for the obstacle.
	sf::FloatRect BoundingBox = getGlobalBounds();

	//Sets up the default direction
	iDirection = 3;

	//Applying the values to the rectangular space
	setPosition(200 , 50);
	setSize(sf::Vector2f(25 , 25));
	setFillColor(sf::Color::Red);

	if (!iMinMoveSpeed > 0)
	{
		iMinMoveSpeed = 1;
	}
};
Exemple #29
0
bool ball::checkCollision(paddle Paddle){
	auto tempItor = Paddle.getPVector()->begin();
	for (auto itor = Paddle.getPVector()->begin(); itor != Paddle.getPVector()->end(); itor++){
		if (this->getSprite()->getGlobalBounds().intersects(itor->getGlobalBounds())){
			//if (itor == Paddle.getPVector()->begin() && next(itor) == Paddle.getPVector()->end()){
			//Paddle.getPVector()->clear();
			//}
			if (itor == Paddle.getPVector()->begin()){
				itor = Paddle.getPVector()->erase(itor);
				if (this->yVelocity > 0){
					this->yVelocity = fmin(-550.f, -(yVelocity * 2.0f));
					this->xVelocity /= 1.1f;
					//this->xVelocity *= (2.0f);
					//this->xVelocity = fmax(550.f, (xVelocity * 2.0f));
					
				}
				return true;
			}
			if (itor != Paddle.getPVector()->end() && next(itor) == Paddle.getPVector()->end()){
				itor = Paddle.getPVector()->erase(itor);
				if (this->yVelocity < 0){
					this->yVelocity *= (-1.f);
					//this->xVelocity *= (2.0f);
					this->xVelocity = fmax(550.f, (xVelocity * 2.0f));
				}
				return true;
			}
			this->yVelocity = 300.f;
			//this->yVelocity = fmin(550.f, (yVelocity * 2.0f));
			this->xVelocity = 300.f;
			itor = Paddle.getPVector()->erase(itor);
			return true;
		}
	}
	return false;
}
bool BoutonImage::clicked(const sf::Vector2f positionSouris) const
{
    return sf::FloatRect(positionSouris.x,positionSouris.y,1,1).intersects(getGlobalBounds());
}