void afficheConstructible  (sf::RenderWindow &App, sf::Sprite &SpriteTower ,sf::Shape &PolygonPorte,Constructible* maCons,int cote, int offSetX, int offSetY )
{
    // affichage du sprite de la construction
    int i = maCons->getPosition()->getI();
    int j = maCons->getPosition()->getJ();


    drawHexagoneIJ ( i,j, SpriteTower, cote, offSetX,  offSetY);
    //SpriteTower.SetCenter(SpriteTower.GetSize().x/2,SpriteTower.GetSize().y/2);

    sf::Vector2f positionAvant = SpriteTower.getPosition();
    SpriteTower.setPosition(positionAvant.x-SpriteTower.getTextureRect().height,positionAvant.y-SpriteTower.getTextureRect().width);
    App.draw(SpriteTower);


    // affichage de la porté
    std::set<Case *> cibles = maCons->getCaseAPorteDEffet();
    std::set<Case *>::iterator its;
    for ( its= cibles.begin() ; its != cibles.end() ; ++its )
    {
        drawHexagoneIJ ( (*its)->getI() , (*its)->getJ(), PolygonPorte, cote, offSetX,  offSetY);
         App.draw(PolygonPorte);
    }
    // les point de vue ( mon dieu c'est moche le code graphique )
    double centreX = SpriteTower.getTextureRect().width /2  ;//  SpriteTower.getTexture().getSize().x/2;
    double centreY = SpriteTower.getTextureRect().height/2 ;
    /*sf::Shape pv   = sf::Shape::Line (0,0, 0+maCons->getPV()/2 ,0,5,sf::Color::Black);
    drawHexagoneIJ (  i,j, pv, cote, offSetX,  offSetY);
    pv.Move(0-centreX,0-centreY);
    App.draw(pv);*/

}
示例#2
0
bool Tools::CanDraw(const sf::RenderWindow &w, const sf::Sprite & s)
{
    sf::View v = w.getView();
    sf::Vector2f size = v.getSize();
    sf::Vector2f center = v.getCenter();
    sf::IntRect screen(center.x - size.x * 0.5f - 2 * TILE_SIZE, center.y - size.y * 0.5f - 2 * TILE_SIZE, size.x + 4 * TILE_SIZE, size.y + 4 * TILE_SIZE);
    return screen.contains(static_cast<sf::Vector2i>(s.getPosition()));
}
示例#3
0
void Camera::follow(sf::Sprite& sp, float d)
{
	Vector2D vd(0, d);
	vd.rotate( sp.getRotation());

	setRotation(sp.getRotation());
	setCenter( sp.getPosition() + vd);
}
示例#4
0
bool ClickTrigger(sf::Sprite &av_Sprite, sf::RenderWindow &av_Window)
{
    int mouseX = sf::Mouse::getPosition().x;
    int mouseY = sf::Mouse::getPosition().y;

    sf::Vector2i windowPosition = av_Window.getPosition();

    if(mouseX > av_Sprite.getPosition().x + windowPosition.x && mouseX < ( av_Sprite.getPosition().x + av_Sprite.getGlobalBounds().width + windowPosition.x)
        && mouseY > av_Sprite.getPosition().y + windowPosition.y + 30  && mouseY < ( av_Sprite.getPosition().y + av_Sprite.getGlobalBounds().height + windowPosition.y + 30) )
    {
        if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
        {
            return true;
        }
        return false;
    }
    return false;
}
示例#5
0
文件: main.cpp 项目: strap8/SFML-Menu
bool checkForMouseTrigger(sf::Sprite &sprite, sf::RenderWindow &window)
{
	int mouseX = sf::Mouse::getPosition().x;
	int mouseY = sf::Mouse::getPosition().y;

	sf::Vector2i windowPosition = window.getPosition();

	if (mouseX > sprite.getPosition().x + windowPosition.x && mouseX < (sprite.getPosition().x + sprite.getGlobalBounds().width + windowPosition.x)
		&& mouseY > sprite.getPosition().y + windowPosition.y + 30 && mouseY < (sprite.getPosition().y + sprite.getGlobalBounds().height + windowPosition.y + 30))
	{
		if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
		{
			return true;
		}
		return false;
	}
	return false;
}
示例#6
0
	void update(sf::RenderWindow& _window) {
		_spriteG.move(_velocity.x, _velocity.y);//Personnage qui bouge


		sf::Vector2f _positionRect = sf::Vector2f(43, 50);
		_positionRect.x = _spriteG.getPosition().x;
		_positionRect.y = _spriteG.getPosition().y;

		_rect.setPosition(_positionRect.x, _positionRect.y);
	}
示例#7
0
bool Entity::isInViewingDistance(sf::Sprite opponent) {


	sf::Vector2f position = opponent.getPosition();
	sf::FloatRect bounds = opponent.getLocalBounds();
	const sf::Rect<float> opponents_rect(position.x, position.y, 32, 32);
	return false;
	//return perimeter.intersects(opponents_rect);

}
示例#8
0
void Camara::moveLeft(sf::Sprite& personaje){
    
    if(desplazamientoCamara!=0){
        if(personaje.getPosition().x<= camara->getSize().x*0.4 + desplazamientoCamara && camara->getCenter().x!=posicionOrigenCamara){
            camara->move(-kVel,0);
            desplazamientoCamara=desplazamientoCamara-kVel;   
        }
    }
    
}
示例#9
0
	void isCollMario(Mario& _mario) {
		if (getBoundingBox().intersects(_mario.getBoundingBox())) {
			cout << "col enemie" << endl;
			if ((getBoundingBoxTop()< _mario.getBoundingBoxTop()) && (mort == false)) {
				mort = true;
			}
			else if ((_spriteG.getPosition().y > _mario.getBoundingBoxTop()) && (mort == false)) {
				cout << "Mario Rip" << endl;
			}
			else {

				if ((_spriteG.getPosition().x < _mario.getBoundingBoxLeft() - 12) && (mort == false)) {//Left

					cout << "Mario Rip" << endl;
				}
				else if ((_spriteG.getPosition().x > _mario.getBoundingBoxLeft() + 23) && (mort == false))//right
					cout << "Mario RIP" << endl;
			}
		}
	}
void cursor::LowAmmo(int current, int maximum)
{
    lowAmmoSprite.setPosition(sprite.getPosition());
    lowAmmoSprite.setRotation(sprite.getRotation());

    double ammoLimit = 0.3 * maximum;
    double ammoPseudoPercentage = static_cast <float> (current) / ammoLimit;
    ammoPseudoPercentage *= 255;

    lowAmmoSprite.setColor(sf::Color(255, 255, 255, 255 - ammoPseudoPercentage));
}
void cursor::HighAmmo(int current, int maximum)
{
    highAmmoSprite.setPosition(sprite.getPosition());
    highAmmoSprite.setRotation(sprite.getRotation());

    double pseudoAmmo = current - (0.7 * maximum);
    double pseudoAmmoMax = maximum - (0.7 * maximum);

    double ammoPseudoPercentage = static_cast <float> (pseudoAmmo) / pseudoAmmoMax;
    ammoPseudoPercentage *= 255;

    highAmmoSprite.setColor(sf::Color(255, 255, 255, ammoPseudoPercentage));
}
示例#12
0
void Bola::colidiu(sf::Sprite lightsaber){//Testar se realmente funcionou a colisao com sabre menor/maior
    if(this->getGlobalBounds().intersects((lightsaber.getGlobalBounds())))
    {
        laser2.play();
        if(this->getPosition().y<lightsaber.getPosition().y){
            speed.y *=(-1);

            float a=this->getPosition().x-(lightsaber.getPosition().x-(50*lightsaber.getScale().x));
            if(a<-10){//Lado esquerdo
                a*=-1;
                if(speed.x>0)
                    speed.x-=a*0.1;
                else
                    speed.x-=a*0.1;
            }else if(a>10){//Lado direito
                if(speed.x>0)
                    speed.x+=a*0.1;
                else
                    speed.x+=a*0.1;
            }
        }else
            speed.x*=-1;
    }
}
示例#13
0
        void handle () {
            rotate();
            float percentageHealth = float((Health/MaxHealth) * 100);
            HealthBarGreen.setSize(sf::Vector2f(percentageHealth * (HealthBarSize / percentageHealth), 5));

            NameOutline.setPosition(Sprite.getPosition().x + 1.5, Sprite.getPosition().y + nameSpacing + 4);
            PlayerName.setPosition(Sprite.getPosition().x, Sprite.getPosition().y + nameSpacing);
            HealthBarRed.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing);
            HealthBarGreen.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing);
            }
示例#14
0
void Model::update( const sf::Sprite& parent)
{
	float alfa=((parent.getRotation() + rotAround)* M_PI) /180.f;
	sf::Vector2f v,p(pos.x * parent.getScale().x, pos.y * parent.getScale().y);

	v.x = p.x * cos(alfa) - p.y * sin(alfa);
	v.y = p.x * sin(alfa) + p.y * cos(alfa);

	setRotation(parent.getRotation() + rot);
	setPosition(parent.getPosition() + v + posNoRot);

	sf::Sprite::setScale(	ModelDef::scale.x * parent.getScale().x, 
							ModelDef::scale.y * parent.getScale().y	);

	//setColor( sf::Color( clR, clG, clB, clA ) );
}
示例#15
0
Collision::OBB Collision::getOBB(const sf::Sprite& object){
	//Gets the oriented bounding box of object, which is the local bounds of the object rotated
	sf::FloatRect box(object.getLocalBounds());
	maths::Vector2 topleft, botright, topright, botleft;

	float rot = object.getRotation();
	maths::Vector2 origin = object.getOrigin();
	maths::Vector2 position = object.getPosition();
	
	//Get rotated coordinates of vertices
	topleft = position + maths::Vector2(box.left, box.top).rotate(rot, origin);
	botright = position + maths::Vector2(box.left + box.width, box.top + box.height).rotate(rot, origin);
	topright = position + maths::Vector2(box.left + box.width, box.top).rotate(rot, origin);
	botleft = position + maths::Vector2(box.left, box.top + box.height).rotate(rot, origin);


	return OBB(topleft, botleft, topright, botright);
}
示例#16
0
    EnergyMeter::EnergyMeter(const sf::Sprite &overlay, const float &maximumValue)
        : value(maximumValue)
        , maximumValue(maximumValue)
        , orientation(-1)
        , overlay(overlay)
        , primaryColor(DEFAULT_PRIMARY_COLOR)
        , secondaryColor(DEFAULT_SECONDARY_COLOR)
        , fillColor(DEFAULT_FILL_COLOR)
    {
        setVisible(true);

        foreground.setSize(
            sf::Vector2f(
                overlay.getLocalBounds().width,
                overlay.getLocalBounds().height
            )
        );

        primaryBackground.setSize(foreground.getSize());

        secondaryBackground.setSize(
            sf::Vector2f(
                2.0f,
                foreground.getSize().y
            )
        );

        setFillColor(fillColor);
        setPrimaryColor(primaryColor);
        setSecondaryColor(secondaryColor);

        setPosition(
            sf::Vector2i(
                static_cast<int>(overlay.getPosition().x),
                static_cast<int>(overlay.getPosition().y)
            )
        );

        setOrientation(VERTICAL_ORIENTATION);

        updateFill();
    }
示例#17
0
 static std::vector<sf::Sprite> split4(sf::Sprite sprite)
 {
     std::vector<sf::Sprite> splits = std::vector<sf::Sprite>(0);
     const sf::Texture* texture = sprite.getTexture();
     sf::IntRect baseRect = sprite.getTextureRect();
     sf::Vector2f position = sprite.getPosition();
     splits.push_back(sf::Sprite(*texture, sf::IntRect(baseRect.left,baseRect.top,baseRect.width/2,baseRect.height/2)));
     splits[0].setPosition(position.x,position.y);
     splits[0].setColor(sprite.getColor());
     splits.push_back(sf::Sprite(*texture, sf::IntRect(baseRect.left+(baseRect.width/2), baseRect.top, baseRect.width/2, baseRect.height/2)));
     splits[1].setPosition(position.x+baseRect.width/2,position.y);
     splits[1].setColor(sprite.getColor());
     splits.push_back(sf::Sprite(*texture, sf::IntRect(baseRect.left, baseRect.top+(baseRect.height/2), baseRect.width/2 , baseRect.height/2)));
     splits[2].setPosition(position.x,position.y+baseRect.height/2);
     splits[2].setColor(sprite.getColor());
     splits.push_back(sf::Sprite(*texture, sf::IntRect(baseRect.left+(baseRect.width/2), baseRect.top+(baseRect.height/2), baseRect.width/2 , baseRect.height/2)));
     splits[3].setPosition(position.x+baseRect.width/2,position.y+baseRect.height/2);
     splits[3].setColor(sprite.getColor());
     return splits;
 }
示例#18
0
bool DebugHud::Button(sf::RenderWindow* window, sf::Sprite buttonSprite) {

    //get width/height
    int width = buttonSprite.getTextureRect().width;
    int height =  buttonSprite.getTextureRect().height;

    float x = buttonSprite.getPosition().x ;
    float y = buttonSprite.getPosition().y ;


    //text mouse
    sf::Vector2i mousePos = sf::Mouse::getPosition(*window);
    if (mousePos.x < x) return false;
    if (mousePos.y < y) return false;
    if (mousePos.x > x + width) return false;
    if (mousePos.y > y + height) return false;

    buttonSprites[3].setPosition(x - width /4,y - height / 2);
    window->draw(buttonSprites[3]);
    return sf::Mouse::isButtonPressed(sf::Mouse::Button::Left);
}
bool CollisionFuncs::currentCollisionR(sf::Sprite& s0, sf::Sprite& s1){
	float e0Left = s0.getPosition().x;
	float e0Right = s0.getPosition().x + s0.getGlobalBounds().width;
	float e0Top = s0.getPosition().y;
	float e0Bottom = s0.getPosition().y + s0.getGlobalBounds().height;

	float e1Left = s1.getPosition().x - 1;
	float e1Right = s1.getPosition().x + s1.getGlobalBounds().width + 1;
	float e1Top = s1.getPosition().y;
	float e1Bottom = s1.getPosition().y + s1.getGlobalBounds().height ;


	// Has collided if all conditions are met
	if (e0Left <= e1Right &&
		e0Right >= e1Left &&
		e0Top <= e1Bottom &&
		e0Bottom >= e1Top) {
		return true;
	}
	else {
		return false;
	}
}
示例#20
0
	void isColl(Blocks& _block) {
		if (getBoundingBox().intersects(_block.getBoundingBox())) {
			cout << "col" << endl;
			_block.setColor(sf::Color::Red);
			if (_spriteG.getPosition().y <= _block.getBoundingBoxTop()) {//up
				canMoveUp = false;
				MarioJumping = false;
				if (_spriteG.getPosition().x - 2 < _block.getBoundingBoxLeft() - 12) {
					MarioJumping = true;
					canMoveRight = false;
				}
				else if (_spriteG.getPosition().x > _block.getBoundingBoxLeft() + 23) {
					MarioJumping = true;
					canMoveLeft = false;
				}
			}
			else if (_spriteG.getPosition().y  > _block.getBoundingBoxTop() - _block.getBoundingBoxHeight()) {
				_velocity.y = 5;
				MarioJumping = true;
			}
			else {

				if (_spriteG.getPosition().x < _block.getBoundingBoxLeft() - 12) {//Left

					canMoveLeft = false;
				}
				else if (_spriteG.getPosition().x > _block.getBoundingBoxLeft() + 23) {//right
					canMoveRight = false;
				}
			}
		}
		else {
			canMoveRight = true;
			canMoveLeft = true;
			canMoveUp = true;
			if (canMoveUp == true)
				_velocity.y += gravity;
		}
	}
示例#21
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;
}
示例#22
0
sf::Vector2f Entity::getPosition()
{
	return m_sprite.getPosition();
}
示例#23
0
bool Collision::BoundingBoxTest(const sf::Sprite& Object1, const sf::Sprite& Object2) {

    sf::Vector2f A, B, C, BL, TR;
    sf::Vector2f HalfSize1 = getSize(Object1);
    sf::Vector2f HalfSize2 = getSize(Object2);

    //For somereason the Vector2d divide by operator
    //was misbehaving
    //Doing it manually
    HalfSize1.x /= 2;
    HalfSize1.y /= 2;
    HalfSize2.x /= 2;
    HalfSize2.y /= 2;
    //Get the Angle we're working on
    float Angle = Object1.getRotation() - Object2.getRotation();
    float CosA = cos(Angle * RADIANS_PER_DEGREE);
    float SinA = sin(Angle * RADIANS_PER_DEGREE);

    float t, x, a, dx, ext1, ext2;

    //Normalise the Center of Object2 so its axis aligned an represented in
    //relation to Object 1
    C = Object2.getPosition();

    C -= Object1.getPosition();

    C = RotatePoint(C, Object2.getRotation());

    //Get the Corners
    BL = TR = C;
    BL -= HalfSize2;
    TR += HalfSize2;

    //Calculate the vertices of the rotate Rect
    A.x = -HalfSize1.y*SinA;
    B.x = A.x;
    t = HalfSize1.x*CosA;
    A.x += t;
    B.x -= t;

    A.y = HalfSize1.y*CosA;
    B.y = A.y;
    t = HalfSize1.x*SinA;
    A.y += t;
    B.y -= t;

    t = SinA * CosA;

    // verify that A is vertical min/max, B is horizontal min/max
    if (t < 0) {
        t = A.x;
        A.x = B.x;
        B.x = t;
        t = A.y;
        A.y = B.y;
        B.y = t;
    }

    // verify that B is horizontal minimum (leftest-vertex)
    if (SinA < 0) {
        B.x = -B.x;
        B.y = -B.y;
    }

    // if rr2(ma) isn't in the horizontal range of
    // colliding with rr1(r), collision is impossible
    if (B.x > TR.x || B.x > -BL.x) return false;

    // if rr1(r) is axis-aligned, vertical min/max are easy to get
    if (t == 0) {
        ext1 = A.y;
        ext2 = -ext1;
    }// else, find vertical min/max in the range [BL.x, TR.x]
    else {
        x = BL.x - A.x;
        a = TR.x - A.x;
        ext1 = A.y;
        // if the first vertical min/max isn't in (BL.x, TR.x), then
        // find the vertical min/max on BL.x or on TR.x
        if (a * x > 0) {
            dx = A.x;
            if (x < 0) {
                dx -= B.x;
                ext1 -= B.y;
                x = a;
            } else {
                dx += B.x;
                ext1 += B.y;
            }
            ext1 *= x;
            ext1 /= dx;
            ext1 += A.y;
        }

        x = BL.x + A.x;
        a = TR.x + A.x;
        ext2 = -A.y;
        // if the second vertical min/max isn't in (BL.x, TR.x), then
        // find the local vertical min/max on BL.x or on TR.x
        if (a * x > 0) {
            dx = -A.x;
            if (x < 0) {
                dx -= B.x;
                ext2 -= B.y;
                x = a;
            } else {
                dx += B.x;
                ext2 += B.y;
            }
            ext2 *= x;
            ext2 /= dx;
            ext2 -= A.y;
        }
    }

    // check whether rr2(ma) is in the vertical range of colliding with rr1(r)
    // (for the horizontal range of rr2)
    return !((ext1 < BL.y && ext2 < BL.y) ||
            (ext1 > TR.y && ext2 > TR.y));

}
示例#24
0
		float getX() { return hazardSprite.getPosition().x; }
示例#25
0
        Player () {
            PlayerNumber = totalPlayers;
            Sprite = loadSpriteData("Player " + intToString(PlayerNumber + 1));
            //Get Global width, seperate to rotation
            CharacterWidth = Sprite.getGlobalBounds().width;
            nameSpacing = 30;
            healthBarSpacing = nameSpacing + 15;

            Sprite.setOrigin(Sprite.getGlobalBounds().width/2, Sprite.getGlobalBounds().height/2);
            Sprite.setPosition((App.getSize().x/2) - (Sprite.getGlobalBounds().width/2), (App.getSize().y/2) - (Sprite.getGlobalBounds().height/2));

            //PlayerName.setFont(sf::Font::getDefaultFont());
            PlayerName.setCharacterSize(15);
            PlayerName.setString("Player: " + intToString(PlayerNumber + 1));
            PlayerName.setOrigin(PlayerName.getGlobalBounds().width/2, PlayerName.getGlobalBounds().height/2);
            PlayerName.setPosition(Sprite.getPosition().x, Sprite.getPosition().y + nameSpacing);

            NameOutline.setSize(sf::Vector2f(PlayerName.getGlobalBounds().width, PlayerName.getGlobalBounds().height));
            NameOutline.setOutlineThickness(2);
            NameOutline.setFillColor(sf::Color(0, 0, 0, 120));
            NameOutline.setOutlineColor(sf::Color::Black);
            NameOutline.setOrigin(NameOutline.getGlobalBounds().width/2, NameOutline.getGlobalBounds().height/2);
            NameOutline.setPosition(Sprite.getPosition().x + 1.5, Sprite.getPosition().y + nameSpacing + 4);

            MaxHealth = Health = 100;
            HealthBarSize = 50;

            HealthBarRed.setSize(sf::Vector2f(HealthBarSize, 5));
            HealthBarRed.setOutlineThickness(1);
            HealthBarRed.setFillColor(sf::Color::Red);
            HealthBarRed.setOutlineColor(sf::Color::Black);
            HealthBarRed.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing);

            HealthBarGreen.setSize(sf::Vector2f(HealthBarSize, 5));
            HealthBarGreen.setOutlineThickness(1);
            HealthBarGreen.setFillColor(sf::Color::Green);
            HealthBarGreen.setOutlineColor(sf::Color::Black);
            HealthBarGreen.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing);

            if (controllerConnected) {
                ControlScheme = ControlSchemes::Joystick;
                Key k;
                k.InputType = Input::JoystickMovedNeg;
                k.KeyCode = sf::Joystick::Axis::Y;
                Bindings["Up"] = k;

                k.InputType = Input::JoystickMovedPos;
                k.KeyCode = sf::Joystick::Axis::Y;
                Bindings["Down"] = k;

                k.InputType = Input::JoystickMovedNeg;
                k.KeyCode = sf::Joystick::Axis::X;
                Bindings["Left"] = k;

                k.InputType = Input::JoystickMovedPos;
                k.KeyCode = sf::Joystick::Axis::X;
                Bindings["Right"] = k;
                } else {
                    ControlScheme = ControlSchemes::KeyboardMouse;
                    Key k;
                    k.InputType = Input::KeyboardInput;
                    k.KeyCode = sf::Keyboard::W;
                    Bindings["Up"] = k;

                    k.InputType = Input::KeyboardInput;
                    k.KeyCode = sf::Keyboard::S;
                    Bindings["Down"] = k;

                    k.InputType = Input::KeyboardInput;
                    k.KeyCode = sf::Keyboard::A;
                    Bindings["Left"] = k;

                    k.InputType = Input::KeyboardInput;
                    k.KeyCode = sf::Keyboard::D;
                    Bindings["Right"] = k;
                    }

            totalPlayers++;
            }
示例#26
0
inline sf::Vector2f ManageLevel::getToolTipPos() const
{
    return m_tooltip.getPosition();
}
int screen_1::Run(sf::RenderWindow &App)
{
	sf::Event Event;

	bool Running = true;

	while (Running)
	{
		//Verifying events
		while (App.pollEvent(Event))
		{
			// Window closed
			if (Event.type == sf::Event::Closed)
			{
				return (-1);
			}
			//Key pressed
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
			{
				sf::Vector2f pos = frogger.getPosition();

				if (pos.x <= 15 || (pos.x <= 15 && pos.y <= 675))
				{
					frogger.move(0, 0);
				}// end if
				else
				{
					if (rectSourceSprite.left != 216)
					{
						rectSourceSprite.left = 216;
						rectSourceSprite.width = 55;
						frogger.setTextureRect(rectSourceSprite);
					}// end if

					frogger.move(-50, 0);

				}// end else
			}// end if
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
			{
				sf::Vector2f pos = frogger.getPosition();

				if (pos.x >= 690)
				{
					frogger.move(0, 0);
				}// end if
				else
				{
					if (rectSourceSprite.left != 89)
					{
						rectSourceSprite.left = 89;
						rectSourceSprite.width = 60;
						frogger.setTextureRect(rectSourceSprite);
					}// end if

					frogger.move(50, 0);

				}// end else
			}// end if
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
			{
				sf::Vector2f pos = frogger.getPosition();

				if (pos.y <= -35)
				{
					frogger.move(0, 0);
				}// end if
				else
				{
					if (rectSourceSprite.left != 0)
					{
						rectSourceSprite.left = 0;
						rectSourceSprite.width = 89;
						frogger.setTextureRect(rectSourceSprite);
					}// end if

					frogger.move(0, -50);
				}
			}// end if
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
			{
				sf::Vector2f pos = frogger.getPosition();

				if (pos.y >= 540)
				{
					frogger.move(0, 0);
				}// end if
				else
				{
					if (rectSourceSprite.left != 149)
					{
						rectSourceSprite.left = 149;
						rectSourceSprite.width = 67;
						frogger.setTextureRect(rectSourceSprite);
					}// end if

					frogger.move(0, 50);

				}// end else
			}// end if
		}

		// Creating the objects
		Object t1(130, 420, 0.5);
		Object t2(550, 290, 0.3);
		Object c1(-50, 420, 0.5);
		Object c2(280, 289, 0.3);
		Object c3(0, 289, 0.3);
		Object sl1(0, 125, 0.2);
		Object sl2(200, 61, 0.3);
		Object sl3(300, 8, 0.4);
		Object l1(799, 8.3, 0.4);
		Object l2(500, 125, 0.2);

		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);

		//Clearing screen
		App.clear(sf::Color(0, 0, 0, 0));

		//Drawing
		App.draw(background);
		App.draw(truck);
		App.draw(truck2);
		App.draw(car);
		App.draw(car2);
		App.draw(car3);
		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(frogger);
		App.display();
	}

	//Never reaching this point normally, but just in case, exit the application
	return -1;
}
示例#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;
			}
		}
	};
示例#29
0
	void input(sf::Event &event)
	{
		if (first && logo.getPosition().y == 0 && (event.type == sf::Event::KeyPressed || event.type == sf::Event::JoystickButtonPressed))
		{
			SoundManager::instance().playPressSound();
			pressFactor = 0.64;
			transition = true;
			timer.restart();
		}

		if (!first)
		{
			if ((event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::X|| event.type == sf::Event::JoystickButtonPressed && xb::Joystick::isButtonPressed(0, xb::Joystick::A)))
			{
				switch (selection)
				{
				case 0:
					if( _access( "save.dat", 0 ) != -1 )
					{
						isMenu = false;
						Parser::instance().loadGame();

						GameData::instance().getThunder().clearOffset();
						GameData::instance().getPlayer().clearOffset();
						GameData::instance().getEmber().clearOffset();

						SceneManager::instance().startTransition(Parser::instance().getSceneInfo(Level::instance().getDay(), Level::instance().getScene()));

						if (Level::instance().getDay() == 6 && Level::instance().getScene() == 7) SceneManager::instance().getScene().setBattleState();
						if (Level::instance().getDay() == 6 && Level::instance().getScene() == 8) SceneManager::instance().getScene().setBattleState();
					}
					else
					{
						SoundManager::instance().playFailSound();
					}
					
					break;
				case 1:
					isMenu = false;
					remove("save.dat");
					Level::instance().setDay(1); 
					Level::instance().setScene(1);

					GameData::instance().addMana();
					GameData::instance().addMana();
					GameData::instance().addMana();

					GameData::instance().addMed();
					GameData::instance().addMed();
					GameData::instance().addMed();
					GameData::instance().addMed();
					GameData::instance().addMed();

					GameData::instance().addShard();

					GameData::instance().addMoney(2000);

					SceneManager::instance().setScene(Parser::instance().getSceneInfo(Level::instance().getDay(), Level::instance().getScene()));
					break;
				case 2:
					running = false;
					break;
				default:
					break;
				}
			}
			
			if(((event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Up) || (xb::Joystick::getAxisDir() == DIR_UP && event.type == sf::Event::JoystickMoved)))
			{
				if (selection > 0)
				{
					selection--;
				}
				else
				{
					selection = 2;
				}

				SoundManager::instance().playSelectSound();
			}
			if(((event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Down) || (xb::Joystick::getAxisDir() == DIR_DOWN && event.type == sf::Event::JoystickMoved)))
			{
				if (selection < 2)
				{
					selection++;
				}
				else
				{
					selection = 0;
				}

				SoundManager::instance().playSelectSound();
			}
		}
	};
示例#30
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;
		}

	}