Ejemplo n.º 1
0
void Level::loadFromLv(b2World& World, std::string levelPath)
{
  std::cout << levelPath << std::endl;
  std::string line;
  std::ifstream myfile (levelPath);
  if (myfile.is_open())
  {
    //current level object init
    while ( getline (myfile,line) )
    {
      std::regex groundRegex("(ground),(.*),(.*),(.*),(.*),(.*)");
      std::smatch groundObject;

      if (std::regex_match(line,groundObject,groundRegex))
      {
        std::cout <<  groundObject[5].str() << std::endl;

        CreateGround(World, std::stof(groundObject[2].str()), stof(groundObject[3].str()), stof(groundObject[4].str()), stof(groundObject[5].str()));
        // CreateGround(World, 5, 5, 5, stof(groundObject[5].str()));
        GroundTexture.loadFromFile(groundObject[6]);

        GroundTexture.setRepeated(true);

      }


    }
    std::cout << levelPath << std::endl;

    myfile.close();
  }
  else std::cout << "Unable to open file" << std::endl;
}
Ejemplo n.º 2
0
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();

}
void AnimatedSphere::create(sf::Texture& tex, float radius, const sf::Time& time)
{
	circle.setTexture(&tex);
	tex.setRepeated(true);

	if(radius < 0)
		throw std::logic_error{ "Circle's radius cannot be negative! Radius = " + std::to_string(radius) };

	float diam = 2 * radius;
	texRect = { 0, 0, (int)diam, (int)diam };

	circle.setRadius(radius);

	passed = sf::Time::Zero;
	animTime = time;

	texRect = { 0, 0, 2 * (int)radius, 2 * (int)radius };
	circle.setTextureRect(texRect);
}