예제 #1
0
	void Update(float fTime)
	{
		FRect.left += dx * fTime;

		// x
		Collision(0);

		if (!bOnGround)
			dy = dy + 0.0005f * fTime;

		FRect.top += dy * fTime;

		bOnGround = false;

		// y
		Collision(1);

		fCurrentFrame += 0.005f * fTime;
		if (fCurrentFrame > 3)
			fCurrentFrame -= 3;

		if(dx > 0)
			SSprite.setTextureRect(sf::IntRect(112 + 30 * int(fCurrentFrame), 144, 16, 16));
		if(dx < 0)
			SSprite.setTextureRect(sf::IntRect(112 + 30 * int(fCurrentFrame) + 16, 144, -16, 16));

		SSprite.setPosition(FRect.left - g_fOffsetX, FRect.top - g_fOffsetY);

		dx = 0;
	}
예제 #2
0
	//Enemy sprite render.
	void update(float deltaTime, char** levelMap, struct config* config) {

		if(mDirection == 0) {mMovement.x = 0;		mMovement.y = -mSpeed;}
		if(mDirection == 1) {mMovement.x = mSpeed;	mMovement.y = 0;}
		if(mDirection == 2) {mMovement.x = 0;		mMovement.y = mSpeed;}
		if(mDirection == 3) {mMovement.x = mSpeed;	mMovement.y = 0;}

		mRect.left += mMovement.x * deltaTime;
		collision(levelMap, config);
		mRect.top += mMovement.y * deltaTime;
		collision(levelMap, config);

		//Enemy animation.
		mCurrentFrame += mAnimationSpeed * deltaTime;
		if(mCurrentFrame > mFrameCount) mCurrentFrame -= mFrameCount;

		if(mMovement.x > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 925, mRect.width, mRect.height));
		if(mMovement.x < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 667, mRect.width, mRect.height));
		if(mMovement.y > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 535, mRect.width, mRect.height));
		if(mMovement.y < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 787, mRect.width, mRect.height));

		mSprite.setPosition(mRect.left - offsetX, mRect.top - offsetY);
		mTextName.setPosition(mRect.left - offsetX, mRect.top - mTextName.getCharacterSize() - offsetY);

	}
예제 #3
0
	//Player constructor.
	Player(sf::Texture& texture, sf::Texture& hpImage, int x, int y, sf::Font& font) {

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

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

		mCurrentFrame = 0;
		mAnimationSpeed = 0.005;

		mIsAlive = true;
		mHP = 100;
		mMaxHp = 100;
		mMP = 100;
	}
예제 #4
0
파일: main.cpp 프로젝트: couchjd/playground
void Player::moveLeft(int moveSpeed){
  facing = left;
  xPos -= moveSpeed;
  if((xPos/10)%2 == 0)
    playerSprite.setTextureRect(sf::IntRect(99, 0, 27, 40));
  else
    playerSprite.setTextureRect(sf::IntRect(339, 0, 27, 40));
  playerSprite.setPosition(xPos, yPos);
}
예제 #5
0
파일: main.cpp 프로젝트: couchjd/playground
void Player::moveRight(int moveSpeed){
  facing = right;
  xPos += moveSpeed;
  if((xPos/10)%2 == 0)
    playerSprite.setTextureRect(sf::IntRect(659, 0, 27, 40));
  else
    playerSprite.setTextureRect(sf::IntRect(421, 0, 27, 40));
  playerSprite.setPosition(xPos, yPos);
}
예제 #6
0
	void Update(float fTime)
	{
		FRect.left += dx * fTime;

		Collision();

		fCurrentFrame += fTime * 0.005f;
		if (fCurrentFrame > 2)
			fCurrentFrame -= 2;

		SSprite.setTextureRect(sf::IntRect(18 * int(fCurrentFrame), 0, 16, 16));	

		if (!bLife)
			SSprite.setTextureRect(sf::IntRect(58, 0, 16, 16));

		SSprite.setPosition(FRect.left - g_fOffsetX, FRect.top - g_fOffsetY);
	}
예제 #7
0
	//Drop item constructor.
	DropItem(sf::Texture& texture, std::string type, int effect, int x, int y) {
		mSprite.setTexture(texture);
		mRect = sf::FloatRect(x, y, 32, 32);
		mSprite.setTextureRect(sf::IntRect(0, 0, 32, 32));
		mCurrentFrame = 0;
		mEffectValue = effect;
		mIsMarkedForRemoval = false;
	}
예제 #8
0
	//Player sprite render.
	void update(float deltaTime, char** levelMap, struct config* config) {

		//Player controls (testing).
		if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))	mMovement.y -= mSpeed;
		if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))	mMovement.y += mSpeed;
		if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))	mMovement.x -= mSpeed;
		if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))	mMovement.x += mSpeed;

		mRect.left += mMovement.x * deltaTime;
		collision(0, levelMap, config);

		mRect.top += mMovement.y * deltaTime;
		collision(1, levelMap, config);

		//Player animation.
		mCurrentFrame += mAnimationSpeed * deltaTime;
		if(mCurrentFrame > mFrameCount) mCurrentFrame -= mFrameCount;

		if(mMovement.x > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 925, mRect.width, mRect.height));
		if(mMovement.x < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 667, mRect.width, mRect.height));
		if(mMovement.y > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 535, mRect.width, mRect.height));
		if(mMovement.y < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 787, mRect.width, mRect.height));

		mSprite.setPosition(mRect.left - offsetX, mRect.top - offsetY);

		//HP.
		if(mHP / mMaxHp >= 0.6)
			mHpSprite.setColor(sf::Color::Green);
		else if((mHP / mMaxHp >= 0.35) && (mHP / mMaxHp < 0.6))
			mHpSprite.setColor(sf::Color::Yellow);
		else if(mHP / mMaxHp < 0.35)
			mHpSprite.setColor(sf::Color::Red);

		mHpSprite.setTextureRect(sf::IntRect(100 * (1 - mHP / mMaxHp), 0, 100, 10));
		mHpSprite.setPosition(mRect.left - offsetX, mRect.top + mRect.height - offsetY);
		mTextName.setPosition(mRect.left - offsetX, mRect.top - mTextName.getCharacterSize() - offsetY);						//-

		//Camera scrolling.
		if(mRect.left > config->screenWidth / 2 - mRect.width / 2)	offsetX = mRect.left - (config->screenWidth / 2 - mRect.width / 2);
		if(mRect.top > config->screenHeight / 2 - mRect.height / 2)	offsetY = mRect.top - (config->screenHeight / 2 - mRect.height / 2);

		//Stopping the player.
		mMovement.x = 0;
		mMovement.y = 0;

	}
예제 #9
0
파일: Player.cpp 프로젝트: Sartek/Teknix
// The flip function works well TODO MOVE THIS SHIT
void Player::Flip(sf::Sprite& sprite)
{
    if (Player::Direction==-1)
    {
        sprite.setTextureRect(
            sf::IntRect(
                sprite.getTextureRect().width, //TODO left+width?
                0,
                -sprite.getTextureRect().width,
                sprite.getTextureRect().height
            )
        );
    }
    else
    {
        sprite.setTextureRect(Player::TextureRect);
    }
}
예제 #10
0
void Animation::get_sprite(int frame, sf::Sprite& sprite) const
{
    if ( d->tileset )
    {
        d->tileset->get_tile(d->start_tile+frame,sprite);
        sf::IntRect ir = sprite.getTextureRect();
        ir.left += d->offset.x;
        ir.top += d->offset.y;
        sprite.setTextureRect(ir);
    }
}
예제 #11
0
void TextureManager::setTexture(sf::Sprite& sprite, string name, unsigned int spriteIndex)
{
    TextureData& data = textureMap[name];
    if (data.texture.getSize().x < 1)
        loadTexture(name, sf::Vector2i(0, 0));
    
    if (spriteIndex < data.sprites.size())
    {
        sprite.setTexture(data.texture);
        sprite.setTextureRect(data.sprites[spriteIndex]);
        sprite.setOrigin(float(data.sprites[spriteIndex].width) / 2, float(data.sprites[spriteIndex].height) / 2);
    }else{
        sprite.setTexture(data.texture, true);
        sprite.setOrigin(data.texture.getSize().x / 2, data.texture.getSize().y / 2);
    }
}
예제 #12
0
// update fucntion for animated sprite class
// pass in float that stores the time since last frame
void GHAnimatedSprite::Update(float timeSinceLastFrame) 
{
	// count the time change
	timeSinceLastChange += timeSinceLastFrame;
	if (timeSinceLastChange >= 0.25f) 
	{
		// reset the timer
		timeSinceLastChange = 0.0f;

		//increment the frame counter
		if (currentFrame >= 3) 
		{
			currentFrame = 0;
		}
		else 
		{
			currentFrame++;
		}

		//change the section of the texture
		sprite.setTextureRect(sf::IntRect(64 * currentFrame, 0, 64, 64));
	}
}
예제 #13
0
	//Enemy constructor.
	Enemy(sf::Texture& texture, int x, int y, sf::Font& font) {
		mSprite.setTexture(texture);
		mRect = sf::FloatRect(x, y, 120, 110);					//Character x, y, width, height.

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

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

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

		mCurrentFrame = 0;
		mAnimationSpeed = mSpeed * 0.05;

		mIsAlive = true;
		mHP = 100;

		mDamage = 30;
	}
예제 #14
0
	Enemy (sf::Texture & tileset) :velX(2), velY(0)
	{
		sprite.setTexture(tileset);
    sprite.setTextureRect(sf::IntRect(153,58,11,10));
	}
예제 #15
0
파일: hud.hpp 프로젝트: K0teu/Squares-War
        void rysuj_hud( sf::RenderWindow & okno )
        {
            if( bonusik->zwroc_timer() > 0 )
                alphaPaskaBonusu = 1;
//               else
//               if( bonusik->zwroc_timer() == 0 )
//                   alphaPaskaBonusu = 0;

            if( bonusik->zwroc_timer() == 0 ){
                if( alphaPaskaBonusu > 0 )
                    alphaPaskaBonusu -= 0.01;
            }
            spr_paskaBonusu.setColor( sf::Color( 255, 255, 255, 255*alphaPaskaBonusu));
            /// GDY HP DOJDZIE DO STANU KRYTYCZNEGO, ZAMIEN NA CZERWONY KOLOR
//            if( gracz->zwroc_hp() < 20 )
//                spr_paskaHp.setColor( sf::Color( 255, 255, 255, 255 ) );
//            else
//                spr_paskaHp.setColor( sf::Color( 255, 255, 255, 255 ) );
//            gracz->ustaw_hp( 10 );
            for( int i = 0 ; i < 2 ; i++ )
            {
                spr_paskaHp.setTexture( tex_paskaHp[ i ] );
                spr_paskaBonusu.setTexture( tex_paskaBonusu[ i ] );
//                spr_paskaBonusu.setScale( 1.5, 1 );
                if( i == 0 )
                {
                    spr_paskaHp.setTextureRect( sf::IntRect( 0, 0, 153, 18 ) );
                    spr_paskaBonusu.setTextureRect( sf::IntRect( 0, 0, 578, 31 ) );
                }
                else
                {
                    spr_paskaHp.setTextureRect( sf::IntRect( 0, 0,
                            (gracz->zwroc_hp()/gracz->zwroc_maxHP())*153, 18 ) );
                    spr_paskaBonusu.setTextureRect( sf::IntRect( 0, 0,
                            (bonusik->zwroc_timer() / bonusik->zwroc_maxTimer() )*578, 31 ) );
                }

                okno.draw( spr_paskaHp );
                if( alphaPaskaBonusu > 0 )
                {
                    okno.draw( spr_paskaBonusu );
                }
            }
            rysuj_tekst( okno, "Poziom: ", ::lvl, 170, 5 );
//            rysuj_tekst( okno, "Score: ", ::score );
            rysuj_tekst( okno, L"Pozostało: ", ::potrzeba_zabitych - ::ilosc_zabitych, 520, 110 );
            /// rysuj jaki lvl
            /// rysuj ile punktow
            /// rysuj jaki bonus
            if( bonusik->x != -500 && bonusik->typ == -1 )
                rysuj_tekst( okno,
                L"Szybko, bonus jest na mapie\n\tmusisz go znaleźć!", 200, 100 );
            if( bonusik->zwroc_timer() > 0 )
                rysuj_tekst( okno, "Czas bonusu: ", bonusik->zwroc_timer() + 1, 285, 410 );

            if( bonusik->typ != -1 )
            {
                ustaw_timer( 1, 2 );
                typ_bonusu = bonusik->typ;
            }
            if( zwroc_timer( 1 ) != 0 )
            {
                switch( typ_bonusu )
                {
                    case bonus_dmgUp:
                        rysuj_tekst( okno, L"Wylosowałes bonus: Zwiększenie ataku!", 200, 100 );
                        break;
                    case bonus_hpUp:
                        rysuj_tekst( okno, L"Wylosowałes bonus: Całkowite wyleczenie!", 200, 100 );
                        break;
                    case bonus_spdUp:
                        rysuj_tekst( okno, L"Wylosowałes bonus: Przyśpieszenie!", 200, 100 );
                        break;
                    case bonus_hpDown:
                        rysuj_tekst( okno, L"Co, ale że co?! HP ci spadło !", 200, 100 );
                        break;
                    case bonus_spdDown:
                        rysuj_tekst( okno, L"Chodzisz powooooli jak zółw...", 200, 100 );
                        break;
                    case bonus_immune:
                        rysuj_tekst( okno, L"Muahahaha! Nieśmiertelny! (czasowo ^^)", 200, 100 );
                        break;
                    case 6:
                        rysuj_tekst( okno, L"Nięęęęęę", 300, 10 );
                        break;
                    case -1: break;
                    default:
                        rysuj_tekst( okno, L"Nięę", 300, 10 );
                        break;
                }
            }
        }
예제 #16
0
void Animation::applyTo(sf::Sprite& sprite, const int index) {
	if (index != -1)
		frameAt = index;
	sprite.setTextureRect(frames[frameAt]);
}
예제 #17
0
void Animation::lunchAnimation(sf::Sprite &sprite,int x,int y, int tailleX,int tailleY)
{
    sprite.setTextureRect(sf::IntRect(x,y,tailleX,tailleY));


}
예제 #18
0
파일: Tile.hpp 프로젝트: Cadaeiz/Breakout
	void setTexture(sf::Texture & texture) { sprite.setTexture(texture); sprite.setTextureRect(sf::IntRect((type/2)*80,(type%2)*40,80,40)); }
예제 #19
0
void Graphics::BlitSurface(sf::Sprite& sprite, sf::IntRect sourceRect)
{
	sprite.setTextureRect(sourceRect);
	window.draw(sprite);
}
예제 #20
0
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;
}
// рисует заданную птицу в нужном месте в переданном окне
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);
}
예제 #22
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;
}
예제 #23
0
파일: Goomba.hpp 프로젝트: W0Z4/ProjetMario
	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;
		}

	}
예제 #24
0
파일: main.cpp 프로젝트: couchjd/playground
void Player::idle(){
  if(facing == right)
    playerSprite.setTextureRect(sf::IntRect(421, 0, 27, 40));
  else
    playerSprite.setTextureRect(sf::IntRect(339, 0, 27, 40));
}