本文整理汇总了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;}
}
}
示例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;}
}
示例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);
}
}
示例4: update
void update()
{
// Before moving the paddle, we'll process player input,
// changing the paddle's velocity.
processPlayerInput();
shape.move(velocity);
}
示例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;}
}
}
示例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();
}
}
示例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());
}
示例8: jump
void jump(float deltaTime)
{
Data date;
speedValue-=date.gravityAcceleration*deltaTime;
playerSprite.move(0, -speedValue);
cout << speedValue << endl;
}
示例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;
}
示例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);
}
示例11: move
void move()
{
rect.move(velocity);
}