Пример #1
0
	//Player constructor.
	Player(sf::Texture& texture, sf::Texture& hpImage, int x, int y, sf::Font& font) {

		mSprite.setTexture(texture);
		mRect = sf::FloatRect(x, y, 120, 110);					//Character x, y, width, height.
		
		mName = "Player 1";
		mTextName.setString(mName);
		mTextName.setFont(font);
		mTextName.setCharacterSize(30);
		mTextName.setStyle(sf::Text::Bold);
		mTextName.setColor(sf::Color::Red);
		
		mHpSprite.setTexture(hpImage);
		mHpSprite.setTextureRect(sf::IntRect(0, 0, 100, 10));

		mSprite.setTextureRect(sf::IntRect(0, 15, 120, 110));
	
		mSpeed = 0.1;
		mMovement.x = 0;
		mMovement.y = 0;

		mCurrentFrame = 0;
		mAnimationSpeed = 0.005;

		mIsAlive = true;
		mHP = 100;
		mMaxHp = 100;
		mMP = 100;
	}
Пример #2
0
/**
*\fn void moveLeft(void)
*\brief allows the Tamagotchi to move
*\param None
*\return Null
*/
void moveLeft(sf::Sprite &t, sf::Texture &t1, sf::Texture &t2)
{
	sf::Vector2f pos = t.getPosition();
	

	if(pos.x < 2)
	{
		D = 0;
	}

	if(pos.x > 600)
	{
		D = 1;
	}

	if(D == 0)
	{
		t.move(+1, 0);
		t.setTexture(t2, 1);
	}

	if(D == 1)
	{
		t.move(-1, 0);
		t.setTexture(t1, 1);
	}
}
Пример #3
0
void StateGameMenu::Initialize()
{
	menu_pointer_tex.loadFromFile("./Resources/Images/gamemenu_pointer.png");
	menu_pointer_sprt.setTexture(menu_pointer_tex);

	menu_tex.loadFromFile("./Resources/Images/gamemenu.png");
	menu_sprt.setTexture(menu_tex);
	menu_sprt.setPosition(180, 142);
}
Пример #4
0
			bool actualizarImagenExplocionPequenia(float currentTime){
			float temporal= currentTime - tiempoInicio;
			if(temporal <100){
			imagen.loadFromFile("graphics/SmallExp00.png");
			sprite.setTexture(imagen, true);
			return true;
			}
			if(temporal >100 && temporal < 200){
			imagen.loadFromFile("graphics/SmallExp00.png");
			sprite.setTexture(imagen, true);
			return true;
			}
			if(temporal >200 && temporal < 300){
			imagen.loadFromFile("graphics/SmallExp01.png");
			sprite.setTexture(imagen, true);
			return true;
			}	
			if(temporal >300 && temporal < 400){
			imagen.loadFromFile("graphics/SmallExp01.png");
			sprite.setTexture(imagen, true);
			}
			if(temporal >400 && temporal < 500){
			imagen.loadFromFile("graphics/SmallExp02.png");
			sprite.setTexture(imagen, true);
			}
			if(temporal >500 && temporal < 600){
			imagen.loadFromFile("graphics/SmallExp02.png");
			sprite.setTexture(imagen, true);
			return true;
			}
			if(temporal >600 && temporal < 700){
			imagen.loadFromFile("graphics/SmallExp03.png");
			sprite.setTexture(imagen, true);
			return true;
			}
			if(temporal >700 && temporal < 800){
			imagen.loadFromFile("graphics/SmallExp03.png");
			sprite.setTexture(imagen, true);
			return true;
			}
			if(temporal >800 && temporal < 1200){
			imagen.loadFromFile("graphics/SmallExp04.png");
			sprite.setTexture(imagen, true);
			return true;
			}
			if(temporal >1200 && temporal < 1700){
			imagen.loadFromFile("graphics/SmallExp04.png");
			sprite.setTexture(imagen, true);
			return true;
			}
			else
			{
				return false;
			}
			
		};
Пример #5
0
void TextureManager::setTexture(sf::Sprite& sprite, string name, unsigned int spriteIndex)
{
    TextureData& data = textureMap[name];
    if (data.texture.getSize().x < 1)
        loadTexture(name, sf::Vector2i(0, 0));
    
    if (spriteIndex < data.sprites.size())
    {
        sprite.setTexture(data.texture);
        sprite.setTextureRect(data.sprites[spriteIndex]);
        sprite.setOrigin(float(data.sprites[spriteIndex].width) / 2, float(data.sprites[spriteIndex].height) / 2);
    }else{
        sprite.setTexture(data.texture, true);
        sprite.setOrigin(data.texture.getSize().x / 2, data.texture.getSize().y / 2);
    }
}
Пример #6
0
void cursor::setTexture(string cursorPass)
{
    sprite.setTexture(textureManager.get(cursorPass));
    sprite.setOrigin((Collision::GetSpriteSize(sprite).x / sprite.getScale().x / 2), (Collision::GetSpriteSize(sprite).y / sprite.getScale().y / 2));
    sprite.rotate(-90);
    sprite.setColor(sf::Color(255, 255, 255, settings.getCursorAplha()));
}
Пример #7
0
void drawSprite(int x, int y, double w, double h, TextureIndex textureIndex)
{
	freeSprite.setPosition(x, y);
	freeSprite.setTexture(getTexture(textureIndex));
	freeSprite.setScale(w / getTexture(textureIndex).getSize().x, h / getTexture(textureIndex).getSize().y);
	window->draw(freeSprite);
}
Пример #8
0
void click(sf::RectangleShape rectangle,sf::Sprite &sprite, bool &clicked, bool &player, sf::Texture &crossTexture, sf::Texture &circleTexture, sf::Event &event) {
	if (((rectangle.getPosition().x <= event.mouseButton.x && event.mouseButton.x <= rectangle.getLocalBounds().width + rectangle.getPosition().x) &&
		(rectangle.getPosition().y <= event.mouseButton.y && event.mouseButton.y <= rectangle.getLocalBounds().height + rectangle.getPosition().y)) &&
		!(clicked)) {
		std::cout << "You clicked on a rectangle" << std::endl;
		clicked = true;
		if (player) {
			std::cout << "cross" << std::endl;
			sprite.setTexture(crossTexture);
		} else {
			std::cout << "circle" << std::endl;
			sprite.setTexture(circleTexture);
		}
		player = !player;
	}
}
Пример #9
0
void resolve() {
    shifter(cx);
    // Shift the palette for this iteration.
    for(int y = 0; y < imageHeight; ++y) {
    // In the imaginary axis...
        double c_im = MaxIm - (y * Im_factor);
        // The current imaginary is the max value minus the scaled vertical iterator.
        for(int x=0; x<imageWidth; ++x) {
        // In the real axis...
            double c_re = MinRe + (x * Re_factor);
            // The current real is the min value plus the scaled horizontal iterator.
            c.real = c_re;
            c.imag = c_im;
            // Change the real and imaginary components of the global complex variable c.
            int iters = fractal();
            // The returned value is the escape iterations for the current coordinate
            col = sf::Color(iters * 4, iters * 4, iters * 4, 255);
            // Create a color based on the current scape iterations.
            imagen.setPixel(x, y, col);
            // Set the image pixel at this current location to that color.
        }
    }
    mandtex.update(imagen);
    // Update the texture.
    mandelb.setTexture(mandtex);
    // Set the texture to the window.
}
Пример #10
0
	void _Log::load_image(){
		if( image_loaded == false && image_path.length() != 0 ) {
			texture_1.loadFromFile( image_path );

			Sprite.setTexture( texture_1, false );
			sf::IntRect spr_data = Sprite.getTextureRect();
			float x,y = WINDOW_HEIGHT - spr_data.height;

			switch( align ){

			case 1: x = 0.f; break;
			case 2: x = WINDOW_WIDTH * 0.25 - spr_data.width /2; break;
			case 3: x = WINDOW_WIDTH * 0.5  - spr_data.width /2; break;
			case 4: x = WINDOW_WIDTH * 0.75  - spr_data.width /2; break;
			case 5: x = WINDOW_WIDTH - spr_data.width; break;

			}

			Sprite.setPosition( x, y );

			cout << x << " " << y << endl;

			image_loaded = true;
		}
	}
Пример #11
0
	void init() {
		m_first_trip = false;
		m_current_state = IDLE;

		getBody()->GetFixtureList()->SetUserData("Checkpoint");
		getBody()->SetUserData(this);

		//Load Texture
		s_texture = "Assets/Game/cp_ps.png";
		m_text_size = sf::Vector2u(42, 94);
		m_sprite.setTexture(ResourceManager<sf::Texture>::instance()->get(s_texture));
		m_sprite.setOrigin(m_text_size.x / 2, m_text_size.y / 2);
		m_sprite.setPosition(vHelper::toSF(getBody()->GetPosition()));

		addFrames(frame_idle,	0, 0, 1, 42, 94, 1.0f);
		addFrames(frame_trip,	1, 0, 5, 42, 94, 1.0f);
		addFrames(frame_active, 2, 0, 3, 42, 94, 1.0f);

		m_animator.addAnimation(IDLE,	frame_idle,		sf::seconds(1.0f));
		m_animator.addAnimation(TRIP,	frame_trip,		sf::seconds(0.4f));
		m_animator.addAnimation(ACTIVE, frame_active,	sf::seconds(0.3f));

		//Load Audio
		s_noise = "Assets/Audio/Game/cp.wav";
		m_noise.setBuffer(ResourceManager<sf::SoundBuffer>::instance()->get(s_noise));
	}
Пример #12
0
	//Drop item constructor.
	DropItem(sf::Texture& texture, std::string type, int effect, int x, int y) {
		mSprite.setTexture(texture);
		mRect = sf::FloatRect(x, y, 32, 32);
		mSprite.setTextureRect(sf::IntRect(0, 0, 32, 32));
		mCurrentFrame = 0;
		mEffectValue = effect;
		mIsMarkedForRemoval = false;
	}
Пример #13
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);*/
}
Пример #14
0
        hud()
        {
            tex_paskaHp[ 0 ].loadFromFile( "gfx/pasek_hpTlo.png" );
            tex_paskaHp[ 1 ].loadFromFile( "gfx/pasek_hp.png" );
            tex_paskaBonusu[ 0 ].loadFromFile( "gfx/pasek_bonusTlo.png" );
            tex_paskaBonusu[ 1 ].loadFromFile( "gfx/pasek_bonus.png" );
            spr_paskaHp.setTexture( tex_paskaHp[ 0 ] );
            spr_paskaBonusu.setTexture( tex_paskaBonusu[ 0 ] );
            tex_tla.loadFromFile( "gfx/tlo0.png" );
            czcionka.loadFromFile( "font/Barme Reczny.ttf" );
            tekst.setFont( czcionka );
            tekst.setCharacterSize( 18 );
            timer[ 0 ] = 0;
            timer[ 1 ] = 0;
            typ_bonusu = 0;
            alphaPaskaBonusu = 0.0001;
//            spr_paskaBonusu.setColor( sf::Color( 255, 255, 255, alphaPaskaBonusu ) );
        }
Пример #15
0
	virtual void init()
	
	
	{
		dt=0;
		select_switch = 0.2;
		
		if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
    // error...
}
	//	darken = sf::RectangleShape(sf::Vector2f(800,400));
		
//sfx
if (!buffer.loadFromFile("sfx/Blip 007.wav"))

{
     //error
}
blip.setBuffer(buffer);


		if(!title.loadFromFile("gfx/title.png"))std::cout<<"Error"<<std::endl;

		t**s.setTexture(title);
		t**s.setOrigin(50,8);
		t**s.setScale(sf::Vector2f(3,3));
		t**s.setPosition(400,100);
		
		sf::FloatRect tempt ;
		
		for(int i =0 ; i<4;i++)
		{
			selector[i].setFont(standard_font);
			selector[i].setCharacterSize(28);
			 
		
		// dla centrowania obiektow
		
			tempt = selector[i].getGlobalBounds();
			selector[i].setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
			
			selector[i].setPosition(350,150+30*i);
		}
		
		selector[0].setString("Start game");
		selector[1].setString("Info");
		selector[2].setString("Highscores");
		selector[3].setString("Exit");
		
		
		selector[0].setColor(sf::Color(0,127,127));
		
		timer.restart();
		
		};
Пример #16
0
	void Set(sf::Texture &Img, int x, int y)
	{
		SSprite.setTexture(Img);
		FRect = sf::FloatRect(float(x), float(y), 16, 16);
		fCurrentFrame = 0.0f;
		bLife = true;

		dx = 0.05f; 
		//dy = 0.0f;
	}
Пример #17
0
	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);
	}
Пример #18
0
	//initialize muparser and graphics 
	void init() {
		p.DefineVar("theta", &t);
		p.DefineConst("pi", pi);
		graph.create(size,size,sf::Color::Transparent);
		graphTx.loadFromImage(graph);
		graphSpr.setTexture(graphTx);

		//center on screen
		graphSpr.setOrigin(size/2,size/2);
		graphSpr.setPosition(windowsize.x/2, windowsize.y/2);
	}
Пример #19
0
void Unit::load(std::string filename) {
	if(!_texture.loadFromFile(filename)) {
		_filename = "";
		_isLoaded = false;
	} 
	else {
		_filename = filename;
		_sprite.setTexture(_texture);
		_isLoaded = true;
	}
}
Пример #20
0
sf::Sprite GraphicEngine::loadSprite(sf::Texture &texture, sf::Sprite &sprite, std::string filename, sf::Vector2i position)
{
	string name = "data/images/" + filename + "";
	sf::Image img;
	img.loadFromFile(name);
	img.createMaskFromColor(sf::Color::White);
	texture.loadFromImage(img);
	sprite.setTexture(texture);
	sprite.setPosition(position.x, position.y);

	return sprite;
}
Пример #21
0
	virtual void init()
	
	
	{
		dt=0;
		
		
		if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
    // error...
}
		darken = sf::RectangleShape(sf::Vector2f(800,400));
		

		
		tit.setFont(standard_font); 


		tit.setString("Made by");

		explain.setFont(standard_font);
		explain.setString("Just a bored slacker");
		explain.setCharacterSize(36);
		explain.setPosition(260,320);

		tit.setCharacterSize(24);

		
		// dla centrowania obiektow
		
		sf::FloatRect tempt = tit.getGlobalBounds();

		
		tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));

		
		tit.setPosition(400,120);


if (!tex.loadFromFile("gfx/jabslogo.png"))
	
	{
		std::cout<<"Fuckup"<<std::endl;
		}

		spr.setTexture(tex);
		spr.setPosition(334,144);

		
		timer.restart();
		
		};
Пример #22
0
player::player(sf::Sprite sprite,sf::Vector2f pos,sf::Sprite bulletsprite)
{
	shape = sprite;
	shape.setPosition(pos);
	
	
	bulletTex.loadFromFile("bullet.png");
	bulletsprite.setTexture(bulletTex);
	lastpos = pos;
	bulletspr = bulletsprite;
	shape.setOrigin(sf::Vector2f(60, 41));
	notpressedbefore = false;
}
Пример #23
0
	Player(sf::Texture &Img)
	{
		SSprite.setTexture(Img);
		FRect = sf::FloatRect(0, 0, 16, 16);
		fCurrentFrame = 0.0f;

		// pos
		FRect.left = 100;
		FRect.top = 50;// 100;
		
		dx = 0.01f; // for init sprite
		dy = 0.0f;
	}
Arvid::Arvid(sf::Vector2f &position) /*:
	mIdleLeftAnimation	("", 0, 0),
	mIdleRightAnimation ("", 0, 0),
	mRunLeftAnimation	("", 0, 0),
	mRunRightAnimation	("", 0, 0),
	mJumpAnimation		("", 0, 0)*/
{ 
	mEntityKind = ARVID;
	setPosition(position);
	TEXTURE.loadFromFile("GUBBJEVEL.png");
	SPRITE.setTexture(TEXTURE);
	mHitBox.width = SPRITE.getLocalBounds().width;
	mHitBox.height = SPRITE.getLocalBounds().height;
	SPRITE.setPosition(position);
}
Пример #25
0
	Application() :
		m_window(sf::VideoMode(300, 300), "Flashlight!"),
		m_layer(),
		m_rect(sf::Vector2f(100.f, 100.f)),
		m_pos(0.f, 0.f)
	{
		m_window.setFramerateLimit(60);
		m_window.setMouseCursorVisible(false);

		m_layer.create(300, 300);
		m_flashlightTexture.create(60, 60);

		// We want to have semi-transparent edges.
		generateSpot();

		m_flashlight.setTexture(m_flashlightTexture.getTexture(), true);
		m_flashlight.setPosition(150.f, 150.f);
		m_flashlight.setOrigin(30.f, 30.f);

		m_rect.setFillColor(sf::Color::Red);
		m_rect.setPosition(100.f, 100.f);

		m_sprite.setTexture(m_layer.getTexture());
	}
Пример #26
0
	void setup()
	{
		window = new sf::RenderWindow(sf::VideoMode(800, 600), "Untitled");
		window->setFramerateLimit(60);

		clock = new sf::Clock();

		// textures are apparently stored in the graphic card's memory rather than RAM
		tile_texture = new sf::Texture();
		tile_texture->loadFromFile("assets/gfx/tiles/basic1.png");

		// sprites are used to position and draw textures
		tile_sprite = new sf::Sprite();
		tile_sprite->setTexture(*tile_texture);
		tile_sprite->setColor(sf::Color(255, 255, 255, 255));
	}
Пример #27
0
sf::Sprite Missile::ajouterMissileVaisseau(sf::Sprite sp, float posMissileX, float posMissileY)
{

    if (!missile.loadFromFile("ressource/missile.png", sf::IntRect(0, 0, 100,100)))
    {
        std::cout<<"Erreur durant le chargement de l'image missile"<<std::endl;
        return sp; // On ferme le programme
    }
    else
    {
        sp.setTexture(missile);
        sp.setScale(0.5f, 0.5f);    //setScale peut changer la taille
        sp.setColor(sf::Color(0, 255, 0));
        sp.setPosition(posMissileX, posMissileY);
        return sp;
    }
}
Пример #28
0
void StateCharacterSelect::Initialize()
{
	background_tex.loadFromFile("./Resources/Images/character_select_bg.png");
	background.setTexture(background_tex);

	background_activated_tex.loadFromFile("./Resources/Images/character_select_bg_selected.png");
	for(int i=0; i<4; i++)
		activated[i].setTexture(background_activated_tex);
	
	activated[0].setTextureRect(sf::IntRect(0, 0, 160, 480));
	activated[0].setPosition(0, 0);
	activated[1].setTextureRect(sf::IntRect(160, 0, 160, 480));
	activated[1].setPosition(160, 0);
	activated[2].setTextureRect(sf::IntRect(320, 0, 160, 480));
	activated[2].setPosition(320, 0);
	activated[3].setTextureRect(sf::IntRect(480, 0, 160, 480));
	activated[3].setPosition(480, 0);
}
Пример #29
0
	int log_setup_1(){
		//Load Font
		if( PTSANS_loaded == false ){
			if (!PTSANS.loadFromFile("PTN57F.ttf")) return -1;
			PTSANS_loaded = true;
		}

		texture_3.loadFromFile( "Temp_log.png" );

		//Setup Strings
		log_string.setFont( PTSANS );
		log_string.setCharacterSize(24);
		log_string.setColor( sf::Color(255, 255, 255) );
		log_string.setPosition(90.f, 600.f);

		log_name.setFont( PTSANS );
		log_name.setCharacterSize(40);
		log_name.setColor( sf::Color(255, 255, 255) );
		log_name.setPosition(90.f, 535.f);

		log_back.setTexture( texture_3, false );
		log_back.setPosition( 0.f, 580.f );

	}
Пример #30
0
	//Enemy constructor.
	Enemy(sf::Texture& texture, int x, int y, sf::Font& font) {
		mSprite.setTexture(texture);
		mRect = sf::FloatRect(x, y, 120, 110);					//Character x, y, width, height.

		mName = "Enemy";
		mTextName.setString(mName);
		mTextName.setFont(font);
		mTextName.setCharacterSize(30);
		mTextName.setStyle(sf::Text::Bold);
		mTextName.setColor(sf::Color::Magenta);

		mSprite.setTextureRect(sf::IntRect(0, 15, 120, 110));

		mDirection = rand() % 4;
		mSpeed = 0.05;

		mCurrentFrame = 0;
		mAnimationSpeed = mSpeed * 0.05;

		mIsAlive = true;
		mHP = 100;

		mDamage = 30;
	}