Exemplo n.º 1
0
Duck::Duck() : ACharacter()
{
  this->_texture = new sf::Texture();
  this->_texture->loadFromFile("ressources//Petit2.png");
  this->_texture->setSmooth(true);
  //sf::Vector2i screenDimensions(200, HEIGHT - 100);
  sf::Vector2i screenDimensions(300, HEIGHT - 125);

  this->_animate = new AnimatedSprite(sf::seconds(0.1), true, false);
  (*this->_animations)[RIGHT].setSpriteSheet(*this->_texture);
  this->setFrames(RIGHT, 44.99999, 49, 0, 4, 0);
  this->_x = 0;
  this->_y = 0;
  this->_speed = 800;
  this->_jumpHeight = 500;
  this->_strengh = false;
  this->_current = &((*this->_animations)[RIGHT]);
  this->_animate->setPosition(sf::Vector2f(screenDimensions));
  this->_animate->play(*this->_current);
  this->_animate->setOrigin(48, 39);
}
DestructibleObstacle::DestructibleObstacle(int sizeX, int sizeY, std::string const &texture) : AObstacle()
{
  sf::Vector2i screenDimensions(200, HEIGHT - 110);
  this->_type = JUMP;
  this->_isDestructible = true;
  if (!this->_texture.loadFromFile(texture))
      std::cout << texture <<": texture loading error" << std::endl;
  this->_shape = new sf::RectangleShape(sf::Vector2f(sizeX, sizeY));
  this->_shape->setPosition(sf::Vector2f(-1, -1));
  _sizeX = sizeX;
  _sizeY = sizeY;
  this->_animate = new AnimatedSprite(sf::seconds(0.06), true, false);
  (*this->_animations)[ACharacter::RIGHT].setSpriteSheet(this->_texture);
  this->setFrames(ACharacter::RIGHT,100, 600, 0, 8, 0);
  (*this->_animations)[ACharacter::IDLE].setSpriteSheet(this->_texture);
  this->setFrames(ACharacter::IDLE, 100, 600, 0, 1, 0);

  this->_current = &((*this->_animations)[ACharacter::IDLE]);
  this->_animate->setPosition(sf::Vector2f(screenDimensions));
  this->_animate->play(*this->_current);
  this->_animate->setOrigin(48, 39);
}
Exemplo n.º 3
0
int main(){

    sf::RenderWindow window(sf::VideoMode(800, 600), "Particles");
    sf::RectangleShape rectangle, rectangle2, nexus;

    ParticleSystem particles(1000);
    sf::Clock clock;

    sf::Vector2i screenDimensions(800, 600);
    sf::Vector2i blockDimensions(10, 10);

    sf::View view1(sf::FloatRect(0, 0, 800, 600));
    sf::View view2(sf::FloatRect(800, 0, 800, 600));

    sf::View standard = window.getView();
    unsigned int size = 100;
    sf::View minimap(sf::FloatRect(0, 0, 800, 600));
    //sf::View minimap(sf::FloatRect(view1.getCenter().x, view1.getCenter().y, size, window.getSize().y*size/window.getSize().x));
    //minimap.setViewport(sf::FloatRect(1.f-(1.f*minimap.getSize().x)/window.getSize().x-0.02f, 1.f-(1.f*minimap.getSize().y)/window.getSize().y-0.02f, (1.f*minimap.getSize().x)/window.getSize().x, (1.f*minimap.getSize().y)/window.getSize().y));
    minimap.setViewport(sf::FloatRect(0.75f, 0, 0.25f, 0.25f));
    minimap.zoom(2.f);
    //view1.setViewport(sf::FloatRect(0, 0, 0.5f, 1));

    // joueur 2 (côté droit de l'écran)
    //view2.setViewport(sf::FloatRect(0.5f, 0, 0.5f, 1));


    rectangle.setOutlineThickness(3);
    rectangle.setOutlineColor(sf::Color(0, 0, 0, 255));
    rectangle.setSize({50.f, 50.f});
    rectangle.setPosition({400.f, 300.f});
    rectangle.setFillColor(sf::Color::Red);

    rectangle2.setOutlineThickness(3);
    rectangle2.setOutlineColor(sf::Color(0, 0, 0, 255));
    rectangle2.setSize({500.f, 500.f});
    rectangle2.setPosition({800.f, 0.f});
    rectangle2.setFillColor(sf::Color::Blue);

    int x = rand()%(800-800*2)+800;
    int y = rand()%(600-0)+0;
    nexus.setSize({100.f, 100.f});
     std::cout << x << " , " << y << std::endl;
    nexus.setPosition({400.f, 300.f});

    sf::Vector2f mouse;
    //view1.setCenter(rectangle.getPosition());

    while (window.isOpen()){
        sf::Event event;
        while (window.pollEvent(event)){
            if(event.type == sf::Event::Closed){
                window.close();
            }

            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
                rectangle.move(-7, 0);
                mouse = {rectangle.getPosition().x+(rectangle.getSize().x/2), rectangle.getPosition().y+(rectangle.getSize().y/2)};

                view1.setCenter(rectangle.getPosition());
                std::cout << rectangle.getPosition().x << " , " << rectangle.getPosition().y << std::endl;
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
                mouse = {rectangle.getPosition().x+(rectangle.getSize().x/2), rectangle.getPosition().y+(rectangle.getSize().y/2)};
                rectangle.move(+7,0);
                view1.setCenter(rectangle.getPosition());
                std::cout << rectangle.getPosition().x << " , " << rectangle.getPosition().y << std::endl;
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
                mouse = {rectangle.getPosition().x+(rectangle.getSize().x/2), rectangle.getPosition().y+(rectangle.getSize().y/2)};
                rectangle.move(0,-7);
                view1.setCenter(rectangle.getPosition());
                std::cout << rectangle.getPosition().x << " , " << rectangle.getPosition().y << std::endl;
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
                mouse = {rectangle.getPosition().x+(rectangle.getSize().x/2), rectangle.getPosition().y+(rectangle.getSize().y/2)};
                rectangle.move(0,+7);
                view1.setCenter(rectangle.getPosition());
                std::cout << rectangle.getPosition().x << " , " << rectangle.getPosition().y << std::endl;
            }
        }

        particles.setEmitter(mouse);
        //particles.setEmitter(window.mapPixelToCoords((sf::Vector2i)mouse));

        sf::Time elapsed = clock.restart();
        particles.update(elapsed);


        window.clear();
        window.setView(view1);

        for(int i = 0;i<nexus.getSize().x/blockDimensions.x; i++){
            for(int j = 0;j<nexus.getSize().y/blockDimensions.y;j++){
                sf::VertexArray vArray(sf::PrimitiveType::Quads, 4);
                vArray[0].position = sf::Vector2f(i*blockDimensions.x+nexus.getPosition().x, j*blockDimensions.y+nexus.getPosition().y);
                vArray[1].position = sf::Vector2f(i*blockDimensions.x+blockDimensions.x+nexus.getPosition().x, j*blockDimensions.y+nexus.getPosition().y);
                vArray[2].position = sf::Vector2f(i*blockDimensions.x+blockDimensions.x+nexus.getPosition().x, j*blockDimensions.y+blockDimensions.y+nexus.getPosition().y);
                vArray[3].position = sf::Vector2f(i*blockDimensions.x+nexus.getPosition().x, j*blockDimensions.y+blockDimensions.y+nexus.getPosition().y);

                for(int k=0;k<4;k++){
                    int red = rand() % 255;
                    int green = rand() % 255;
                    int blue = rand() % 255;

                    vArray[k].color = sf::Color(red, green, blue);
                }
                window.draw(vArray);
            }
        }


        //window.clear();

        window.setView(standard);
        window.draw(particles);
        window.draw(rectangle);

        //window.draw(rectangle2);
        //window.setView(view2);
        //window.draw(rectangle2);

        window.setView(minimap);
        window.draw(particles);
        window.draw(rectangle);

        window.display();
    }

    return 0;
}
Exemplo n.º 4
0
int main(int argc, char** argv) {
	sf::Vector2i screenDimensions(600, 442);

	sf::RenderWindow window(sf::VideoMode(screenDimensions.x, screenDimensions.y), "SFML tutorial");

	sf::Texture texture;
	sf::Sprite image;

	if (!texture.loadFromFile("Resources/texture.jpg")) {
		std::cout << "cannot load texture" << std::endl;
	}

	image.setTexture(texture);
	image.setScale(1.0f, (float)screenDimensions.y / texture.getSize().y);

	sf::RectangleShape rect(sf::Vector2f(20, 20));
	rect.setFillColor(sf::Color::Green);

	sf::Clock clock;
	float moveSpeed = 10000.0f;

	sf::View view;
	view.reset(sf::FloatRect(0, 0, screenDimensions.x, screenDimensions.y));
	view.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f)); // display full view

	sf::Vector2f position(screenDimensions.x / 2, screenDimensions.y / 2);

	while (window.isOpen()) {
		clock.restart();

		sf::Event event;
		while (window.pollEvent(event)) {
			switch (event.type) {
			case sf::Event::Closed:
				window.close();
				break;

			default:
				break;
			}
		}

		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
			rect.move(moveSpeed * clock.restart().asSeconds(), 0);
		} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
			rect.move(-moveSpeed * clock.restart().asSeconds(), 0);
		}

		/*
		position.x = rect.getPosition().x + 10 - (screenDimensions.x / 2);
		position.y = rect.getPosition().y + 10 - (screenDimensions.y / 2);

		if (position.x < 0)
			position.x = 0;
		if (position.y < 0)
			position.y = 0;
		*/

		if (rect.getPosition().x + 10 > screenDimensions.x / 2)
			position.x = rect.getPosition().x + 10;
		else
			position.x = screenDimensions.x / 2;

		//view.reset(sf::FloatRect(position.x, position.y, screenDimensions.x, screenDimensions.y));
		view.setCenter(position);

		window.setView(view);
		window.draw(image);
		window.draw(rect);
		window.display();
		window.clear(sf::Color(66, 66, 66));
	}

	return EXIT_SUCCESS;
}
Exemplo n.º 5
0
int main()
{
    
    sf::Vector2i screenDimensions(800, 600);
    //sf::Vector2i blockDimensions(10, 10);
    
    sf::RenderWindow window(sf::VideoMode(screenDimensions.x,screenDimensions.y),"RogueGame");
    
    Music epicSong;
    epicSong.playMusic();
    
    Elf *p1 = new Elf("Gino",60, 70);
    
    GrassGround *gg = new GrassGround("terrain");
    gg->loadG();
    
    
    
    
        
    sf::View view;
    view.reset(sf::FloatRect(0, 0, screenDimensions.x, screenDimensions.y));
    view.setViewport(sf::FloatRect(0, 0 , 1, 1));
    
    sf::Vector2f position(0, 0);
    
    sf::Image icon;
    if (!icon.loadFromFile("iconB.png")) {
        return EXIT_FAILURE;
    }
    window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());

    
    //window.setKeyRepeatEnabled(false);

    
    while(window.isOpen()){
        window.clear();
        
        sf::Event Event;
        
        while(window.pollEvent(Event)){//loop degli eventi
            
            switch(Event.type){
                    
                case sf::Event::Closed:
                    window.close();
                    break;
            }
        }
        
        p1->walk();
        
        position.x=p1->getPos("x")+32 - (screenDimensions.x/2); //metto in position la posizione dell omino - mezzo display
        position.y=p1->getPos("y")+32 - (screenDimensions.y/2);
        if (position.x < 0)
            position.x=0;
        else if(position.x > 200)
                position.x=200;
        if (position.y < 0)
            position.y=0;
        else if(position.y > 150)
                position.y=150;
        view.reset(sf::FloatRect(position.x, position.y, screenDimensions.x, screenDimensions.y)); //cosicche se si passa il centro si muove la camera, e dopo un po si smette di muovere.
        
        
        window.setView(view);
        
        window.draw(gg->getGSprite());
        window.draw(p1->getSprite());
        window.display();
        window.clear();
        
    }//gameloop
}//main
Exemplo n.º 6
0
int main()
{
    // setup window
    sf::Vector2i screenDimensions(576,272);
    sf::RenderWindow window(sf::VideoMode(screenDimensions.x, screenDimensions.y), "Rainsford");
    window.setFramerateLimit(60);
    
    sf::Vector2f scaler(screenDimensions.x/72, screenDimensions.y/34);
    
    /*background setup
    There are 3 copies of each background layer (z-score), one is drawn in left and one is drawn right of
     the default background that is automatically drawn. After the any of the 3 copies moves its entire width left
     (position.x is negative width) it is assigned position.x = positive width. This "shuffles" the copies
     and gives an illusion of continuity.
     
     */
    sf::RectangleShape titlescreen (sf::Vector2f(screenDimensions.x, screenDimensions.y));
    sf::Texture title;
    if (!title.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Rainsford Titlescreen.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    titlescreen.setTexture(&title); // texture is a sf::Texture
    titlescreen.setTextureRect(sf::IntRect(0, 0, 576,272));

    
    
    sf::RectangleShape titleback (sf::Vector2f(screenDimensions.x, screenDimensions.y));
    sf::Texture titlebackTex;
    if (!titlebackTex.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Titleback.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    titleback.setTexture(&titlebackTex); // texture is a sf::Texture
    titleback.setTextureRect(sf::IntRect(0, 0, 576,272));
    
    
    
    sf::RectangleShape moon (sf::Vector2f(screenDimensions.x, screenDimensions.y));
    sf::Texture moonT;
    if (!moonT.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Moon.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    moon.setTexture(&moonT); // texture is a sf::Texture
    moon.setTextureRect(sf::IntRect(0, 0, 576,272));

    
    

    //back1
    sf::RectangleShape back1(sf::Vector2f(72,34));
    sf::Texture textureBack1;
    if (!textureBack1.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background1.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    back1.setTexture(&textureBack1); // texture is a sf::Texture
    back1.setTextureRect(sf::IntRect(0, 0, 72,34));
    
    //back2
    sf::RectangleShape back2(sf::Vector2f(128,32));
    sf::Texture textureBack2;
    if (!textureBack2.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background2.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    back2.setTexture(&textureBack2); // texture is a sf::Texture
    back2.setTextureRect(sf::IntRect(0, 0, 128,32));

    sf::RectangleShape back2a(sf::Vector2f(128,32));
    back2a.setTexture(&textureBack2); // texture is a sf::Texture
    back2a.setTextureRect(sf::IntRect(0, 0, 128,32));
    back2a.setPosition(-128*8, 0);
    
    sf::RectangleShape back2b(sf::Vector2f(128,32));
    back2b.setTexture(&textureBack2); // texture is a sf::Texture
    back2b.setTextureRect(sf::IntRect(0, 0, 128,32));
    back2b.setPosition(128*8, 0);
    
    //back3
    sf::RectangleShape back3(sf::Vector2f(128,32));
    sf::Texture textureBack3;
    if (!textureBack3.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background3.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    back3.setTexture(&textureBack3); // texture is a sf::Texture
    back3.setTextureRect(sf::IntRect(0, 0, 128,32));

    sf::RectangleShape back3a(sf::Vector2f(128,32));
    back3a.setTexture(&textureBack3); // texture is a sf::Texture
    back3a.setTextureRect(sf::IntRect(0, 0, 128,32));
    back3a.setPosition(-128*8, 0);
    
    sf::RectangleShape back3b(sf::Vector2f(128,32));
    back3b.setTexture(&textureBack3); // texture is a sf::Texture
    back3b.setTextureRect(sf::IntRect(0, 0, 128,32));
    back3b.setPosition(128*8, 0);
    
    //back4
    sf::RectangleShape back4(sf::Vector2f(112,32));
    sf::Texture textureBack4;
    if (!textureBack4.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background4.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    back4.setTexture(&textureBack4); // texture is a sf::Texture
    back4.setTextureRect(sf::IntRect(0, 0, 112,32));

    sf::RectangleShape back4a(sf::Vector2f(112,32));
    back4a.setTexture(&textureBack4); // texture is a sf::Texture
    back4a.setTextureRect(sf::IntRect(0, 0, 112,32));
    back4a.setPosition(-112*8, 0);
    
    sf::RectangleShape back4b(sf::Vector2f(112,32));
    back4b.setTexture(&textureBack4); // texture is a sf::Texture
    back4b.setTextureRect(sf::IntRect(0, 0, 112,32));
    back4b.setPosition(112*8, 0);
    
    //back5
    sf::RectangleShape back5(sf::Vector2f(96,32));
    sf::Texture textureBack5;
    if (!textureBack5.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background5.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    back5.setTexture(&textureBack5); // texture is a sf::Texture
    back5.setTextureRect(sf::IntRect(0, 0, 96,32));
    
    sf::RectangleShape back5a(sf::Vector2f(96,32));
    back5a.setTexture(&textureBack5); // texture is a sf::Texture
    back5a.setTextureRect(sf::IntRect(0, 0, 96,32));
    back5a.setPosition(-96*8, 0);
    
    sf::RectangleShape back5b(sf::Vector2f(96,32));
    back5b.setTexture(&textureBack5); // texture is a sf::Texture
    back5b.setTextureRect(sf::IntRect(0, 0, 96,32));
    back5b.setPosition(96*8, 0);
    
    //back6
    sf::RectangleShape back6(sf::Vector2f(72,32));
    sf::Texture textureBack6;
    if (!textureBack6.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background6.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    back6.setTexture(&textureBack6); // texture is a sf::Texture
    back6.setTextureRect(sf::IntRect(0, 0, 72,32));

    sf::RectangleShape back6a(sf::Vector2f(72,32));
    back6a.setTexture(&textureBack6); // texture is a sf::Texture
    back6a.setTextureRect(sf::IntRect(0, 0, 72,32));
    back6a.setPosition(-72*8, 0);
    
    sf::RectangleShape back6b(sf::Vector2f(72,32));
    back6b.setTexture(&textureBack6); // texture is a sf::Texture
    back6b.setTextureRect(sf::IntRect(0, 0, 72,32));
    back6b.setPosition(72*8, 0);
    
    //moonlight
    sf::RectangleShape moonlight(sf::Vector2f(96,32));
    sf::Texture textureMoon;
    if (!textureMoon.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Moonlight.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    moonlight.setTexture(&textureMoon); // texture is a sf::Texture
    moonlight.setTextureRect(sf::IntRect(0, 0, 96,32));
    
    sf::RectangleShape moonlighta(sf::Vector2f(96,32));
    moonlighta.setTexture(&textureBack6); // texture is a sf::Texture
    moonlighta.setTextureRect(sf::IntRect(0, 0, 96,32));
    moonlighta.setPosition(-96*8, 0);
    
    sf::RectangleShape moonlightb(sf::Vector2f(96,32));
    moonlightb.setTexture(&textureMoon); // texture is a sf::Texture
    moonlightb.setTextureRect(sf::IntRect(0, 0, 96,32));
    moonlightb.setPosition(96*8, 0);

    
    //vines
    sf::RectangleShape vines(sf::Vector2f(96,32));
    sf::Texture textureVines;
    if (!textureVines.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Vines.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    vines.setTexture(&textureVines); // texture is a sf::Texture
    vines.setTextureRect(sf::IntRect(0, 0, 96,32));
    
    sf::RectangleShape vinesa(sf::Vector2f(96,32));
    vinesa.setTexture(&textureVines); // texture is a sf::Texture
    vinesa.setTextureRect(sf::IntRect(0, 0, 96,32));
    vinesa.setPosition(-96*8, 0);
    
    sf::RectangleShape vinesb(sf::Vector2f(96,32));
    vinesb.setTexture(&textureVines); // texture is a sf::Texture
    vinesb.setTextureRect(sf::IntRect(0, 0, 96,32));
    vinesb.setPosition(96*8, 0);

    
    //end of backgrounds ***********************************************************
    
    back1.scale(scaler);
    back2.scale(scaler);
    back3.scale(scaler);
    back4.scale(scaler);
    back5.scale(scaler);
    back6.scale(scaler);
    vines.scale(scaler);
    back2a.scale(scaler);
    back3a.scale(scaler);
    back4a.scale(scaler);
    back5a.scale(scaler);
    back6a.scale(scaler);
    vinesa.scale(scaler);
    back2b.scale(scaler);
    back3b.scale(scaler);
    back4b.scale(scaler);
    back5b.scale(scaler);
    back6b.scale(scaler);
    vinesb.scale(scaler);
    moonlight.scale(scaler);
    moonlighta.scale(scaler);
    moonlightb.scale(scaler);
    
    //flickering stormlamp spritesheet
    sf::Texture stormLamp;
    
    if (!stormLamp.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/RainsfordStormLamp_Spritesheet.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    
    Animation flicker;
    flicker.setSpriteSheet(stormLamp);
    flicker.addFrame(sf::IntRect (0, 0, 160, 90));
    flicker.addFrame(sf::IntRect (0, 90, 160, 90));
    flicker.addFrame(sf::IntRect (0, 180, 160, 90));
    flicker.addFrame(sf::IntRect (0, 90, 160, 90));


    AnimatedSprite flickerSprite(sf::seconds(.3), true, false);
    flickerSprite.scale(scaler);
    flickerSprite.setPosition(((-160/scaler.x)*18), -120*scaler.y/4);
    
    //IVAN STUFF
    // load texture (spritesheet)
    sf::Texture textureIvan;
    if (!textureIvan.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Spritesheet_Ivan.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    
    // set up the animations for all four directions (set spritesheet and push frames)
    
    Animation ivan_standingRight;
    ivan_standingRight.setSpriteSheet(textureIvan);
    ivan_standingRight.addFrame(sf::IntRect(0, 0, 8, 8));
    ivan_standingRight.addFrame(sf::IntRect(8, 0, 8, 8));
    ivan_standingRight.addFrame(sf::IntRect(16, 0, 8, 8));
    ivan_standingRight.addFrame(sf::IntRect( 24, 0, 8, 8));
    ivan_standingRight.addFrame(sf::IntRect(32, 0, 8, 8));
    ivan_standingRight.addFrame(sf::IntRect( 40, 0, 8, 8));
    
    Animation ivan_standingLeft;
    ivan_standingLeft.setSpriteSheet(textureIvan);
    ivan_standingLeft.addFrame(sf::IntRect(0, 8, 8, 8));
    ivan_standingLeft.addFrame(sf::IntRect(8, 8, 8, 8));
    ivan_standingLeft.addFrame(sf::IntRect(16, 8, 8, 8));
    ivan_standingLeft.addFrame(sf::IntRect( 24, 8, 8, 8));
    ivan_standingLeft.addFrame(sf::IntRect(32, 8, 8, 8));
    ivan_standingLeft.addFrame(sf::IntRect(40, 8, 8, 8));
    
    Animation ivan_walkingRight;
    ivan_walkingRight.setSpriteSheet(textureIvan);
    ivan_walkingRight.addFrame(sf::IntRect(0, 16, 8, 8));
    ivan_walkingRight.addFrame(sf::IntRect(8, 16, 8, 8));
    ivan_walkingRight.addFrame(sf::IntRect(16, 16, 8, 8));
    ivan_walkingRight.addFrame(sf::IntRect( 24, 16, 8, 8));
    ivan_walkingRight.addFrame(sf::IntRect(32, 16, 8, 8));
    ivan_walkingRight.addFrame(sf::IntRect( 40, 16, 8, 8));
    
    Animation ivan_walkingLeft;
    ivan_walkingLeft.setSpriteSheet(textureIvan);
    ivan_walkingLeft.addFrame(sf::IntRect(0, 24, 8, 8));
    ivan_walkingLeft.addFrame(sf::IntRect(8, 24, 8, 8));
    ivan_walkingLeft.addFrame(sf::IntRect(16, 24, 8, 8));
    ivan_walkingLeft.addFrame(sf::IntRect( 24, 24, 8, 8));
    ivan_walkingLeft.addFrame(sf::IntRect(32, 24, 8, 8));
    ivan_walkingLeft.addFrame(sf::IntRect( 40, 24, 8, 8));

    Animation* currentIvanAnimation = &ivan_standingRight;
    
    AnimatedSprite ivan(sf::seconds(.07), true, false);
    ivan.setPosition(sf::Vector2f(screenDimensions.x / 2 - 264, 192));
    ivan.scale(scaler);
    
    
    // DOG load texture (spritesheet)
    sf::Texture textureDog;
    if (!textureDog.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Spritesheet_Dog.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    

    //dog spritesheet animation setup
    Animation dog_standingRight;
    dog_standingRight.setSpriteSheet(textureDog);
    dog_standingRight.addFrame(sf::IntRect(0, 0, 8, 8));
    dog_standingRight.addFrame(sf::IntRect(8, 0, 8, 8));
    dog_standingRight.addFrame(sf::IntRect(16, 0, 8, 8));
    dog_standingRight.addFrame(sf::IntRect( 24, 0, 8, 8));
    
    Animation dog_standingLeft;
    dog_standingLeft.setSpriteSheet(textureDog);
    dog_standingLeft.addFrame(sf::IntRect(0, 8, 8, 8));
    dog_standingLeft.addFrame(sf::IntRect(8, 8, 8, 8));
    dog_standingLeft.addFrame(sf::IntRect(16, 8, 8, 8));
    dog_standingLeft.addFrame(sf::IntRect( 24, 8, 8, 8));

    Animation dog_walkingRight;
    dog_walkingRight.setSpriteSheet(textureDog);
    dog_walkingRight.addFrame(sf::IntRect(0, 16, 8, 8));
    dog_walkingRight.addFrame(sf::IntRect(8, 16, 8, 8));
    dog_walkingRight.addFrame(sf::IntRect(16, 16, 8, 8));
    dog_walkingRight.addFrame(sf::IntRect( 24, 16, 8, 8));
    
    Animation dog_walkingLeft;
    dog_walkingLeft.setSpriteSheet(textureDog);
    dog_walkingLeft.addFrame(sf::IntRect(0, 24, 8, 8));
    dog_walkingLeft.addFrame(sf::IntRect(8, 24, 8, 8));
    dog_walkingLeft.addFrame(sf::IntRect(16, 24, 8, 8));
    dog_walkingLeft.addFrame(sf::IntRect( 24, 24, 8, 8));

    Animation dog_walkingRightHostile;
    dog_walkingRightHostile.setSpriteSheet(textureDog);
    dog_walkingRightHostile.addFrame(sf::IntRect(0, 32, 8, 8));
    dog_walkingRightHostile.addFrame(sf::IntRect(8, 32, 8, 8));
    dog_walkingRightHostile.addFrame(sf::IntRect(16, 32, 8, 8));
    dog_walkingRightHostile.addFrame(sf::IntRect( 24, 32, 8, 8));
    
    Animation dog_walkingLeftHostile;
    dog_walkingLeftHostile.setSpriteSheet(textureDog);
    dog_walkingLeftHostile.addFrame(sf::IntRect(0, 40, 8, 8));
    dog_walkingLeftHostile.addFrame(sf::IntRect(8, 40, 8, 8));
    dog_walkingLeftHostile.addFrame(sf::IntRect(16, 40, 8, 8));
    dog_walkingLeftHostile.addFrame(sf::IntRect( 24, 40, 8, 8));

    Animation* currentDogAnimation = &dog_standingRight;
    
    AnimatedSprite dog(sf::seconds(.07), true, false);
    dog.setPosition(sf::Vector2f(screenDimensions.x / 2 - 200, 192));
    dog.scale(scaler);
    
    
    // load texture (spritesheet)
    sf::Texture texture;
    if (!texture.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Spritesheet_Rainsford.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    
    // set up the animations for all directions (set spritesheet and push frames)
    
    Animation standingRight;
    standingRight.setSpriteSheet(texture);
    standingRight.addFrame(sf::IntRect(0, 0, 8, 8));
    standingRight.addFrame(sf::IntRect(8, 0, 8, 8));
    standingRight.addFrame(sf::IntRect(16, 0, 8, 8));
    standingRight.addFrame(sf::IntRect( 24, 0, 8, 8));
   // standingRight.addFrame(sf::IntRect(32, 0, 8, 8));
   // standingRight.addFrame(sf::IntRect( 40, 0, 8, 8));
    
    Animation standingLeft;
    standingLeft.setSpriteSheet(texture);
    standingLeft.addFrame(sf::IntRect(0, 8, 8, 8));
    standingLeft.addFrame(sf::IntRect(8, 8, 8, 8));
    standingLeft.addFrame(sf::IntRect(16, 8, 8, 8));
    standingLeft.addFrame(sf::IntRect( 24, 8, 8, 8));
   // standingLeft.addFrame(sf::IntRect(32, 8, 8, 8));
   // standingLeft.addFrame(sf::IntRect(40, 8, 8, 8));

    Animation walkingRight;
    walkingRight.setSpriteSheet(texture);
    walkingRight.addFrame(sf::IntRect(0, 16, 8, 8));
    walkingRight.addFrame(sf::IntRect(8, 16, 8, 8));
    walkingRight.addFrame(sf::IntRect(16, 16, 8, 8));
    walkingRight.addFrame(sf::IntRect( 24, 16, 8, 8));
    //walkingRight.addFrame(sf::IntRect(32, 16, 8, 8));
    //walkingRight.addFrame(sf::IntRect( 40, 16, 8, 8));
    
    Animation walkingLeft;
    walkingLeft.setSpriteSheet(texture);
    walkingLeft.addFrame(sf::IntRect(0, 24, 8, 8));
    walkingLeft.addFrame(sf::IntRect(8, 24, 8, 8));
    walkingLeft.addFrame(sf::IntRect(16, 24, 8, 8));
    walkingLeft.addFrame(sf::IntRect( 24, 24, 8, 8));
    //walkingLeft.addFrame(sf::IntRect(32, 24, 8, 8));
    //walkingLeft.addFrame(sf::IntRect( 40, 24, 8, 8));
  
    Animation jumpingRight;
    jumpingRight.setSpriteSheet(texture);
    jumpingRight.addFrame(sf::IntRect(0, 32, 8, 8));
    jumpingRight.addFrame(sf::IntRect(8, 32, 8, 8));
    jumpingRight.addFrame(sf::IntRect(16, 32, 8, 8));
    jumpingRight.addFrame(sf::IntRect( 24, 32, 8, 8));
    //jumpingRight.addFrame(sf::IntRect(32, 32, 8, 8));
    //jumpingRight.addFrame(sf::IntRect( 40, 32, 8, 8));

    
    Animation jumpingLeft;
    jumpingLeft.setSpriteSheet(texture);
    jumpingLeft.addFrame(sf::IntRect(0, 40, 8, 8));
    jumpingLeft.addFrame(sf::IntRect(8, 40, 8, 8));
    jumpingLeft.addFrame(sf::IntRect(16, 40, 8, 8));
    jumpingLeft.addFrame(sf::IntRect( 24, 40, 8, 8));
    //jumpingLeft.addFrame(sf::IntRect(32, 40, 8, 8));
    //jumpingLeft.addFrame(sf::IntRect( 40, 40, 8, 8));

    
    Animation crawlingRight;
    crawlingRight.setSpriteSheet(texture);
    crawlingRight.addFrame(sf::IntRect(0, 64, 8, 8));
    crawlingRight.addFrame(sf::IntRect(8, 64, 8, 8));
    crawlingRight.addFrame(sf::IntRect(16, 64, 8, 8));
    crawlingRight.addFrame(sf::IntRect( 24, 64, 8, 8));
    //jumpingRight.addFrame(sf::IntRect(32, 32, 8, 8));
    //jumpingRight.addFrame(sf::IntRect( 40, 32, 8, 8));
    
    
    Animation crawlingLeft;
    crawlingLeft.setSpriteSheet(texture);
    crawlingLeft.addFrame(sf::IntRect(0, 72, 8, 8));
    crawlingLeft.addFrame(sf::IntRect(8, 72, 8, 8));
    crawlingLeft.addFrame(sf::IntRect(16, 72, 8, 8));
    crawlingLeft.addFrame(sf::IntRect( 24, 72, 8, 8));
    //jumpingLeft.addFrame(sf::IntRect(32, 40, 8, 8));
    //jumpingLeft.addFrame(sf::IntRect( 40, 40, 8, 8));

    
    Animation disguise1;
    disguise1.setSpriteSheet(texture);
    disguise1.addFrame(sf::IntRect(0, 48, 8, 8));
    Animation disguise2;
    disguise2.setSpriteSheet(texture);
    disguise2.addFrame(sf::IntRect(8, 48, 8, 8));
    Animation disguise3;
    disguise3.setSpriteSheet(texture);
    disguise3.addFrame(sf::IntRect(16, 48, 8, 8));
    Animation disguise4;
    disguise4.setSpriteSheet(texture);
    disguise4.addFrame(sf::IntRect(24, 48, 8, 8));
    
    Animation crouchedRight;
    crouchedRight.setSpriteSheet(texture);
    crouchedRight.addFrame(sf::IntRect(0, 56, 8, 8));
    
    Animation crouchedLeft;
    crouchedLeft.setSpriteSheet(texture);
    crouchedLeft.addFrame(sf::IntRect(8, 56, 8, 8));


    Animation* currentAnimation = &standingRight;
    
    
    
    float rainsfordAnimationSpeed = .07;
    
    
    // set up AnimatedSprite
    AnimatedSprite animatedSprite(sf::seconds(rainsfordAnimationSpeed), true, false);
    animatedSprite.setPosition(sf::Vector2f(screenDimensions.x / 2 - 64, 192));
    animatedSprite.scale(scaler);
    sf::Clock frameClock;
    
    float speed = 650.f;
    bool noKeyWasPressed = true;
    
    
    enum direction { left, right};
    direction currentDir = right;
    
    
       while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
                window.close();
        }
        
        sf::Time frameTime = frameClock.restart();
        
        
        // if a key was pressed set the correct animation and move correctly
        sf::Vector2f movement(0.f, 0.f);
        
        
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
        {
            if(currentDir == left)
            {
                currentAnimation = &jumpingLeft;
                noKeyWasPressed = false;
            }
            if(currentDir == right)
            {
                currentAnimation = &jumpingRight;
                noKeyWasPressed = false;
            }
 
        }
        
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
    {
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
            {
                currentAnimation = &crawlingLeft;
                currentDogAnimation = &dog_walkingLeft; //DOG ANIMATION
                currentIvanAnimation = &ivan_walkingLeft; //Ivan ANIMATION

                movement.x += .2*speed;
                noKeyWasPressed = false;
                currentDir = left;
            }
            else
            {
                currentAnimation = &walkingLeft;
                currentDogAnimation = &dog_walkingLeftHostile; //DOG ANIMATION
                currentIvanAnimation = &ivan_walkingLeft; //Ivan ANIMATION

                movement.x += speed;
                noKeyWasPressed = false;
                currentDir = left;

            }
        }
        
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
           

            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
            {
                currentAnimation = &crawlingRight;
                currentDogAnimation = &dog_walkingRight; //DOG ANIMATION
                currentIvanAnimation = &ivan_walkingRight; //Ivan ANIMATION

                movement.x -= .2*speed;
                noKeyWasPressed = false;
                currentDir = right;
            }
            else
            {
                currentAnimation = &walkingRight;
                currentDogAnimation = &dog_walkingRightHostile; //DOG ANIMATION
                currentIvanAnimation = &ivan_walkingRight; //Ivan ANIMATION

                movement.x -= speed;
                noKeyWasPressed = false;
                currentDir = right;
            }
        }
        
    }
        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
        {
            if(currentDir == left)
            {
                currentAnimation = &crouchedLeft;
                noKeyWasPressed = false;
            }
            if(currentDir == right)
            {
                currentAnimation = &crouchedRight;
                noKeyWasPressed = false;
            }
            
        }
        

        
        
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::E))
        {
            currentAnimation = &disguise1;
            noKeyWasPressed = false;
            movement.x = 0;
        }
        
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::R))
        {
            currentAnimation = &disguise2;
            noKeyWasPressed = false;
            movement.x = 0;
        }
        
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::T))
        {
            currentAnimation = &disguise3;
            noKeyWasPressed = false;
            movement.x = 0;
        }
        
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Y))
        {
            currentAnimation = &disguise4;
            noKeyWasPressed = false;
            movement.x = 0;
        }
        
        

        
        // if no key was pressed
        if (noKeyWasPressed)
        {
            sf::Time slowerFrameTime = sf::seconds(.3);
            
            animatedSprite.setFrameTime(slowerFrameTime);
            dog.setFrameTime(slowerFrameTime); //DOG WUZ HERE
            ivan.setFrameTime(slowerFrameTime); //IVAn

            if (currentDir == left)
            {
                currentAnimation = &standingLeft;
                currentDogAnimation = &dog_standingLeft;// DAWG HERE TOO DOG
                currentIvanAnimation = &ivan_standingLeft;// IVAN

            }
            if (currentDir == right)
            {
                currentAnimation = &standingRight;
                currentDogAnimation = &dog_standingRight; // DAWG HERE TOO 2 DOG
                currentIvanAnimation = &ivan_standingRight;// IVAN

            }
        }
        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
        {
            animatedSprite.setFrameTime(sf::seconds(.15));
            dog.setFrameTime(sf::seconds(.15));//DOOOOOOOGGGGEEE DOG
            ivan.setFrameTime(sf::seconds(.15));//IVAN

        }
        else
        {
            animatedSprite.setFrameTime(sf::seconds(.07));
            dog.setFrameTime(sf::seconds(.07));//DOOOOOOOGGGGEEEDOOOOOOOGGGGEEEDOOOOOOOGGGGEEE DOG
            ivan.setFrameTime(sf::seconds(.07));//IVAN
        }
        
        
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
    {
               //EDGE EFFECT HERE
        if (back2.getPosition().x <= back2.getSize().x*-8)
        {
            back2.setPosition(back2.getSize().x*8, 0);
        }
        if (back2a.getPosition().x <= back2a.getSize().x*-8)
        {
            back2a.setPosition(back2a.getSize().x*8, 0);
        }
 
        if (back2b.getPosition().x <= back2b.getSize().x*-8)
        {
            back2b.setPosition(back2b.getSize().x*8, 0);
        }
        
        if (back3.getPosition().x <= back3.getSize().x*-8)
        {
            back3.setPosition(back3.getSize().x*8, 0);
        }
        if (back3a.getPosition().x <= back3a.getSize().x*-8)
        {
            back3a.setPosition(back3a.getSize().x*8, 0);
        }
        
        if (back3b.getPosition().x <= back3b.getSize().x*-8)
        {
            back3b.setPosition(back3b.getSize().x*8, 0);
        }

        
        if (back4.getPosition().x <= back4.getSize().x*-8)
        {
            back4.setPosition(back4.getSize().x*8, 0);
        }
        if (back4a.getPosition().x <= back4a.getSize().x*-8)
        {
            back4a.setPosition(back4a.getSize().x*8, 0);
        }
        
        if (back4b.getPosition().x <= back4b.getSize().x*-8)
        {
            back4b.setPosition(back4b.getSize().x*8, 0);
        }

        
        if (back5.getPosition().x <= back5.getSize().x*-8)
        {
            back5.setPosition(back5.getSize().x*8, 0);
        }
        if (back5a.getPosition().x <= back5a.getSize().x*-8)
        {
            back5a.setPosition(back5a.getSize().x*8, 0);
        }
        
        if (back5b.getPosition().x <= back5b.getSize().x*-8)
        {
            back5b.setPosition(back5b.getSize().x*8, 0);
        }

        
        if (back6.getPosition().x <= back6.getSize().x*-8)
        {
            back6.setPosition(back6.getSize().x*8, 0);
        }
        if (back6a.getPosition().x <= back6a.getSize().x*-8)
        {
            back6a.setPosition(back6a.getSize().x*8, 0);
        }
        
        if (back6b.getPosition().x <= back6b.getSize().x*-8)
        {
            back6b.setPosition(back6b.getSize().x*8, 0);
        }
        
        
            //vines
        if (vines.getPosition().x <= vines.getSize().x*-8)
        {
            vines.setPosition(vines.getSize().x*8, 0);
        }
        if (vinesa.getPosition().x <= vinesa.getSize().x*-8)
        {
            vinesa.setPosition(vinesa.getSize().x*8, 0);
        }
        
        if (vinesb.getPosition().x <= vinesb.getSize().x*-8)
        {
            vinesb.setPosition(vinesb.getSize().x*8, 0);
        }

            //moonlight
        if (moonlight.getPosition().x <= moonlight.getSize().x*-8)
        {
            moonlight.setPosition(moonlight.getSize().x*8, 0);
        }
        if (moonlighta.getPosition().x <= moonlighta.getSize().x*-8)
        {
            moonlighta.setPosition(moonlighta.getSize().x*8, 0);
        }
        
        if (moonlightb.getPosition().x <= moonlightb.getSize().x*-8)
        {
            moonlightb.setPosition(moonlightb.getSize().x*8, 0);
        }

        
    }
        
        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
    {
        
        //positive
        /*
        if (back2.getPosition().x >= back2.getSize().x*8)
        {
            back2.setPosition(back2.getSize().x*-8, 0);
        }
        if (back2a.getPosition().x >= back2a.getSize().x*8)
        {
            back2a.setPosition(back2a.getSize().x*-8, 0);
        }
        
        if (back2b.getPosition().x >= back2b.getSize().x*8)
        {
            back2b.setPosition(back2b.getSize().x*-8, 0);
        }
        
        if (back3.getPosition().x >= back3.getSize().x*8)
        {
            back3.setPosition(back3.getSize().x*-8, 0);
        }
        if (back3a.getPosition().x >= back3a.getSize().x*8)
        {
            back3a.setPosition(back3a.getSize().x*-8, 0);
        }
        
        if (back3b.getPosition().x >= back3b.getSize().x*8)
        {
            back3b.setPosition(back3b.getSize().x*-8, 0);
        }
        */
        
        if (back4.getPosition().x >= back4.getSize().x*8)
        {
            back4.setPosition(back4.getSize().x*-8, 0);
        }
        if (back4a.getPosition().x >= back4a.getSize().x*8)
        {
            back4a.setPosition(back4a.getSize().x*-8, 0);
        }
        
        if (back4b.getPosition().x >= back4b.getSize().x*8)
        {
            back4b.setPosition(back4b.getSize().x*-8, 0);
        }
        
        
        if (back5.getPosition().x >= back5.getSize().x*8)
        {
            back5.setPosition(back5.getSize().x*-8, 0);
        }
        if (back5a.getPosition().x >= back5a.getSize().x*8)
        {
            back5a.setPosition(back5a.getSize().x*-8, 0);
        }
        
        if (back5b.getPosition().x >= back5b.getSize().x*8)
        {
            back5b.setPosition(back5b.getSize().x*-8, 0);
        }
        
        
        if (back6.getPosition().x >= back6.getSize().x*8)
        {
            back6.setPosition(back6.getSize().x*-8, 0);
        }
        if (back6a.getPosition().x >= back6a.getSize().x*8)
        {
            back6a.setPosition(back6a.getSize().x*-8, 0);
        }
        
        if (back6b.getPosition().x >= back6b.getSize().x*8)
        {
            back6b.setPosition(back6b.getSize().x*-8, 0);
        }
            //vines
         if (vines.getPosition().x >= vines.getSize().x*8)
         {
         vines.setPosition(vines.getSize().x*-8, 0);
         }
         if (vinesa.getPosition().x >= vinesa.getSize().x*8)
         {
         vinesa.setPosition(vinesa.getSize().x*-8, 0);
         }
         
         if (vinesb.getPosition().x >= vinesb.getSize().x*8)
         {
         vinesb.setPosition(vinesb.getSize().x*-8, 0);
         }
        
        //moonlight
        if (moonlight.getPosition().x >= moonlight.getSize().x*8)
        {
            moonlight.setPosition(moonlight.getSize().x*-8, 0);
        }
        if (moonlighta.getPosition().x >= moonlighta.getSize().x*8)
        {
            moonlighta.setPosition(moonlighta.getSize().x*-8, 0);
        }
        
        if (moonlightb.getPosition().x >= moonlightb.getSize().x*8)
        {
            moonlightb.setPosition(moonlightb.getSize().x*-8, 0);
        }

        
    }
        
        
        float timeMov = 1;
        timeMov = frameTime.asSeconds();
        
        ivan.play(*currentIvanAnimation);
        dog.play(*currentDogAnimation);//dog animation here
        animatedSprite.play(*currentAnimation);
        flickerSprite.play(flicker);
        animatedSprite.move(0,0);
        back2.move(-16 * timeMov, 0);
        back3.move(-32 * timeMov, 0);
        back4.move(.3*movement.x * timeMov, 0);
        moonlight.move(.45*movement.x * timeMov, 0);
        back5.move(.55*movement.x * timeMov, 0);
        vines.move(.65*movement.x * timeMov, 0);
        back6.move(.8*movement.x * timeMov, 0);
        back2a.move(-16 * timeMov, 0);
        back3a.move(-32 * timeMov, 0);
        back4a.move(.3*movement.x * timeMov, 0);
        moonlighta.move(.45*movement.x * timeMov, 0);
        back5a.move(.55*movement.x * timeMov, 0);
        vinesa.move(.65*movement.x * timeMov, 0);
        back6a.move(.8*movement.x * timeMov, 0);
        back2b.move(-16 * timeMov, 0);
        back3b.move(-32 * timeMov, 0);
        back4b.move(.3*movement.x * timeMov, 0);
        moonlightb.move(.45*movement.x * timeMov, 0);
        back5b.move(.55*movement.x * timeMov, 0);
        vinesb.move(.65*movement.x * timeMov, 0);
        back6b.move(.8*movement.x * timeMov, 0);
        noKeyWasPressed = true;

        
        // update AnimatedSprite
        dog.update(frameTime);//dog
        ivan.update(frameTime);//ivan
        animatedSprite.update(frameTime);
        flickerSprite.update(sf::seconds(.03f));
        
        
        // draw
        window.clear();
        window.draw(titleback);
        window.draw(moon);
        //window.draw(back1);
        window.draw(back2);
        window.draw(back2a);
        window.draw(back2b);
        window.draw(back3);
        window.draw(back3a);
        window.draw(back3b);
        /*window.draw(back4);
        window.draw(back4a);
        window.draw(back4b);
        window.draw(back5);
        window.draw(back5a);
        window.draw(back5b);
        window.draw(back6);
        window.draw(back6a);
        window.draw(back6b);
        window.draw(animatedSprite);
        window.draw(dog);//dog
        window.draw(ivan);//ivan
         */
        
        window.draw(titlescreen);
        
        
        int flickerCounter = 0;
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::F))
        {
            if(flickerCounter==0) flickerCounter++;
            else flickerCounter--;
        }
        if(flickerCounter!=0)
        window.draw(flickerSprite);
        
        window.display();
    }
    
    return 0;
}
Exemplo n.º 7
0
int main() {
    sf::Vector2i screenDimensions(800, 600);
    sf::RenderWindow w(sf::VideoMode(screenDimensions.x, screenDimensions.y), L"Whee");
    w.setKeyRepeatEnabled(false);

    enum Direction { Down, Left, Right, Up };
    sf::Vector2i source(1, Down);
    float frameCounter = 1, switchFrame = 30, frameSpeed = 200;
    sf::Clock c;
    bool updateFrame = true;
    bool animateSprite = true;

    sf::Texture pT;
    sf::Sprite pS;
    pT.loadFromFile("../data/sprites/player1.png");
    pS.setTexture(pT);

    // let's draw text
    // for this to work we need a font file
    sf::Font fnt;
    fnt.loadFromFile("../data/fonts/ForMateKonaVe.ttf");// we can wrap this in an if/then to test that it loads
    sf::String words = " ";
    sf::Text sT(words, fnt, 40);

    // we can style our text as well
    sT.setColor(sf::Color(44, 27, 180, 197));
    sT.setStyle(sf::Text::Bold | sf::Text::Italic);

    // in my several tests, I've found the text handling to be INCREDIBLY buggy
    // if the string is not set (eg. null) OR is empty (eg. "") we get an malloc error
    // for whatever reason when the application ends it is trying to free a pointer to null or empty string
    // my solution (besides a submitting a patch) is to create a string with a space character as a placeholder

    // to handle word-wrapping we would need to create a vector of strings
    // and use the size via getGlobalBounds against the window size to handle the width
    // it gets much more complex with translations, but meh

    while (w.isOpen()) {

        sf::Event e;
        while (w.pollEvent(e)) {
            if (e.type == sf::Event::Closed || e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::Escape) {
                w.close();
            } else if (e.type == sf::Event::TextEntered) {
                if (e.text.unicode >= 32 && e.text.unicode <= 126) {

                    // add character
                    words += (char) e.text.unicode;

                } else if (e.text.unicode == 8) {

                    // backspace
                    words.erase(words.getSize() - 1, words.getSize());

                }

                sT.setString(words);
            }
        }

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
            source.y = Up;
            pS.move(0, -1 * c.getElapsedTime().asSeconds() * frameSpeed);
            animateSprite= true;
        } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
            source.y = Down;
            pS.move(0, 1 * c.getElapsedTime().asSeconds() * frameSpeed);
            animateSprite= true;
        } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
            source.y = Left;
            pS.move(-1 * c.getElapsedTime().asSeconds() * frameSpeed, 0);
            animateSprite= true;
        } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
            source.y = Right;
            pS.move(1 * c.getElapsedTime().asSeconds() * frameSpeed, 0);
            animateSprite= true;
        }

        if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
            sf::Vector2i mP = sf::Mouse::getPosition(w);
            pS.setPosition(mP.x - pS.getTextureRect().width / 2, mP.y - pS.getTextureRect().height / 2);

        }

        frameCounter = (updateFrame) ? frameCounter + frameSpeed * c.restart().asSeconds() : 1;
        if (frameCounter >= switchFrame) {
            frameCounter = 1;
        }

        if (animateSprite) {
            source.x++;
            if (source.x * 32 >= pT.getSize().x) {
                source.x = 0;
            }
        }

        pS.setTextureRect(sf::IntRect(source.x * 32, source.y * 32, 32, 32));
        w.draw(pS);

        // now we draw the text
        w.draw(sT);

        w.display();
        w.clear();
        animateSprite = false;
    }

    return 0;
}
Exemplo n.º 8
0
int main() {
    sf::Vector2i screenDimensions(800, 600);
    sf::RenderWindow w(sf::VideoMode(screenDimensions.x, screenDimensions.y), L"Whee");
    w.setKeyRepeatEnabled(false);

    // use to map to sprite facing by index (eg. first sprite is down, second is left, third is right, fourth is up)
    enum Direction { Down, Left, Right, Up };

    // create a game clock
    sf::Clock c;

    // define movement speeds
    float frameCounter = 1, switchFrame = 100, frameSpeed = 500, movementSpeed = 200;

    // some booleans for the game
    bool paused = false;

    // both players will use the same texture
    sf::Texture playerOneTexture;
    playerOneTexture.loadFromFile("../data/sprites/player1.png");
    sf::Texture playerTwoTexture;
    playerTwoTexture.loadFromFile("../data/sprites/player2.png");

    // create two player sprites
    sf::Sprite playerOne;
    sf::Sprite playerTwo;

    // create animation and position storage for each player
    bool animateOne = true, animateTwo = true;

    // set default directions for each players facing
    sf::Vector2i playerOneDirection(1, Down);
    sf::Vector2i playerTwoDirection(1, Down);

    // set texture on each sprite
    playerOne.setTexture(playerOneTexture);
    playerTwo.setTexture(playerTwoTexture);

    // set initial player sprites
    playerOne.setTextureRect(sf::IntRect(playerOneDirection.x * 32, playerOneDirection.y * 32, 32, 32));
    playerTwo.setTextureRect(sf::IntRect(playerTwoDirection.x * 32, playerTwoDirection.y * 32, 32, 32));

    // create background image
    sf::Texture background;
    background.loadFromFile("../data/levels/1.jpg");
    sf::Sprite backgroundSprite;
    backgroundSprite.setTexture(background);
    backgroundSprite.setScale(1.0f, (float) screenDimensions.y / background.getSize().y);

    // now we create two views, one for each viewport (playerOne and playerTwo)
    sf::View playerOneView;
    sf::View playerTwoView;

    // define each viewport
    playerOneView.reset(sf::FloatRect(0, 0, screenDimensions.x, screenDimensions.y));
    playerOneView.setViewport(sf::FloatRect(0, 0, 0.5f, 1.0f));
    playerOneView.setSize(screenDimensions.x / 2, screenDimensions.y);
    playerTwoView.reset(sf::FloatRect(0, 0, screenDimensions.x, screenDimensions.y));
    playerTwoView.setViewport(sf::FloatRect(0.5f, 0, 0.5f, 1.0f));
    playerTwoView.setSize(screenDimensions.x / 2, screenDimensions.y);

    // create a divider?
    sf::Vector2f viewPositionOne(screenDimensions.x / 2, screenDimensions.y / 2);
    sf::Vector2f viewPositionTwo(viewPositionOne);

    while (w.isOpen()) {

        sf::Event e;
        while (w.pollEvent(e)) {
            if (e.type == sf::Event::Closed || e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::Escape) {
                w.close();
            }
        }

        // player one controls
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
            playerOneDirection.y = Up;
            playerOne.move(0, -movementSpeed * c.getElapsedTime().asSeconds());
            animateOne = true;
        } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
            playerOneDirection.y = Down;
            playerOne.move(0, movementSpeed * c.getElapsedTime().asSeconds());
            animateOne = true;
        } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
            playerOneDirection.y = Left;
            playerOne.move(-movementSpeed * c.getElapsedTime().asSeconds(), 0);
            animateOne = true;
        } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
            playerOneDirection.y = Right;
            playerOne.move(movementSpeed * c.getElapsedTime().asSeconds(), 0);
            animateOne = true;
        }

        // player two controls
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
            playerTwoDirection.y = Up;
            playerTwo.move(0, -movementSpeed * c.getElapsedTime().asSeconds());
            animateTwo = true;
        } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
            playerTwoDirection.y = Down;
            playerTwo.move(0, movementSpeed * c.getElapsedTime().asSeconds());
            animateTwo = true;
        } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
            playerTwoDirection.y = Left;
            playerTwo.move(-movementSpeed * c.getElapsedTime().asSeconds(), 0);
            animateTwo = true;
        } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
            playerTwoDirection.y = Right;
            playerTwo.move(movementSpeed * c.getElapsedTime().asSeconds(), 0);
            animateTwo = true;
        }

        // use same timelapse for multiple characters calculations
        float timeLapse = c.restart().asSeconds();
        frameCounter = (animateOne || animateTwo) ? frameCounter + frameSpeed * timeLapse : 1;
        if (frameCounter >= switchFrame) {

            // reset frameCounter
            frameCounter = 1;

            // handle playerOne animation changes
            if (animateOne) {
                playerOneDirection.x++;
                if (playerOneDirection.x * 32 >= playerOneTexture.getSize().x) {
                    playerOneDirection.x = 0;
                }
                animateOne = false;
            }

            // handle playerTwo animation changes
            if (animateTwo) {
                playerTwoDirection.x++;
                if (playerTwoDirection.x * 32 >= playerTwoTexture.getSize().x) {
                    playerTwoDirection.x = 0;
                }
                animateTwo = false;
            }

        }

        // zoom by floating point, and it is ratio based on the current view size
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) {
            playerOneView.zoom(1.01f);
            playerTwoView.zoom(1.01f);
        } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::X)) {
            playerOneView.zoom(0.99f);
            playerTwoView.zoom(0.99f);
        }


        // rotation is the same method, values are forwards or backwards
        // radians can be used as well with slightly different arg parameter signature
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::R)) {
            playerOneView.rotate(0.1f);
            playerTwoView.rotate(0.1f);
        } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::E)) {
            playerOneView.rotate(-0.1f);
            playerTwoView.rotate(-0.1f);
        }

        // getting it back to perfect centering is really difficult
        // ideally you should track the original or "normal" view
        // state and have a key to reset the view


        // handle viewport movement/scrolling
        if (playerOne.getPosition().x + 16 >= playerOneView.getSize().x / 2) {
            viewPositionOne.x = playerOne.getPosition().x + 16;
        } else {
            viewPositionOne.x = playerOneView.getSize().x / 2;
        }
        if (playerTwo.getPosition().x + 16 >= playerTwoView.getSize().x / 2) {
            viewPositionTwo.x = playerTwo.getPosition().x + 16;
        } else {
            viewPositionTwo.x = playerTwoView.getSize().x / 2;
        }
        playerOneView.setCenter(viewPositionOne);
        playerTwoView.setCenter(viewPositionTwo);

        // render both players (shitz bout to get crazy with double rendered views)
        playerOne.setTextureRect(sf::IntRect(playerOneDirection.x * 32, playerOneDirection.y * 32, 32, 32));
        playerTwo.setTextureRect(sf::IntRect(playerTwoDirection.x * 32, playerTwoDirection.y * 32, 32, 32));

        // render viewport one
        w.setView(playerOneView);
        w.draw(backgroundSprite);

        // draw players in viewport one
        w.draw(playerOne);
        w.draw(playerTwo);

        // render viewport two
        w.setView(playerTwoView);
        w.draw(backgroundSprite);

        // draw players in viewport two
        w.draw(playerOne);
        w.draw(playerTwo);

        // draw renders to screen and clear clutter
        w.display();
        w.clear();
    }

    return 0;
}
Exemplo n.º 9
0
int main()
{
    // setup window
    sf::Vector2i screenDimensions(800,600);
    sf::RenderWindow window(sf::VideoMode(screenDimensions.x, screenDimensions.y), "Animations!");
    window.setFramerateLimit(60);

    // load texture (spritesheet)
    sf::Texture texture;
    if (!texture.loadFromFile("player.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }

    // set up the animations for all four directions (set spritesheet and push frames)
    Animation walkingAnimationDown;
    walkingAnimationDown.setSpriteSheet(texture);
    walkingAnimationDown.addFrame(sf::IntRect(32, 0, 32, 32));
    walkingAnimationDown.addFrame(sf::IntRect(64, 0, 32, 32));
    walkingAnimationDown.addFrame(sf::IntRect(32, 0, 32, 32));
    walkingAnimationDown.addFrame(sf::IntRect( 0, 0, 32, 32));

    Animation walkingAnimationLeft;
    walkingAnimationLeft.setSpriteSheet(texture);
    walkingAnimationLeft.addFrame(sf::IntRect(32, 32, 32, 32));
    walkingAnimationLeft.addFrame(sf::IntRect(64, 32, 32, 32));
    walkingAnimationLeft.addFrame(sf::IntRect(32, 32, 32, 32));
    walkingAnimationLeft.addFrame(sf::IntRect( 0, 32, 32, 32));

    Animation walkingAnimationRight;
    walkingAnimationRight.setSpriteSheet(texture);
    walkingAnimationRight.addFrame(sf::IntRect(32, 64, 32, 32));
    walkingAnimationRight.addFrame(sf::IntRect(64, 64, 32, 32));
    walkingAnimationRight.addFrame(sf::IntRect(32, 64, 32, 32));
    walkingAnimationRight.addFrame(sf::IntRect( 0, 64, 32, 32));

    Animation walkingAnimationUp;
    walkingAnimationUp.setSpriteSheet(texture);
    walkingAnimationUp.addFrame(sf::IntRect(32, 96, 32, 32));
    walkingAnimationUp.addFrame(sf::IntRect(64, 96, 32, 32));
    walkingAnimationUp.addFrame(sf::IntRect(32, 96, 32, 32));
    walkingAnimationUp.addFrame(sf::IntRect( 0, 96, 32, 32));

    Animation* currentAnimation = &walkingAnimationDown;

    // set up AnimatedSprite
    AnimatedSprite animatedSprite(sf::seconds(0.2), true, false);
    animatedSprite.setPosition(sf::Vector2f(screenDimensions / 2));

    sf::Clock frameClock;

    float speed = 80.f;
    bool noKeyWasPressed = true;

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
                window.close();
        }

        sf::Time frameTime = frameClock.restart();

        // if a key was pressed set the correct animation and move correctly
        sf::Vector2f movement(0.f, 0.f);
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
        {
            currentAnimation = &walkingAnimationUp;
            movement.y -= speed;
            noKeyWasPressed = false;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
        {
            currentAnimation = &walkingAnimationDown;
            movement.y += speed;
            noKeyWasPressed = false;
        }
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
            currentAnimation = &walkingAnimationLeft;
            movement.x -= speed;
            noKeyWasPressed = false;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
            currentAnimation = &walkingAnimationRight;
            movement.x += speed;
            noKeyWasPressed = false;
        }
        animatedSprite.play(*currentAnimation);
        animatedSprite.move(movement * frameTime.asSeconds());

        // if no key was pressed stop the animation
        if (noKeyWasPressed)
        {
            animatedSprite.stop();
        }
        noKeyWasPressed = true;

        // update AnimatedSprite
        animatedSprite.update(frameTime);

        // draw
        window.clear();
        window.draw(animatedSprite);
        window.display();
    }

    return 0;
}