예제 #1
0
//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
0
//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
0
    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
0
파일: p04.cpp 프로젝트: Boza-s6/cppcon2014
 void update()
 {
     // Before moving the paddle, we'll process player input,
     // changing the paddle's velocity.
     processPlayerInput();
     shape.move(velocity);
 }
예제 #5
0
//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;}
    }
}
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
0
	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
0
    void jump(float deltaTime)
    {

        Data date;

        speedValue-=date.gravityAcceleration*deltaTime;
        playerSprite.move(0, -speedValue);
        cout << speedValue << endl;
    }
예제 #9
0
	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;
	}
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
0
 void move()
 {
     rect.move(velocity);
 }
예제 #12
0
파일: p05.cpp 프로젝트: Boza-s6/cppcon2014
 void update()
 {
     processPlayerInput();
     shape.move(velocity);
 }