Esempio n. 1
0
    void openChest(Chestwo, sf::Vector2f Pos, sf::Sprite s)
    {
        s.setPosition(Pos);
        window->draw(s);

    }
Esempio n. 2
0
sf::Sprite Missile::supprimerMissile(sf::Sprite sp)
{
    sp.setScale(0.0f, 0.0f);
    sp.setPosition(0.0f, 0.0f);
    return sp;
}
Esempio n. 3
0
 void GraphicsHandler::drawSpriteAtCell(sf::Sprite &s, std::size_t x, std::size_t y)
 {
     s.setPosition(x*board_config.cellWidth(), y*board_config.cellHeight());
     display.draw(s);
 }
Esempio n. 4
0
void character::step_back(){
    xpos -= xvel;
    ypos -= yvel;
    sprite.setPosition(sf::Vector2f(xpos, ypos));
    collision_box = sprite.getGlobalBounds();
}
Esempio n. 5
0
///
/// main function
//
int main()
{

	// Initialize the screen
	sf::RenderWindow rw(sf::VideoMode(640,496),"Caverns");
	global::rwpWindow = &rw;

	// Seed the random number generator
	ut::seed();
	std::cout << "seed: " << ut::current_seed << std::endl;

	// Set up fpscalc
	FpsCalc::GetInstance()->Init(60);

	// Load all the fonts
	global::fntMain.loadFromFile("resources/font/pixelette.ttf");
	global::fntDeath.loadFromFile("resources/font/trebucbd.ttf");

	// Load all the sounds
	global::SNDBUF_mine.loadFromFile("resources/sound/mine.wav");
	global::SNDBUF_zombie.loadFromFile("resources/sound/zombie.wav");
	global::SNDBUF_zombie_omg.loadFromFile("resources/sound/zombie_omg.wav");
	global::SNDBUF_player_hit.loadFromFile("resources/sound/player_hit.wav");
	global::SNDBUF_player_miss.loadFromFile("resources/sound/player_miss.wav");
	global::SNDBUF_player_hurt.loadFromFile("resources/sound/player_hurt.wav");
	global::SNDBUF_get_sword.loadFromFile("resources/sound/get_sword.wav");

	// Load all the textures
	global::TXT_player_down.loadFromFile("resources/texture/player_down.png");
	global::TXT_player_up.loadFromFile("resources/texture/player_up.png");
	global::TXT_player_left.loadFromFile("resources/texture/player_left.png");
	global::TXT_player_right.loadFromFile("resources/texture/player_right.png");
	global::TXT_player_down_sword.loadFromFile("resources/texture/player_down_sword.png");
	global::TXT_player_right_sword.loadFromFile("resources/texture/player_right_sword.png");

	global::TXT_wall.loadFromFile("resources/texture/wall.png");
	global::TXT_u_wall.loadFromFile("resources/texture/unbreakable_wall.png");
	global::TXT_exit.loadFromFile("resources/texture/exit.png");
	global::TXT_lantern.loadFromFile("resources/texture/lantern.png");
	global::TXT_chest_closed.loadFromFile("resources/texture/chest_closed.png");
	global::TXT_chest_open.loadFromFile("resources/texture/chest_open.png");

	global::TXT_menu.loadFromFile("resources/texture/menu.png");
	global::TXT_dead.loadFromFile("resources/texture/dead.png");
	global::TXT_pause.loadFromFile("resources/texture/paused.png");

	global::TXT_zombie_left.loadFromFile("resources/texture/zombie_left.png");
	global::TXT_zombie_right.loadFromFile("resources/texture/zombie_right.png");
	global::TXT_zombie_left_omg.loadFromFile("resources/texture/zombie_left_omg.png");
	global::TXT_zombie_right_omg.loadFromFile("resources/texture/zombie_right_omg.png");




	// Set sprites
	SPR_menu.setTexture(global::TXT_menu); SPR_menu.setPosition(0,0);
	SPR_dead.setTexture(global::TXT_dead); SPR_dead.setPosition(0,0);
	SPR_pause.setTexture(global::TXT_pause); SPR_pause.setPosition(0,0);




	///////           ///////
	// Enter the main loop //
	///////           ///////
	int loop_return = main_loop();




	// Close the screen
	global::rwpWindow->close();

	// Free all memmory used
	FpsCalc::GetInstance()->FreeMemory();

	return 0;
}
Esempio n. 6
0
	//Drop item sprite render.
	void update(float time) {
		
		//if(~isMarkedForRemoval())
			mSprite.setPosition(mRect.left - offsetX, mRect.top - offsetY);

	}
Esempio n. 7
0
int screen_1::Run(sf::RenderWindow &App)
{
    hop.setBuffer(hopFile);
    trucked.setBuffer(truckedFile);
    dunked.setBuffer(dunkedFile);
    
    // Clock
    sf:: Clock clock;
    sf::Time time;
    sf::Time delay;
    
    // Plays Intro
    intro.play();
    delay = intro.getDuration();
    
    time = clock.getElapsedTime();
    // Music
    while ( clock.getElapsedTime() <= delay )
    {
        //cout << "NO";
    }
    froggerTheme.setVolume(50);
    froggerTheme.play();
    clock.restart();
    
    sf::Event Event;
    
    bool Running = true;
    int sum = 0;// for log testing purposes
    int sum2 = 0;
    int sum3 = 0;
    int sum4 = 0;
    int sum5 = 0;
    int sum6 = 0;
    int sum7 = 0;
    int sum8 = 0;
    int sum9 = 0;
    int sum10 = 0;
    
    while (Running)
    {
        // Timer Rect and Clock
        double time = clock.getElapsedTime().asSeconds();
        
        if(time >= 1.5)
        {
            timeRect.width = timeRect.width - 2.383;
            timer.setTextureRect(timeRect);
            clock.restart();
        }
        
        if(timeRect.width <= 0)
        {
            frogOnLily1 = false;
            frogOnLily2 = false;
            frogOnLily3 = false;
            frogOnLily4 = false;
            frogOnLily5 = false;
            mainPlayer.setNumLives(3);
            rectSource.width = 115;
            life.setTextureRect(rectSource);
            occupied1.setPosition(-100, -100);
            occupied2.setPosition(-100, -100);
            occupied3.setPosition(-100, -100);
            occupied4.setPosition(-100, -100);
            occupied5.setPosition(-100, -100);
            froggerTheme.pause();
            clock.restart();
            timeRect.width = 143;
            timer.setTextureRect(timeRect);
            frogger.setPosition(320, 605);
            
            return 2;
        }
        // *********************************************************************
        // Creating the objects of Object class for continuous movement
        //
        // Object(double posX, double posY, double speed)
        // *********************************************************************
        // Trucks
        Object t1(130, 420,0.2 );
        Object t2(550, 290, 0.2);
        // Cars
        Object c1(-50, 420, 0.3);
        Object c2(280, 289, 0.2);
        Object c3(0, 289, 0.2);
        // Short Logs
        Object sl1(0, 125, 0.2);
        Object sl2(200, 61, 0.3);
        Object sl3(300, 8, 0.4);
        // Long Logs
        Object l1(799, 8.3, 0.4);
        Object l2(500, 125, 0.2);
        
        // Sets object's direction
        t1.moveRight(truck);
        t2.moveLeft(truck2);
        c1.moveRight(car);
        c2.moveLeft(car2);
        c3.moveLeft(car3);
        sl1.moveRight(shortLog);
        sl2.moveLeft(shortLog2);
        sl3.moveRight(shortLog3);
        l1.moveRight(longLog);
        l2.moveRight(longLog2);
        
        
        // *********************************************************************
        // The following rectangles are for collision detection
        // *********************************************************************
        // Frog
        sf::RectangleShape rect;
        
        // Trucks
        sf::RectangleShape rect2;
        sf::RectangleShape rect3;
        
        // Cars
        sf::RectangleShape rect4;
        sf::RectangleShape rect5;
        sf::RectangleShape rect6;
        
        // Short Logs
        sf::RectangleShape rect7;
        sf::RectangleShape rect8;
        sf::RectangleShape rect9;
        
        // Long Logs
        sf::RectangleShape rect10;
        sf::RectangleShape rect11;
        
        // River
        sf::RectangleShape rect12;
        
        // Lilypads
        sf::RectangleShape rect13;
        sf::RectangleShape rect14;
        sf::RectangleShape rect15;
        sf::RectangleShape rect16;
        sf::RectangleShape rect17;
        
        // *********************************************************************
        // Setting size of rectangles aka size(width, height)
        // *********************************************************************
        // Frog
        sf::Vector2f size(40, 40);
        
        // Truck
        sf::Vector2f size2(120, 70);
        sf::Vector2f size3(120, 70);
        sf::Vector2f size4(95, 70);
        
        // Cars
        sf::Vector2f size5(95, 70);
        sf::Vector2f size6(95, 70);
        
        // Short Logs
        sf::Vector2f size7(85, 35);
        sf::Vector2f size8(85, 35);
        sf::Vector2f size9(85, 35);
        
        // Long Log
        sf::Vector2f size10(135, 35);
        sf::Vector2f size11(135, 35);
        
        // River
        sf::Vector2f size12(800, 230);
        
        // Lilypads
        sf::Vector2f size13(60, 60);
        sf::Vector2f size14(60, 60);
        sf::Vector2f size15(60, 60);
        sf::Vector2f size16(60, 60);
        sf::Vector2f size17(60, 60);
        
        // *********************************************************************
        // Get pos of every object
        // *********************************************************************
        // Trucks
        sf::Vector2f objectPos = truck.getPosition();
        sf::Vector2f objectPos2 = truck2.getPosition();
        // Cars
        sf::Vector2f objectPos3 = car.getPosition();
        sf::Vector2f objectPos4 = car2.getPosition();
        sf::Vector2f objectPos5 = car3.getPosition();
        // Short Logs
        sf::Vector2f objectPos6 = shortLog.getPosition();
        sf::Vector2f objectPos7 = shortLog2.getPosition();
        sf::Vector2f objectPos8 = shortLog3.getPosition();
        // Long Logs
        sf::Vector2f objectPos9 = longLog.getPosition();
        sf::Vector2f objectPos10 = longLog2.getPosition();
        // Lilypad
        sf::Vector2f objectPos11 = lillypad.getPosition();
        sf::Vector2f objectPos12 = lillypad2.getPosition();
        sf::Vector2f objectPos13 = lillypad3.getPosition();
        sf::Vector2f objectPos14 = lillypad4.getPosition();
        sf::Vector2f objectPos15 = lillypad5.getPosition();
        
        // *********************************************************************
        // Sets boundary settings
        // *********************************************************************
        sf::Vector2f pos = frogger.getPosition();
        
        // Frog
        rect.setPosition(pos.x + 30 , pos.y +10);
        rect.setSize(size);
        rect.setFillColor(sf::Color::Transparent);
        rect.setOutlineColor(sf::Color::Red);
        rect.setOutlineThickness(5);
        
        // Trucks
        rect2.setPosition(objectPos.x + 40, objectPos.y + 20);
        rect2.setSize(size2);
        rect2.setFillColor(sf::Color::Transparent);
        rect2.setOutlineColor(sf::Color::Red);
        rect2.setOutlineThickness(5);
        
        rect3.setPosition(objectPos2.x + 40, objectPos2.y + 60);
        rect3.setSize(size3);
        rect3.setFillColor(sf::Color::Transparent);
        rect3.setOutlineColor(sf::Color::Red);
        rect3.setOutlineThickness(5);
        
        // Cars
        rect4.setPosition(objectPos3.x + 45, objectPos3.y + 70);
        rect4.setSize(size4);
        rect4.setFillColor(sf::Color::Transparent);
        rect4.setOutlineColor(sf::Color::Red);
        rect4.setOutlineThickness(5);
        
        rect5.setPosition(objectPos4.x + 50, objectPos4.y + 70);
        rect5.setSize(size5);
        rect5.setFillColor(sf::Color::Transparent);
        rect5.setOutlineColor(sf::Color::Red);
        rect5.setOutlineThickness(5);
        
        rect6.setPosition(objectPos5.x + 50, objectPos5.y + 70);
        rect6.setSize(size6);
        rect6.setFillColor(sf::Color::Transparent);
        rect6.setOutlineColor(sf::Color::Red);
        rect6.setOutlineThickness(5);
        
        // Short Logs
        rect7.setPosition(objectPos6.x + 30, objectPos6.y + 80);
        rect7.setSize(size7);
        rect7.setFillColor(sf::Color::Transparent);
        rect7.setOutlineColor(sf::Color::Red);
        rect7.setOutlineThickness(5);
        
        rect8.setPosition(objectPos7.x + 30, objectPos7.y + 80);
        rect8.setSize(size8);
        rect8.setFillColor(sf::Color::Transparent);
        rect8.setOutlineColor(sf::Color::Red);
        rect8.setOutlineThickness(5);
        
        rect9.setPosition(objectPos8.x + 30, objectPos8.y + 80);
        rect9.setSize(size9);
        rect9.setFillColor(sf::Color::Transparent);
        rect9.setOutlineColor(sf::Color::Red);
        rect9.setOutlineThickness(5);
        
        // Long Logs
        rect10.setPosition(objectPos9.x + 35, objectPos9.y + 70);
        rect10.setSize(size10);
        rect10.setFillColor(sf::Color::Transparent);
        rect10.setOutlineColor(sf::Color::Red);
        rect10.setOutlineThickness(5);
        
        rect11.setPosition(objectPos10.x + 35, objectPos10.y + 70);
        rect11.setSize(size11);
        rect11.setFillColor(sf::Color::Transparent);
        rect11.setOutlineColor(sf::Color::Red);
        rect11.setOutlineThickness(5);
        // River
        rect12.setPosition(0, 0);
        rect12.setSize(size12);
        rect12.setFillColor(sf::Color::Transparent);
        rect12.setOutlineColor(sf::Color::Red);
        rect12.setOutlineThickness(5);
        
        // Lilypads
        rect13.setPosition(objectPos11.x + 30, objectPos11.y+40);
        rect13.setSize(size13);
        rect13.setFillColor(sf::Color::Transparent);
        rect13.setOutlineColor(sf::Color::Red);
        rect13.setOutlineThickness(5);
        
        rect14.setPosition(objectPos12.x + 30 , objectPos12.y+40);
        rect14.setSize(size14);
        rect14.setFillColor(sf::Color::Transparent);
        rect14.setOutlineColor(sf::Color::Red);
        rect14.setOutlineThickness(5);
        
        rect15.setPosition(objectPos13.x + 30, objectPos13.y+40);
        rect15.setSize(size15);
        rect15.setFillColor(sf::Color::Transparent);
        rect15.setOutlineColor(sf::Color::Red);
        rect15.setOutlineThickness(5);
        
        rect16.setPosition(objectPos14.x + 30 , objectPos14.y+40);
        rect16.setSize(size16);
        rect16.setFillColor(sf::Color::Transparent);
        rect16.setOutlineColor(sf::Color::Red);
        rect16.setOutlineThickness(5);
        
        rect17.setPosition(objectPos15.x + 30 , objectPos15.y+40);
        rect17.setSize(size17);
        rect17.setFillColor(sf::Color::Transparent);
        rect17.setOutlineColor(sf::Color::Red);
        rect17.setOutlineThickness(5);
        
        // *********************************************************************
        // Frogger Hit Truck 1
        // *********************************************************************
        if (rect.getGlobalBounds().intersects(rect2.getGlobalBounds()))
            
        {
            
            froggerTheme.pause();
            trucked.play();
            
            lives = mainPlayer.getNumLives();
            mainPlayer.setNumLives(lives - 1);
            mainPlayer.setIsHit(true);
            rectSource.width -= 38.3;
            life.setTextureRect(rectSource);
         
            froggerTheme.play();
            //death.setPosition(-100,-100);
        }
        // *********************************************************************
        // Frogger Hit Truck 2
        // *********************************************************************
        if (rect.getGlobalBounds().intersects(rect3.getGlobalBounds()))
        {
            froggerTheme.pause();
            trucked.play();
            
            lives = mainPlayer.getNumLives();
            mainPlayer.setNumLives(lives - 1);
            mainPlayer.setIsHit(true);
            rectSource.width -= 38.3;
            life.setTextureRect(rectSource);
            
            sf::Vector2f pos = frogger.getPosition();
            death.setPosition(pos);
            
            froggerTheme.play();
            death.setPosition(-100,-100);
            
        }
        // *********************************************************************
        // Frogger Hit Car 1
        // *********************************************************************
        if (rect.getGlobalBounds().intersects(rect4.getGlobalBounds()))
        {
            froggerTheme.pause();
            trucked.play();
            
            lives = mainPlayer.getNumLives();
            mainPlayer.setNumLives(lives - 1);
            mainPlayer.setIsHit(true);
            rectSource.width -= 38.3;
            life.setTextureRect(rectSource);
            
            sf::Vector2f pos = frogger.getPosition();
            death.setPosition(pos);
            
            froggerTheme.play();
            death.setPosition(-100,-100);
            
        }
        // *********************************************************************
        // Frogger Hit Car 2
        // *********************************************************************
        if (rect.getGlobalBounds().intersects(rect5.getGlobalBounds()))
        {
            froggerTheme.pause();
            trucked.play();
            
            lives = mainPlayer.getNumLives();
            mainPlayer.setNumLives(lives - 1);
            mainPlayer.setIsHit(true);
            rectSource.width -= 38.3;
            life.setTextureRect(rectSource);
            
            sf::Vector2f pos = frogger.getPosition();
            death.setPosition(pos);
            
            froggerTheme.play();
            death.setPosition(-100,-100);
            
        }
        // *********************************************************************
        // Frogger Hit Car 3
        // *********************************************************************
        if (rect.getGlobalBounds().intersects(rect6.getGlobalBounds()))
        {
            froggerTheme.pause();
            trucked.play();
            
            lives = mainPlayer.getNumLives();
            mainPlayer.setNumLives(lives - 1);
            mainPlayer.setIsHit(true);
            rectSource.width -= 38.3;
            life.setTextureRect(rectSource);
            
            sf::Vector2f pos = frogger.getPosition();
            death.setPosition(pos);
            
            froggerTheme.play();
            death.setPosition(-100,-100);
            
        }
        
        // *********************************************************************
        // Below this line will be log collision checking
        // *********************************************************************
        if (rect.getGlobalBounds().intersects(rect7.getGlobalBounds()))
        {
            frogger.setPosition(objectPos6.x + 45 + sum2 , objectPos6.y + 80 + sum);
            isOnLog = true;
        }
        else
        {
            isOnLog = false;
            sum = 0;
            sum2 = 0;
        }
        
        if (rect.getGlobalBounds().intersects(rect8.getGlobalBounds()))
        {
            
            frogger.setPosition(objectPos7.x + 45 + sum4, objectPos7.y + 80 + sum3);
            isOnLog2 = true;
        }
        else
        {
            isOnLog2 = false;
            sum3 = 0;
            sum4 = 0;
        }
        if (rect.getGlobalBounds().intersects(rect9.getGlobalBounds()))
        {
            frogger.setPosition(objectPos8.x + 45+sum6, objectPos8.y + 80+sum5);
            isOnLog3 = true;
        }
        else
        {
            isOnLog3 = false;
            sum5 = 0;
            sum6 = 0;
            
        }
        if (rect.getGlobalBounds().intersects(rect10.getGlobalBounds()))
        {
            frogger.setPosition(objectPos9.x + 45 + sum8, objectPos9.y + 70+ sum7);
            isOnLog4 = true;
            
        }
        else
        {
            isOnLog4 = false;
            sum7 = 0;
            sum8 = 0;
        }
        if (rect.getGlobalBounds().intersects(rect11.getGlobalBounds()))
        {
            frogger.setPosition(objectPos10.x + 45+ sum10, objectPos10.y + 70+sum9);
            isOnLog5 = true;
        }
        else
        {
            isOnLog5 = false;
            sum9 = 0;
            sum10 = 0;
        }
        
        // *********************************************************************
        // Below this line will be lily collision checking
        // *********************************************************************
        if (rect.getGlobalBounds().intersects(rect13.getGlobalBounds()))
        {
            isOnLily = true;
            if (frogOnLily1 == false)
            {
                score += 50;
            }
            frogOnLily1 = true;
            sf::Vector2f lilyPos = rect13.getPosition();
            occupied1.setPosition(lilyPos);
            
        }
        if (rect.getGlobalBounds().intersects(rect14.getGlobalBounds()))
        {
            isOnLily = true;
            if (frogOnLily2 == false)
            {
                score += 50;
            }
            frogOnLily2 = true;
            sf::Vector2f lilyPos = rect14.getPosition();
            occupied2.setPosition(lilyPos);
        }
        if (rect.getGlobalBounds().intersects(rect15.getGlobalBounds()))
        {
            isOnLily = true;
            if (frogOnLily3 == false)
            {
                score += 50;
            }
            frogOnLily3 = true;
            sf::Vector2f lilyPos = rect15.getPosition();
            occupied3.setPosition(lilyPos);
            
        }
        if (rect.getGlobalBounds().intersects(rect16.getGlobalBounds()))
        {
            isOnLily = true;
            if (frogOnLily4 == false)
            {
                score += 50;
            }
            frogOnLily4 = true;
            sf::Vector2f lilyPos = rect16.getPosition();
            occupied4.setPosition(lilyPos);
        }
        if (rect.getGlobalBounds().intersects(rect17.getGlobalBounds()))
        {
            isOnLily = true;
            if (frogOnLily5 == false)
            {
                score += 50;
            }
            frogOnLily5 = true;
            sf::Vector2f lilyPos = rect17.getPosition();
            occupied5.setPosition(lilyPos);
        }
        
        // *********************************************************************
        // Checks if frogger is on log AND goes outside screen boundaries
        //  if so frogger dies
        // *********************************************************************
        sf::Vector2f location = frogger.getPosition();
        // Checks if frogger went out of bounds
        if (rect.getGlobalBounds().intersects(rect12.getGlobalBounds()))
        {
            if ((isOnLog || isOnLog2 || isOnLog3 || isOnLog4 || isOnLog5) && (location.x >= 740 || location.x < -40))
            {
                mainPlayer.setIsHit(true);
                lives = mainPlayer.getNumLives();
                mainPlayer.setNumLives(lives - 1);
                rectSource.width -= 38.3;
                life.setTextureRect(rectSource);
                
            }
        }
        // Checks if frogger is on the logs not the water
        if (rect.getGlobalBounds().intersects(rect12.getGlobalBounds()))
        {
            if (isOnLog || isOnLog2 || isOnLog3 || isOnLog4 || isOnLog5)
            {
                //this frogger is on the logs not the water
            }
            else
            {
                froggerTheme.pause();
                dunked.play();
                froggerTheme.play();
                mainPlayer.setIsHit(true);
                lives = mainPlayer.getNumLives();
                mainPlayer.setNumLives(lives - 1);
                rectSource.width -= 38.3;
                life.setTextureRect(rectSource);
            }
            
        }
        // Checks if the frog has landed on a lilypad
        if (isOnLily || isOnLily2 || isOnLily3 || isOnLily4 || isOnLily5)
        {
            // the frog has landed on the lily pad
            froggerLanded = true;
        }
        // *********************************************************************
        // Checks if the frog has landed on all 5 lilypads if so you win
        // *********************************************************************
        if (frogOnLily1 && frogOnLily2 && frogOnLily3 && frogOnLily4 && frogOnLily5)
        {
            score += 10000;
            
            frogOnLily1 = false;
            frogOnLily2 = false;
            frogOnLily3 = false;
            frogOnLily4 = false;
            frogOnLily5 = false;
            
            mainPlayer.setNumLives(3);
            rectSource.width = 115;
            life.setTextureRect(rectSource);
            occupied1.setPosition(-100, -100);
            occupied2.setPosition(-100, -100);
            occupied3.setPosition(-100, -100);
            occupied4.setPosition(-100, -100);
            occupied5.setPosition(-100, -100);
            froggerTheme.pause();
            clock.restart();
            timeRect.width = 143;
            timer.setTextureRect(timeRect);
            frogger.setPosition(320, 605);
            
            return 2;
        }
        while (App.pollEvent(Event))
        {
            // Window closed
            if (Event.type == sf::Event::Closed)
            {
                return (-1);
            }
            // *********************************************************************
            // LEFT
            // *********************************************************************
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
            {
                
                if (isOnLog)
                {
                    sum2 = (sum2 + (20 * -1));
                }
                if (isOnLog2)
                {
                    sum4 = (sum4 + (20 * -1));
                }
                if (isOnLog3)
                {
                    sum6 = (sum6 + (20 * -1));
                }
                if (isOnLog4)
                {
                    sum8 = (sum8 + (20 * -1));
                }
                if (isOnLog5)
                {
                    sum10 = (sum10 + (20 * -1));
                }
                
                
                sf::Vector2f pos = frogger.getPosition();
                
                
                if (pos.x < 0)
                {
                    frogger.move(0, 0);
                }
                else
                {
                    if (rectSourceSprite.left != 216)
                    {
                        rectSourceSprite.left = 216;
                        rectSourceSprite.width = 55;
                        frogger.setTextureRect(rectSourceSprite);
                    }
                    score += 10;
                    froggerTheme.setVolume(0);
                    hop.play();
                    frogger.move(-40, 0);
                    froggerTheme.setVolume(50);
                    
                }
            }
            // *********************************************************************
            // RIGHT
            // *********************************************************************
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
            {
                if (isOnLog)
                {
                    sum2 = (sum2 + (20));
                }
                if (isOnLog2)
                {
                    sum4 = (sum4 + (20));
                }
                if (isOnLog3)
                {
                    sum6 = (sum6 + (20));
                }
                if (isOnLog4)
                {
                    sum8 = (sum8 + (20));
                }
                if (isOnLog5)
                {
                    sum10 = (sum10 + (20));
                }
                
                sf::Vector2f pos = frogger.getPosition();
                
                if (pos.x >= 640)
                {
                    frogger.move(0, 0);
                }
                else
                {
                    if (rectSourceSprite.left != 89)
                    {
                        rectSourceSprite.left = 89;
                        rectSourceSprite.width = 60;
                        frogger.setTextureRect(rectSourceSprite);
                    }
                    score += 10;
                    froggerTheme.setVolume(0);
                    hop.play();
                    frogger.move(40, 0);
                    froggerTheme.setVolume(50);
                }
            }
            // *********************************************************************
            // UP
            // *********************************************************************
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
            {
                
                
                if (isOnLog)
                {
                    sum = (sum + (20 * -1));
                }
                
                if (isOnLog2)
                {
                    sum3 = (sum3 + (20 * -1));
                }
                if (isOnLog3)
                {
                    sum5 = (sum5 + (20 * -1));
                }
                if (isOnLog4)
                {
                    sum7 = (sum7 + (20 * -1));
                }
                if (isOnLog5)
                {
                    sum9 = (sum9 + (20 * -1));
                }
                
                
                if (pos.y <= -35)
                {
                    frogger.move(0, 0);
                }
                else
                {
                    if (rectSourceSprite.left != 0)
                    {
                        rectSourceSprite.left = 0;
                        rectSourceSprite.width = 89;
                        frogger.setTextureRect(rectSourceSprite);
                    }
                    score += 10;
                    froggerTheme.setVolume(0);
                    hop.play();
                    frogger.move(0, -40);
                    froggerTheme.setVolume(50);
                }
            }
            // *********************************************************************
            // DOWN
            // *********************************************************************
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
            {
                
                
                if (isOnLog)
                {
                    sum = (sum + 20);
                }
                
                if (isOnLog2)
                {
                    sum3 = (sum3 + 20);
                }
                if (isOnLog3)
                {
                    sum5 = (sum5 + 20);
                }
                
                if (isOnLog4)
                {
                    sum7 = (sum7 + 20);
                }
                if (isOnLog5)
                {
                    sum9 = (sum9 + 20);
                }
                sf::Vector2f pos = frogger.getPosition();
                if (pos.y >= 650)
                {
                    frogger.move(0, 0);
                }
                else
                {
                    if (rectSourceSprite.left != 149)
                    {
                        rectSourceSprite.left = 149;
                        rectSourceSprite.width = 67;
                        frogger.setTextureRect(rectSourceSprite);
                    }
                    score += 10;
                    froggerTheme.setVolume(0);
                    hop.play();
                    frogger.move(0, 40);
                    froggerTheme.setVolume(50);
                }
            }
        }
        
        // *********************************************************************
        // Checks if player has been hit
        // *********************************************************************
        if (mainPlayer.getIsHit() == true)
        {
            cout << " Number of lives" << mainPlayer.getNumLives() << endl;
            mainPlayer.setIsHit(false);
            rectSourceSprite.left = 0;
            rectSourceSprite.width = 89;
            frogger.setTextureRect(rectSourceSprite);
            frogger.setPosition(320, 605);
        }
        // *********************************************************************
        // Checks if player landed on lily
        // *********************************************************************
        if (froggerLanded == true)
        {
            froggerLanded = false;
            rectSourceSprite.left = 0;
            rectSourceSprite.width = 89;
            frogger.setTextureRect(rectSourceSprite);
            frogger.setPosition(320, 605);
            isOnLily = false;
            isOnLily2 = false;
            isOnLily3 = false;
            isOnLily4 = false;
            isOnLily5 = false;
        }
        // *********************************************************************
        // Checks if player has run out of lives
        // *********************************************************************
        if (mainPlayer.getNumLives() < 1)
        {
            frogOnLily1 = false;
            frogOnLily2 = false;
            frogOnLily3 = false;
            frogOnLily4 = false;
            frogOnLily5 = false;
            mainPlayer.setNumLives(3);
            rectSource.width = 115;
            life.setTextureRect(rectSource);
            occupied1.setPosition(-100, -100);
            occupied2.setPosition(-100, -100);
            occupied3.setPosition(-100, -100);
            occupied4.setPosition(-100, -100);
            occupied5.setPosition(-100, -100);
            froggerTheme.pause();
            clock.restart();
            timeRect.width = 143;
            timer.setTextureRect(timeRect);
            frogger.setPosition(320, 605);
            
            return 2;
            
        }
        
        App.clear(sf::Color(0, 0, 0, 0));
        //Drawing
        App.draw(background);
        App.draw(car2);
        App.draw(car3);
        App.draw(truck2);
        App.draw(truck);
        App.draw(car);
        App.draw(longLog);
        App.draw(longLog2);
        App.draw(shortLog);
        App.draw(shortLog2);
        App.draw(shortLog3);
        App.draw(lillypad);
        App.draw(lillypad2);
        App.draw(lillypad3);
        App.draw(lillypad4);
        App.draw(lillypad5);
        App.draw(life);
        App.draw(timer);
        App.draw(frogger);
        App.draw(occupied1);
        App.draw(occupied2);
        App.draw(occupied3);
        App.draw(occupied4);
        App.draw(occupied5);

        // *********************************************************************
        // The following are for testing purposes only
        // Draws the boundary box
        // *********************************************************************
        App.draw(rect);
        App.draw(rect2);
        App.draw(rect3);
        App.draw(rect4);
        App.draw(rect5);
        App.draw(rect6);
        App.draw(rect7);
        App.draw(rect8);
        App.draw(rect9);
        App.draw(rect10);
        App.draw(rect11);
        App.draw(rect12);
        App.draw(rect13);
        App.draw(rect14);
        App.draw(rect15);
        App.draw(rect16);
        App.draw(rect17);
        
        App.display();
    }
    
    //Never reaching this point normally, but just in case, exit the application
    return -1;
}
Esempio n. 8
0
 void CenterSprite(sf::Sprite& sprite, const sf::RenderTarget& target)
 {
     sf::FloatRect sprite_bounds = sprite.getLocalBounds();
     sprite.setOrigin(sprite_bounds.left + (sprite_bounds.width/2.0f), sprite_bounds.top + (sprite_bounds.height/2.0f));
     sprite.setPosition(sf::Vector2f(target.getSize() / (unsigned)2));
 }
void SpriteManager::draw(sf::Sprite sprite, float x, float y, sf::RenderWindow &window) {
    sprite.setPosition(x, y);
    window.draw(sprite);
}
Esempio n. 10
0
 void CenterSpriteHor(sf::Sprite& sprite, const sf::RenderTarget& target)
 {
     sf::FloatRect sprite_bounds = sprite.getLocalBounds();
     sprite.setOrigin(sprite_bounds.left + (sprite_bounds.width/2.f), 0);
     sprite.setPosition(target.getSize().x/2.f, sprite.getPosition().y);
 }
Esempio n. 11
0
 void CenterSpriteVert(sf::Sprite& sprite, const sf::RenderTarget& target)
 {
     sf::FloatRect sprite_bounds = sprite.getLocalBounds();
     sprite.setOrigin(0, sprite_bounds.top + (sprite_bounds.height/2.f));
     sprite.setPosition(sprite.getPosition().x, target.getSize().y/2.f);
 }
Esempio n. 12
0
StateGameMenu::StateGameMenu(State* state, unsigned int id) :
background_state(state), id(id), toggle(true)
{ menu_pointer_sprt.setPosition(208, 178); }
	void set_position(const sf::Vector2f& position)
	{
		
		m_sprite.setPosition(position);
		
	}
	void set_position()
	{
		
		m_sprite.setPosition(m_posit);
		
	}
Esempio n. 15
0
	MainMenu() : system(TextureManager::instance().getTexture("assets/rticle.png"))
	{
		pointer.setTexture(TextureManager::instance().getTexture("assets/two_pointer.png"));
		//pointer.setPosition(1183, 427);

		//system = new thor::ParticleSystem();

		emitter.setEmissionRate(0.5f);
		emitter.setParticleLifetime( sf::seconds(40) );

		emitter.setParticleRotation( thor::Distributions::uniform(0.f, 360.f) );
		emitter.setParticlePosition( sf::Vector2f(1260,740) );
		emitter.setParticleScale(sf::Vector2f(0.1,0.1));

		system.addEmitter(thor::refEmitter(emitter));

		thor::ColorGradient gradient;
		gradient[0.0f] = sf::Color::Magenta;
		gradient[0.1f] = sf::Color::Red;
		gradient[0.2f] = sf::Color::Blue;
		gradient[0.3f] = sf::Color::Cyan;
		gradient[0.4f] = sf::Color::Green;
		gradient[0.5f] = sf::Color::Red;
		gradient[0.6f] = sf::Color::Magenta;
		gradient[0.7f] = sf::Color::Cyan;
		gradient[0.8f] = sf::Color::Red;
		gradient[0.9f] = sf::Color::Blue;
		gradient[1.0f] = sf::Color::Red;

		thor::ColorAnimation colorizer(gradient);
		thor::FadeAnimation fader(0.1f, 0.1f);

		system.addAffector( thor::ScaleAffector(sf::Vector2f(0.1f,0.1)));	
		system.addAffector( thor::AnimationAffector(fader) );
		system.addAffector( thor::AnimationAffector(colorizer) );

		sprite = AnimatedSprite(sf::seconds(0.3));

		v.setTexture(TextureManager::instance().getTexture("assets/one_upper.png"));
		back2.setTexture(TextureManager::instance().getTexture("assets/two_menu.png"));
		logo.setTexture(TextureManager::instance().getTexture("assets/one_logo.png"));
		press.setTexture(TextureManager::instance().getTexture("assets/one_anybutton.png"));
		anim.setSpriteSheet(TextureManager::instance().getTexture("assets/one_animooted.jpg"));

		for (int i = 0; i < 5; i++)
		{
			anim.addFrame(sf::IntRect(0, 800 * i, WIDTH, HEIGHT));
		}

		sprite.setAnimation(anim);
		sprite.setLooped(true);
		sprite.play();

		logo.setColor(sf::Color(255,255,255,0));
		press.setColor(sf::Color(255,255,255,0));
		pointer.setColor(sf::Color(255,255,255,0));
		press.setPosition(WIDTH/2 - press.getTextureRect().width/2, HEIGHT/2 - press.getTextureRect().height/2 + 100);
		pressFading = true;

		newLogoY = 800;
		oTweener.addTween(&CDBTweener::TWEQ_BACK, CDBTweener::TWEA_INOUT, 2.f, &newLogoY, 0.0f);

		first = true;

		pressFactor = 0.2;
		transition = false;
		check = false;
		
		sm.init(sf::Vector2f(WIDTH, HEIGHT));
		rt.create(WIDTH, HEIGHT);

		MusicManager::instance().playMusicFast("low");

		selection = 1;
	};
Esempio n. 16
0
void update(sf::RectangleShape floor[], sf::RectangleShape road[], int floorWidth, int floorHeightPosition, sf::Sprite& rrSprite, double &pos, bool &jumpStatus,
     bool& isoverlap, std::stringstream &ss, sf::Clock &clock, sf::Text &textTime, sf::Music& roadrunnerMusic, sf::Music& sanicMusic, sf::Sound& squawkSound, 
     bool& deathStatus, sf::Sprite& sanicSprite, sf::Sprite& sanicPowerupSprite, bool& sanicPowerupStatus, int& globalSpeed, sf::Time& sanicTime, bool& powerupSpawnStatus, 
     sf::Time& powerupSpawnTimer, sf::Sprite arrayOfObjectSprite[], bool& boulderSpawnStatus, int numObject, int objStop, sf::Sound& jumpSound, sf::RectangleShape backgroundbox[])
{
	//game timer
     if (!isoverlap)
	{
		sf::Time time1 = clock.getElapsedTime();
		ss.str(std::string());
		ss << setprecision(2) << fixed << static_cast<double>(time1.asSeconds());
		textTime.setString(ss.str().c_str());
	}

     // Return to roadrunner character
     if (clock.getElapsedTime() >= sanicTime && sanicPowerupStatus)
     {
          sanicMusic.pause();
          roadrunnerMusic.play();
          sanicPowerupStatus = false;
     }

     // How fast everything moves
     if (sanicPowerupStatus && (clock.getElapsedTime() <= sanicTime - sf::seconds(1)))         //sanic run speed
          globalSpeed = 100;
     else
          globalSpeed = 15;                                                                    //roadrunner run speed

     // Powerup spawner, checks every 10 seconds
     if (clock.getElapsedTime() >= powerupSpawnTimer)
     {
          powerupSpawnTimer += sf::seconds(10);                       //time to spawn for every consecutive powerup after the first
          powerupSpawnStatus = true;
     }

     // Powerup spawn chance
     if (powerupSpawnStatus)
     {
          if (rand() % 100 <= 33)                                 // 33% chance to spawn
          {
               sanicPowerupSprite.setScale(0.05, 0.05);
               sanicPowerupSprite.setPosition(floorWidth, 250);
          }
          powerupSpawnStatus = false;
     }

     // Sanicpowerup movement, how fast the icon moves
     if (sanicPowerupSprite.getPosition().x >= objStop)
          sanicPowerupSprite.move(-globalSpeed, 0);

     // Roadrunner and sanicpowerup collision
     if (overlap(rrSprite, sanicPowerupSprite) && !sanicPowerupStatus)
     {
          roadrunnerMusic.pause();
          sanicMusic.play();
          sanicPowerupStatus = true;
          sanicTime = clock.getElapsedTime() + sf::seconds(10);
          sanicPowerupSprite.setScale(0, 0);
     }

     //Infinite floor/road
     floor[0].move(-globalSpeed, 0);
     floor[1].move(-globalSpeed, 0);

     road[0].move(-globalSpeed, 0);
     road[1].move(-globalSpeed, 0);
     
     if (floor[0].getPosition().x <= -floorWidth)
	{
		floor[0].setPosition(0, floorHeightPosition);
		floor[1].setPosition(floorWidth, floorHeightPosition);

          road[0].setPosition(0, floorHeightPosition);
          road[1].setPosition(floorWidth, floorHeightPosition);
	}

     //backgroundbox, movement, infinite background
     if (sanicPowerupStatus && (clock.getElapsedTime() <= sanicTime - sf::seconds(1)))
     {
          backgroundbox[0].move(-globalSpeed / 2 + 10, 0);
          backgroundbox[1].move(-globalSpeed / 2 + 10, 0);
     }
     else
     {
          backgroundbox[0].move(-globalSpeed + 10, 0);
          backgroundbox[1].move(-globalSpeed + 10, 0);
     }

     if (backgroundbox[0].getPosition().x <= -floorWidth)
     {
          backgroundbox[0].setPosition(0, -100);
          backgroundbox[1].setPosition(floorWidth, -100);
     }
     
    
	// Roadrunner jump
     if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && rrSprite.getPosition().y >= 505)
	{
		jumpStatus = true;
          jumpSound.play();
	}

	if (jumpStatus && (rrSprite.getPosition().y <= 505))
	{
		rrSprite.move(0, -15);
	}

	if (rrSprite.getPosition().y <= 100)
	{
		jumpStatus = false;
	}

	if (!jumpStatus && (rrSprite.getPosition().y < 505))
	{
		rrSprite.move(0, 15);
	}

     // Sanic jump
     if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && sanicSprite.getPosition().y >= 485)
     {
          jumpStatus = true;
     }

     if (jumpStatus && (sanicSprite.getPosition().y <= 485))
     {
          sanicSprite.move(0, -15);
     }

     if (sanicSprite.getPosition().y <= 100)
     {
          jumpStatus = false;
     }

     if (!jumpStatus && (sanicSprite.getPosition().y < 485))
     {
          sanicSprite.move(0, 15);
     }

     // Movement of objects
     for (int i = 0; i < numObject-1; i++)
     {
          if (arrayOfObjectSprite[i].getPosition().x >= objStop)
               arrayOfObjectSprite[i].move(-globalSpeed, 0);
     }

     if (arrayOfObjectSprite[6].getPosition().x >= objStop)
          arrayOfObjectSprite[6].move(-globalSpeed * 1.3, 0);             // Coyote run speed

     // First checkpoint: spawns one object
     for (int i = 0; i < numObject; i++)
     {
          if ((arrayOfObjectSprite[i].getPosition().x >= 800 && arrayOfObjectSprite[i].getPosition().x <= 1000) && boulderSpawnStatus)
          {
               boulderSpawnStatus = false;
               int reroll = true;
               int randBoulderSpawn = floorWidth + 700 + rand() % 1000;

               while (reroll)
               {
                    int randBoulder = rand() % numObject;

                    if (arrayOfObjectSprite[randBoulder].getPosition().x <= objStop)
                    {
                         if (randBoulder >= 0 && randBoulder < 2)
                              arrayOfObjectSprite[randBoulder].setPosition(randBoulderSpawn, 500);            // boulder

                         else if (randBoulder >= 2 && randBoulder < 4)
                              arrayOfObjectSprite[randBoulder].setPosition(randBoulderSpawn, 420);            // cactus

                         else if (randBoulder >= 4 && randBoulder < 6)
                              arrayOfObjectSprite[randBoulder].setPosition(randBoulderSpawn, 510);            // tumbleWeed

                         else
                              arrayOfObjectSprite[randBoulder].setPosition(randBoulderSpawn+1000, 470);       // coyote, give him a running start

                         reroll = false;
                    }
               }
          }
     }

     // Second Checkpoint: renable spawning of objects
     for (int i = 0; i < numObject; i++)
     {
          if (arrayOfObjectSprite[i].getPosition().x >= 600 && arrayOfObjectSprite[i].getPosition().x < 800)
               boulderSpawnStatus = true;
     }

     // Check collision for all objects in array
     for (int i = 0; i < numObject; i++)
     {
          if (overlap(rrSprite, arrayOfObjectSprite[i]) && !sanicPowerupStatus)
          {
               isoverlap = true;
          }
     }

     // Death conditions
     if (isoverlap && deathStatus)
     {
          roadrunnerMusic.pause();
          squawkSound.play();
          deathStatus = false;

     }
     
}
Esempio n. 17
0
void			Element::setPosSprite(sf::Sprite &sprite)
{
  sprite.setPosition((int)_posX * 16, (int)_posY * 16);
}	
// рисует заданную птицу в нужном месте в переданном окне
void draw_bird(const dtts::BirdState &_bird_state, sf::Sprite &_sprite, sf::RenderWindow &_window) {
	_sprite.setPosition(_bird_state.x - bird_radius, height - (_bird_state.y + bird_radius));
	_sprite.setTextureRect(sf::IntRect(_bird_state.right_direction ? 0 : 2 * bird_radius, 0, bird_radius * 2, bird_radius * 2));
	_window.draw(_sprite);
}
Esempio n. 19
0
	void gestionEvenement(sf::RenderWindow& _window, sf::Event& _event) {

		if (_velocity.x < 0)
			_animationPersoG.y = Left;
		else
			_animationPersoG.y = Right;
		if (mort == true) {
			_animationPersoG.y = Rip;
			_velocity.x = 0;
		}

		//Gravite
		if ((_spriteG.getPosition().y <= 385) && (MarioJumping == true)) {
			_velocity.y += gravity;

		}
		else {

			_velocity.y = 0;
			MarioJumping = false;
		}

		if (canMoveLeft == false)
			_velocity.x = speed;
		if (canMoveRight == false)
			_velocity.x = -speed;
		if ((canMoveRight == true) && (canMoveLeft == true) && (MarioJumping == false) && (mort == false)) {
			if (_velocity.x == 0)
				_velocity.x = speed;
			_velocity.x = _velocity.x;
		}


		if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
			updateFPS = false;//arrete l'animation
		}


		if (_time.getElapsedTime().asMilliseconds() >= 50) {
			_animationPersoG.x--;
			if (_animationPersoG.x * 18 >= _textureG.getSize().x)
				_animationPersoG.x = 2;
			_time.restart();
			cout << _spriteG.getPosition().x << "," << _spriteG.getPosition().y << endl;
		}

		_spriteG.setTextureRect(sf::IntRect(_animationPersoG.x * 18, _animationPersoG.y * 18, 18, 18));

		if (_spriteG.getPosition().x <= 0) {
			//empeche de sortir de l'ecran
			_spriteG.setPosition(sf::Vector2f(0, _spriteG.getPosition().y));
			_velocity.x = speed;
		}


		if (_spriteG.getPosition().y >= 385) {
			//Mario touche le sol
			_spriteG.setPosition(sf::Vector2f(_spriteG.getPosition().x, 385));
			MarioJumping = false;
			canMoveUp = false;

		}
		if (_spriteG.getPosition().x >= 2760){//empeche de sortir de l'ecran
			_spriteG.setPosition(sf::Vector2f(2760, _spriteG.getPosition().y));
			_velocity.x = -speed;
		}

	}
/**
Affiche le monstre la ou il doit etre sur la case, avec le bon angle et la bonne position
affiche également les points de vie du moob
*/
void afficheMonstre        (sf::RenderWindow &App, sf::Sprite  &SpriteMoob ,Monstre* monMoob,int cote, int offSetX, int offSetY ,  std::list<Tour*> &listTour)
{
   using namespace std;

    Case* caseMoob = monMoob->CaseCourante();

    drawHexagoneIJ ( caseMoob->getI() , caseMoob->getJ(), SpriteMoob, cote, offSetX,  offSetY);
    //sf::Shape pv   = sf::RectangleShape (0,0, 0+monMoob->getPV()/2 ,0,5,sf::Color::Black);

    sf::RectangleShape pv (sf::Vector2f(5,monMoob->getPV()/2));
    pv.setFillColor(sf::Color::Black);
    /// Moche

    drawHexagoneIJ ( caseMoob->getI() , caseMoob->getJ(), pv, cote, offSetX,  offSetY);
    // on centre le moob

    int etape;
    Direction dtion = monMoob->quelleDirection(etape);
    // on bouge en fonction de la direction
    double moobOffSetX=0,moobOffSetY=0,moobAvancement;
    if ( etape == 0)
    {
        moobAvancement = ((1000-monMoob->getAvancement())/1000)*cote*(sqrt(3));
    }
    else
    {
        moobAvancement = ((500-monMoob->getAvancement())/1000)*cote*(sqrt(3));
    }

    double angle = 0;
    switch (dtion)
    {
        case Est  : {
            moobOffSetX = moobAvancement;
            moobOffSetY =0;
            angle = -90;
            if ( etape == 0)
            {
                moobOffSetX -= (sqrt(3)/2) *cote;

            }

            break;}
        case NordEst : {
            moobOffSetX = moobAvancement / 2 ;
            moobOffSetY = -moobAvancement * (sqrt(3)/2) ;

            if ( etape == 0)
            {
                moobOffSetX -= (sqrt(3)/2) *cote /2;
                moobOffSetY += (sqrt(3)/2) *cote *(sqrt(3)/2);

            }
            angle = -30;
            break;}
        case NordOuest : {
            moobOffSetX = -moobAvancement / 2 ;
            moobOffSetY = -moobAvancement * (sqrt(3)/2) ;
            if ( etape == 0)
            {
                moobOffSetX += (sqrt(3)/2) *cote /2;
                moobOffSetY += (sqrt(3)/2) *cote *(sqrt(3)/2);

            }
            angle = 30;
            break;}
        case Ouest : {
            moobOffSetX = - moobAvancement;
            moobOffSetY = 0;
            if ( etape == 0)
            {
                moobOffSetX += (sqrt(3)/2) *cote;


            }
            angle = 90;
            break;}
        case SudOuest : {
             angle = 160;
            moobOffSetX = -moobAvancement / 2 ;
            moobOffSetY = moobAvancement * (sqrt(3)/2) ;
             if ( etape == 0)
            {
                moobOffSetX += (sqrt(3)/2) *cote /2;
                moobOffSetY -= (sqrt(3)/2) *cote *(sqrt(3)/2);

            }

            break;}
        case SudEst: {
             angle = -160;
             moobOffSetX = moobAvancement / 2 ;
            moobOffSetY = moobAvancement * (sqrt(3)/2) ;
              if ( etape == 0)
            {
                moobOffSetX -= (sqrt(3)/2) *cote /2;
                moobOffSetY -= (sqrt(3)/2) *cote *(sqrt(3)/2);

            }

            break;}
    }

    SpriteMoob.move(moobOffSetX,moobOffSetY);
   //double centreX = SpriteMoob.getSize().x/2;

   // double centreY = SpriteMoob.getSize().y/2 ;


    double centreX = SpriteMoob.getTextureRect().width /2  ;//  SpriteTower.getTexture().getSize().x/2;
    double centreY = SpriteMoob.getTextureRect().height/2 ;
    SpriteMoob.setPosition(centreX,centreY);
    SpriteMoob.rotate(angle);

    pv.  move(moobOffSetX-centreX,moobOffSetY-centreY);
    App.draw(pv);
    App.draw(SpriteMoob);

    //la gestion de l'attaque n'est pas encore definie
    if ( monMoob != NULL )
    {

        using namespace std;

        Case* laCase = monMoob->CaseCourante();

        if (laCase != NULL )
        {


            std::list<Tour*>::iterator itt = listTour.begin();

            for ( itt; itt != listTour.end() ; ++itt)
            {
                if ( (*itt)->getCible() == monMoob)
                {

                    sf::Vector2<int> ij;
                    sf::Vector2<double>xy;
                    ij.x = (*itt)->getPosition()->getI();
                    ij.y = (*itt)->getPosition()->getJ();
                    xy = IJtoXY (ij, cote, offSetX,  offSetY);
                   // sf::Shape Line   = sf::Shape::Line(SpriteMoob.GetPosition().x,SpriteMoob.GetPosition().y,xy.x,xy.y, 2, sf::Color::Red);
                   // App.Draw(Line);

                }
            }
        }
    }

}
Esempio n. 21
0
//-----------------------------------
void bomb::damage(sf::RenderWindow& window, sf::Sprite& sprFire)
{

	if (scrn.getArrayElement(calculateIndex(b),calculateIndex(l)+1) != 4)
	{
		for (int i=0; i <= dst; ++i)
		{
			if (scrn.getArrayElement(calculateIndex(b), calculateIndex(l)+i) == 2 )
			{
				if (first)
				{
					bricks.remove(brick(l+i*step, r+(i*step), b, t, scrn));
					scrn.setArrayElement(0, calculateIndex(b), calculateIndex(l)+i);
				}
				break;
			}
			if (scrn.getArrayElement(calculateIndex(b), calculateIndex(l)+i) == 3)
			{
				enemies.remove( enemy ( l + i*step, r + i*step, b, t, scrn) );
				scrn.setArrayElement(0, calculateIndex(b), calculateIndex(l) + i);
			}
			sprFire.setPosition(sf::Vector2f(l + i*step, b));
			window.draw(sprFire);
		}
	}
	if (scrn.getArrayElement(calculateIndex(b), calculateIndex(l)-1) != 4)
	{
		for (int i=0; i <= dst; ++i)
		{
			if (scrn.getArrayElement(calculateIndex(b), calculateIndex(l) - i) == 2 && first)
			{
				if(first)
				{
					bricks.remove(brick( l - i*step, r - i*step, b, t, scrn));
					scrn.setArrayElement(0, calculateIndex(b), calculateIndex(l) - i);
				}
				break;
			}
			if (scrn.getArrayElement(calculateIndex(b), calculateIndex(l) - i - 1) == 3 )
			{
				enemies.remove( enemy (l-i*step, r-i*step, b, t, scrn) );
				scrn.setArrayElement(0, calculateIndex(b), calculateIndex(l) - i - 1);
			}
			sprFire.setPosition(sf::Vector2f(l- i*step, b));
			window.draw(sprFire);
		}
	}
	if (scrn.getArrayElement(calculateIndex(b)+1, calculateIndex(l)) != 4 )
	{
		for (int i=0; i <= dst; ++i)
		{
			if (scrn.getArrayElement(calculateIndex(b)+i, calculateIndex(l)) == 2  && first)
			{
				if(first)
				{
					bricks.remove(brick(l, r, b+i*step, t+i*step, scrn));
					scrn.setArrayElement(0, calculateIndex(b)+i, calculateIndex(l));
				}
				break;
			}
			if (scrn.getArrayElement(calculateIndex(b)+i, calculateIndex(l)) == 3)
			{
				enemies.remove( enemy (l, r, b+i*step, t+i*step, scrn) );
				scrn.setArrayElement(0, calculateIndex(b)+i, calculateIndex(l));
			}
			sprFire.setPosition(sf::Vector2f(l, b+ i*step));
			window.draw(sprFire);
		}
	}
	if (scrn.getArrayElement(calculateIndex(b)-1, calculateIndex(l)) != 4)
	{
		for (int i = 0; i <= dst; i++)
		{
			if (scrn.getArrayElement(calculateIndex(b)-i, calculateIndex(l)) == 2)
			{
				if (first)
				{
					bricks.remove(brick (l, r, b-i*step, t-i*step, scrn));
					scrn.setArrayElement(0, calculateIndex(b)-i, calculateIndex(l));
				}
				break;
			}
			if (scrn.getArrayElement(calculateIndex(b)-i, calculateIndex(l)) == 3)
			{
				enemies.remove (enemy (l, r, b-i*step, t-i*step, scrn));
				scrn.setArrayElement (0, calculateIndex(b)-i, calculateIndex(l));
			}
			sprFire.setPosition(sf::Vector2f(l , b - i*step));
			window.draw(sprFire);
		}
	}
	if (first)
	{
		first = false;
	}
	return;
}
Esempio n. 22
0
void GraphicsHandler::drawSpriteAtCell(sf::Sprite &s, const int x, const int y)
{
    s.setPosition(x * cell_size, y * cell_size);
    display->draw(s);
}
Esempio n. 23
0
void character::set_position(float x, float y){
    xpos = x;
    ypos = y;
    sprite.setPosition(sf::Vector2f(xpos, ypos));
    collision_box = sprite.getGlobalBounds();
}
Esempio n. 24
0
void set_position(sf::Sprite& sprite, float line, float col)
{
    sprite.setPosition(24 * (2 + col), 24 * (3 + line));
}
Esempio n. 25
0
void Renderer::drawSprite(sf::Sprite sprite, int x, int y) {
	sprite.setPosition(x, y);
	mRenderWindow->draw(sprite);
}
void  findWay(gameMap_t * self,
              sf::RenderWindow & window,
              selection_t * cUnit,
              sf::Sprite & aCell,
              sf::Sprite & aEnemy,
              cursor_t * gCur,
              sf::Sprite & gameBackground,
              sf::Sprite & gameInterface,
              sf::Sprite & gameMenu,
              sf::Sprite & gameEndTurn,
              int player,
              sf::Sprite & cTc,
              player_t*pl,
              sf::Sprite & cBc){

    if(cUnit->status==0){
        return;
    }
    for(int i = 0;i<cellNumX;i++){
            for(int j = 0;j<cellNumY;j++){

                    int added = 0;

                    if (cUnit->cell!=NULL&&(float)sqrt((cUnit->cell->iX-i)*(cUnit->cell->iX-i)+(cUnit->cell->jY-j)*(cUnit->cell->jY-j)) <=  (float)(cUnit->cell->unit->cPoints) || (float)sqrt((cUnit->cell->iX-i)*(cUnit->cell->iX-i)+(cUnit->cell->jY-j)*(cUnit->cell->jY-j)) <=  (float)(cUnit->cell->unit->aRange)) {

                    std::string tmp;

                    int tmpSt = self->cell[i][j].obj_un_null;



                    if(self->cell[i][j].unit!=NULL && self->cell[i][j].unit->player  !=  cUnit->cell->unit->player && self->cell[i][j].obj_un_null == 1)
                        {
                            self->cell[i][j].obj_un_null = 0;
                            tmpSt = 1;
                        }


                    tmp = pathFind(cUnit->cell->iX,cUnit->cell->jY,i,j,self);

                    if(tmp!="" && calculateLength(tmp)<=cUnit->cell->unit->cPoints){



                         aCell.setPosition(self->cell[i][j].X,self->cell[i][j].Y);
                         window.draw(aCell);

                          if(gCur->status==1&&gCur->cell->iX == i &&gCur->cell->jY == j && tmp!=""&& self->cell[gCur->cell->iX][gCur->cell->jY].unit == NULL){

                                if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){

                                    cUnit->cell->unit->cPoints-=calculateLength(tmp);

                                    int tmpInt = tmp[0] - 48;

                                    cUnit->cell->unit->direction=tmpInt;

                                    int tmpX = 0, tmpY = 0;

                                    cUnit->cell->unit->direction = tmpInt;


                                    tmpX = cUnit->cell->iX;

                                    tmpY = cUnit->cell->jY;

                                    self->cell[tmpX][tmpY].obj_un_null=0;

                                   int tmpCX = cUnit->cell->X;
                                   int tmpCY = cUnit->cell->Y;


                                    for(int l = 0;l<tmp.length();l++){

                                    int tmpD = tmp[l] - 48;

                                    cUnit->cell->unit->direction = tmpD;

                                    sf::Texture tmpT;
                                    sf::Sprite tmpS;


                                    tmpT.loadFromFile(cUnit->cell->unit->sprites.path[cUnit->cell->unit->direction]);
                                    tmpS.setTexture(tmpT);

                                    for(int a = 0 ; a<10;a++){
                                            switch(tmpD){
                                        case 0:
                                            tmpCX+=10;
                                             break;
                                        case 1:
                                            tmpCX+=10;
                                            tmpCY+=10;
                                             break;
                                        case 2:
                                             tmpCY+=10;
                                             break;
                                        case 3:
                                             tmpCX-=10;
                                             tmpCY+=10;
                                             break;
                                        case 4:
                                            tmpCX-=10;
                                             break;
                                        case 5:
                                            tmpCX-=10;
                                            tmpCY-=10;
                                             break;
                                        case 6:
                                             tmpCY-=10;
                                             break;
                                        case 7:
                                             tmpCY-=10;
                                              tmpCX+=10;
                                             break;

                                           }

                                            Sleep(20);

                                            window.clear(sf::Color::Black);
                                            window.draw(gameBackground);
                                            drawUnits(self,window);
/*
                                            window.draw(gameInterface);
                                            window.draw(gameMenu);
                                            drawMinMap(window,player,self);
                                            window.draw(gameEndTurn);
                                            drawPlayer(window,player,pl);*/




                                            tmpS.setPosition(tmpCX,tmpCY);

                                            window.draw(tmpS);

                                            window.draw(gameInterface);
                                            window.draw(gameMenu);
                                            drawMinMap(window,player,self);
                                            window.draw(gameEndTurn);
                                            drawPlayer(window,player,pl);



                                            window.draw(cTc);
                                             window.draw(cBc);
                                            pData(window,cUnit);


                                            window.display();

                                    }




                                    }

                                    self->cell[gCur->cell->iX][gCur->cell->jY].unit = cUnit->cell->unit;
                                    self->cell[gCur->cell->iX][gCur->cell->jY].obj_un_null=1;
                                    added = 1;




                                    setSelect(&self->cell[gCur->cell->iX][gCur->cell->jY],cUnit);

                                    self->cell[tmpX][tmpY].unit = NULL;



                                }
                            }



                   }

                    if(tmpSt == 1 && tmp!="" && calculateLength(tmp)<=cUnit->cell->unit->aRange&&cUnit->cell->unit->cPoints>0){


                         aEnemy.setPosition(self->cell[i][j].X,self->cell[i][j].Y);
                         window.draw(aEnemy);

                         if(gCur->status==1&&gCur->cell->iX == i &&gCur->cell->jY == j&& self->cell[gCur->cell->iX][gCur->cell->jY].unit != NULL && cUnit->cell->unit->player!=self->cell[i][j].unit->player){

                                if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){

                                        if(added!=1){
                                        self->cell[i][j].obj_un_null = tmpSt;
                                        }

                                        int tmpD = tmp[0] - 48;
                                        cUnit->cell->unit->direction = tmpD;

                                            window.clear(sf::Color::Black);
                                            window.draw(gameBackground);

                                            drawUnits(self,window);


                                        sf::Texture tmpT;
                                        sf::Sprite tmpS;
                                        tmpT.loadFromFile(self->cell[i][j].unit->sprites.path[10]);
                                        tmpS.setTexture(tmpT);
                                        tmpS.setPosition(self->cell[i][j].X + rand()%50+20,self->cell[i][j].Y + rand()%50+20);
                                        window.draw(tmpS);


                                        window.draw(gameInterface);
                                            window.draw(gameMenu);
                                            drawMinMap(window,player,self);
                                            window.draw(gameEndTurn);
                                            drawPlayer(window,player,pl);
                                            pData(window,cUnit);


                                        sf::Texture tmpT1;
                                        sf::Sprite tmpS1;



                                       tmpT1.loadFromFile(self->cell[i][j].unit->sprites.path[11+cUnit->cell->unit->direction]);


                                        tmpS1.setTexture(tmpT1);
                                        tmpS1.setPosition(cUnit->cell->X,cUnit->cell->Y);


                                        window.draw(tmpS1);
                                        window.display();
                                        Sleep(400);


                                      cUnit->cell->unit->cPoints-=1;
                                      int tmpDmg = cUnit->cell->unit->dmg -  self->cell[i][j].unit->armor;
                                      if(tmpDmg<0){tmpDmg=0;}
                                      self->cell[i][j].unit->hp-=tmpDmg;


                                      if(self->cell[i][j].unit->hp<=0){

                                        sf::Texture tmpT;
                                        sf::Sprite tmpS;


                                        tmpT.loadFromFile(self->cell[i][j].unit->sprites.path[8]);
                                        tmpS.setTexture(tmpT);
                                        tmpS.setPosition(self->cell[i][j].X,self->cell[i][j].Y);



                                            window.clear(sf::Color::Black);
                                            window.draw(gameBackground);
                                            drawUnits(self,window);

                                            window.draw(gameInterface);
                                            window.draw(gameMenu);
                                            drawMinMap(window,player,self);
                                            window.draw(gameEndTurn);
                                            drawPlayer(window,player,pl);

                                            pData(window,cUnit);
                                            window.draw(cBc);
                                            window.draw(tmpS);




                                        window.display();
                                        Sleep(400);

                                        deleteUnit(self->cell[i][j].unit);
                                        self->cell[i][j].unit = NULL;
                                        self->cell[i][j].obj_un_null = 0;
                                        return;
                                      }
                               }
                         }
                   }

                   if(added!=1){

                   self->cell[i][j].obj_un_null = tmpSt;
                   }
                 }
            }
        }
}
Esempio n. 27
0
inline void ManageLevel::setToolTipPos (sf::Vector2f _temp)
{
    m_tooltip.setPosition(_temp);
}
Esempio n. 28
0
	void update(sf::Time time)
	{
		MusicManager::instance().update(time);

		system.update(time);

		sm.update();
		oTweener.step(time.asMilliseconds() / 1000.f);

		if ((int)(rand() % 90) == 3 && first) sm.setCurrentEffect("distortion", sf::seconds(0.05));
		if ((int)(rand() % 100) == 3 && !first) sm.setCurrentEffect("inversion", sf::seconds(1));

		if (first)
		{
			logo.setColor(sf::Color(255,255,255,interpolateLinear(logo.getColor().a, 255, 0.05f)));
			logo.setPosition(0, newLogoY);

			if (!pressFading)
			{
				press.setColor(sf::Color(255,255,255,interpolateLinear(press.getColor().a, 0,pressFactor)));
				if (press.getColor().a < 7)
				{
					pressFading = true;
				}
			}
			else
			{
				press.setColor(sf::Color(255,255,255,interpolateLinear(press.getColor().a, 255, pressFactor)));
				if (press.getColor().a > 243)
				{
					pressFading = false;
				}
			}

			sprite.update(time);

			if (transition && timer.getElapsedTime().asSeconds() > 0.5)
			{
				press.setColor(sf::Color(255,255,255,0));
			}

			if (transition && timer.getElapsedTime().asSeconds() > 0.5)
			{
				transition = false;
				oTweener.addTween(&CDBTweener::TWEQ_BACK, CDBTweener::TWEA_INOUT, 2.f, &newLogoY, -800.0f);
			}

			if (!transition && logo.getPosition().y <= -800 && !check)
			{
				sm.setCurrentEffect("rgb", sf::seconds(1));
				check = true;
				timer.restart();SoundManager::instance().playNoiseSound();
			}
			if (check && timer.getElapsedTime().asSeconds() > 1)
			{
				first = false;
				MusicManager::instance().playMusicFast("battle");				
				pressFading = true;
			}
		}		
		else
		{
			pressFactor = 0.2;
			if (!pressFading)
			{
				pointer.setColor(sf::Color(255,255,255,interpolateLinear(pointer.getColor().a, 0,pressFactor)));
				if (pointer.getColor().a < 7)
				{
					pressFading = true;
				}
			}
			else
			{
				pointer.setColor(sf::Color(255,255,255,interpolateLinear(pointer.getColor().a, 255, pressFactor)));
				if (pointer.getColor().a > 243)
				{
					pressFading = false;
				}
			}

			switch (selection)
			{
			case 0:
				pointer.setPosition(1183, 415);
				break;
			case 1:
				pointer.setPosition(1183, 531);
				break;
			case 2:			
				pointer.setPosition(1183, 645);
				break;
			default:
				break;
			}
		}
	};
Esempio n. 29
0
void Object::planeSetPosition(sf::Sprite &plane, sf::Vector2f position)
{
	plane.setPosition(position);
}
Esempio n. 30
0
void initialize() { //carica il gioco alla posizione iniziale
	loadTextureIntoSprite(ball, "Assets/ball.png");
	gameWindow.draw(ball);
	ball.setPosition(sf::VideoMode::getDesktopMode().width / 2, sf::VideoMode::getDesktopMode().height / 2);
	gameWindow.display();
}