当前位置: 首页>>代码示例>>C++>>正文


C++ RectangleShape::move方法代码示例

本文整理汇总了C++中sf::RectangleShape::move方法的典型用法代码示例。如果您正苦于以下问题:C++ RectangleShape::move方法的具体用法?C++ RectangleShape::move怎么用?C++ RectangleShape::move使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sf::RectangleShape的用法示例。


在下文中一共展示了RectangleShape::move方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: key_pressed_events

//keyboard inputs (pressed)
void key_pressed_events(){
    if(event.key.code == sf::Keyboard::Left){
       square.move(x_move, 0);
       x_move -= (x_move > 0) ? x_move - 2 : 2;
       if(x_move <= -5){x_move = -5;}

       
       it = stars.begin();
       while(it != stars.end()){
            it -> move(x_move / -4, 0);
            it -> setFillColor(sf::Color(rand() % (255 + 1 - 240) + 240,
                    rand() % (255 + 1 - 240) + 240,
                    rand() % (255 + 1 - 240) + 240));
           if(it -> getPosition().x > window_x){
                it -> setPosition(0, it -> getPosition().y);}
            ++it;}
    }

    else if(event.key.code == sf::Keyboard::A){
       it = stars.begin();
       while(it != stars.end()){
            it -> move(6 / 4, 0);
            it -> setFillColor(sf::Color(rand() % (255 + 1 - 240) + 240,
                    rand() % (255 + 1 - 240) + 240,
                    rand() % (255 + 1 - 240) + 240));
           if(it -> getPosition().x > window_x){
                it -> setPosition(0, it -> getPosition().y);}
            ++it;}
    }

    else if(event.key.code == sf::Keyboard::Right){
        square.move(x_move, 0);
        x_move += 2;
        if(x_move >= 5){x_move = 5;}

       it = stars.begin();
       while(it != stars.end()){
           it -> move(x_move / -4, 0);
           it -> setFillColor(sf::Color(rand() % (255 + 1 - 240) + 240,
                rand() % (255 + 1 - 240) + 240,
                rand() % (255 + 1 - 240) + 240));
           if(it -> getPosition().x < 0){
                it -> setPosition(window_x, it -> getPosition().y);} 
           ++it;}
    }

    else if(event.key.code == sf::Keyboard::D){
       it = stars.begin();
       while(it != stars.end()){
            it -> move(6 / -4, 0);
            it -> setFillColor(sf::Color(rand() % (255 + 1 - 240) + 240,
                    rand() % (255 + 1 - 240) + 240,
                    rand() % (255 + 1 - 240) + 240));
            if(it -> getPosition().x < 0){
                it -> setPosition(window_x, it -> getPosition().y);}
            ++it;}
    }


}
开发者ID:janicelihuang,项目名称:final_land,代码行数:61,代码来源:test_night_sky.cpp

示例2: key_released_events

//keyboard inputs (release)
void key_released_events(){
   if(event.key.code == sf::Keyboard::Left){
        square.move((x_move) / 2, 0);
        x_move = 0;}

   else if(event.key.code == sf::Keyboard::Right){
        square.move(x_move / 2, 0);
        x_move = 0;}
}
开发者ID:janicelihuang,项目名称:final_land,代码行数:10,代码来源:test_night_sky.cpp

示例3: playerMove

    void playerMove(float deltaTime){

        if( sf::Keyboard::isKeyPressed( sf::Keyboard::Right ) )
        {
            playerSprite.move(200*deltaTime, 0);
        }

        if( sf::Keyboard::isKeyPressed( sf::Keyboard::Left ) )
        {
            playerSprite.move(-200*deltaTime, 0);
        }


    }
开发者ID:2Def,项目名称:JumpSimulation,代码行数:14,代码来源:jump.cpp

示例4: update

 void update()
 {
     // Before moving the paddle, we'll process player input,
     // changing the paddle's velocity.
     processPlayerInput();
     shape.move(velocity);
 }
开发者ID:Boza-s6,项目名称:cppcon2014,代码行数:7,代码来源:p04.cpp

示例5: system_events

//checks for system events
void system_events(){
    if(event.type == sf::Event::Closed){window.close();}

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

    else if(event.type == sf::Event::KeyPressed){
        if(event.key.code == sf::Keyboard::Left){
           square.move(x_move, 0);
           x_move -= (x_move > 0) ? x_move - 4 : 4;}

        else if(event.key.code == sf::Keyboard::Right){
            square.move(x_move, 0);
            x_move += 4;}
    }
}
开发者ID:janicelihuang,项目名称:final_land,代码行数:17,代码来源:test_night_sky.cpp

示例6: run

void LogicHandler::run(void){

	double deltaTime = 0;
	sf::Clock clock;
	while (window->isOpen()){
		sf::Event event;
		while (window->pollEvent(event)){
			handleEvent(event);
        }
		
		clock.restart();
		LogicHandler::update(deltaTime);

		window->clear(sf::Color(20, 180, 255));

		//render
		if(titleScreen){
			window->draw(titleScreenBg);
		}else{
			for(int i = 0; i < spriteList.size(); i++){
				window->draw(*spriteList.at(i));
			}
		}

		window->draw(shape);
		shape.move(1, 0);
		
		deltaTime = (double)clock.getElapsedTime().asMicroseconds();

		window->display();
    }
}
开发者ID:turbio,项目名称:the_incredible_florist_adventure,代码行数:32,代码来源:LogicHandler.cpp

示例7: update

	void update(sf::Time timeChange)
	{
		sf::Vector2f p1Movement(0, 0);
		sf::Vector2f p2Movement(0, 0);


		if (p1MovingUp)
			p1Movement.y -= paddleSpeed;
		if (p1MovingDown)
			p1Movement.y += paddleSpeed;
		if (p2MovingUp)
			p2Movement.y -= paddleSpeed;
		if (p2MovingDown)
			p2Movement.y += paddleSpeed;

		p1Paddle.move(p1Movement * timeChange.asSeconds());
		p2Paddle.move(p2Movement * timeChange.asSeconds());


		// Check collision
		if (ball.getPosition().y < 0 || ball.getPosition().y > 480){
			ballMovement.y *= -1;
		}
		if (ball.getGlobalBounds().intersects(p1Paddle.getGlobalBounds()) || ball.getGlobalBounds().intersects(p2Paddle.getGlobalBounds())){
			ballMovement.x *= -1;
		}



		// Scoring
		if (ball.getPosition().x > 600){
			// P1 scores
			ball.setPosition(300, 240);
			p1Score++;
			p1ScoreText.setString(std::to_string(p1Score));
		}
		else if (ball.getPosition().x < 0){
			// P2 scores
			ball.setPosition(300, 240);
			p2Score++;
			p2ScoreText.setString(std::to_string(p2Score));
		}

		ball.move(ballMovement * timeChange.asSeconds());


	}
开发者ID:minhoolee,项目名称:id-Tech-Files,代码行数:47,代码来源:Main.cpp

示例8: jump

    void jump(float deltaTime)
    {

        Data date;

        speedValue-=date.gravityAcceleration*deltaTime;
        playerSprite.move(0, -speedValue);
        cout << speedValue << endl;
    }
开发者ID:2Def,项目名称:JumpSimulation,代码行数:9,代码来源:jump.cpp

示例9: update

	void update () {
		shape.move(velocity);

		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left)
					&& left() > 0) velocity.x = -paddleVelocity;
		else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Right)
					&& right() < windowWidth) velocity.x = paddleVelocity;
		
		else 
			velocity.x = 0;
	}
开发者ID:CodeBlockers,项目名称:ZombieWasteland,代码行数:11,代码来源:modelo_main.cpp

示例10: game_update

void game_update(float elapsedTime)
{
    static float moveSpeed = 100.0f;

    color.a += 1;
    r.setFillColor(color);

    if(r.getPosition().x + r.getSize().x > g_pEngine->getScreenWidth() ||
        r.getPosition().x < 0)
    {
        moveDir *= -1;
        moveSpeed += 1;
    }

    r.move(moveSpeed * elapsedTime * moveDir, 0);
}
开发者ID:SwarmofPeanuts,项目名称:dice-roller-test-program,代码行数:16,代码来源:main.cpp

示例11: move

 void move()
 {
     rect.move(velocity);
 }
开发者ID:Knayder,项目名称:Earth-Editor,代码行数:4,代码来源:particle.cpp


注:本文中的sf::RectangleShape::move方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。