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


C++ Paddle类代码示例

本文整理汇总了C++中Paddle的典型用法代码示例。如果您正苦于以下问题:C++ Paddle类的具体用法?C++ Paddle怎么用?C++ Paddle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: display

/* Callback handler for window re-paint event */
void display() {
    glClear(GL_COLOR_BUFFER_BIT);  // Clear the color buffer
    glMatrixMode(GL_MODELVIEW);    // To operate on the model-view matrix
    glLoadIdentity();              // Reset model-view matrix
    paddleRight.move();
    ball.draw();
    paddleRight.draw();
    paddleLeft.draw();

    glutSwapBuffers();  // Swap front and back buffers (of double buffered mode)

    // Animation Control - compute the location for the next refresh
    ball.contactLeft(paddleLeft);
    ball.contactRight(paddleRight);
    ball.move();
    ai.AIPaddleMove(ball);
    //ai2.AIPaddleMove(ball);
    if (ball.didRoundEnd() == 'R') {
        ++scoreRight;
        ball.resetBallPos();
    }
    else if (ball.didRoundEnd() == 'L') {
        ++scoreLeft;
        ball.resetBallPos();
    }
    else
        return;


}
开发者ID:harman666666,项目名称:PONG,代码行数:31,代码来源:MAIN.cpp

示例2: onPaddleHit

void PowerUp::onPaddleHit(Paddle& paddle)
{
    switch (m_type)
    {
        case SMALL_PADDLE:
            paddle.shrink();
            break;
        case LARGE_PADDLE:
            paddle.grow();
            break;
        case STICKY_PADDLE:
            paddle.activeSticky();
            break;
        case LASER_PADDLE:
            paddle.activeLaser();
            break;
        case TRIPLE_BALL:
            getManager()->createBall();
            getManager()->createBall();
            break;
        case POWER_BALL:
            getManager()->applyOnEachBall(&Ball::enablePowerBall);
            break;
        case EXTRA_LIFE:
            getManager()->addPlayerLife();
            break;
        case SPEED_RESET:
            getManager()->applyOnEachBall(&Ball::resetSpeed);
            break;
    }
    kill();
    SoundSystem::playSound("power-up.ogg");
}
开发者ID:abodelot,项目名称:wallbreaker,代码行数:33,代码来源:PowerUp.cpp

示例3: isCollided

bool Ball::isCollided(Paddle &paddle) {
    
    const sf::Vector2f polarPos = toPolar(getPosition() - Settings::getScreenCenter());
    const float ballRad = ((sf::CircleShape*)shape)->getRadius();
    
    const float closeRad = 0.01 * Settings::getZoneRadius();
    if ((polarPos.x + ballRad) > (paddle.getRadius() - closeRad)) {
        const float ballRadAngle = toPolar(sf::Vector2f(-ballRad, polarPos.x)).y;
        const float closeAngle = 1.0;
        const float paddleCenter = paddle.getCenterAngle();
        
        if ( ((polarPos.y + ballRadAngle) > (paddleCenter - paddle.getAngularLength() - closeAngle)) &&
            ((polarPos.y - ballRadAngle) < (paddleCenter + paddle.getAngularLength() + closeAngle)) ) {
            
            // ball is close to paddle, so bother to do checks
            
            const int NUM_POINTS = ((sf::CircleShape*)shape)->getPointCount();
            for (int i = 0; i<NUM_POINTS; i++) {
                // check for every point on the circle shape, in global coords
                sf::Vector2f localPoint = ((sf::CircleShape*)shape)->getPoint(i);
                sf::Transform transform = shape->getTransform();
                sf::Vector2f globalPoint = transform.transformPoint(localPoint);
                
                if (paddle.isWithin(globalPoint)) {
                    return true;
                }
            }
        }
        
    }
    return false;
}
开发者ID:gozzle,项目名称:polarPong,代码行数:32,代码来源:Ball.cpp

示例4: run

    // Il metodo `run` farà partire il game loop.
    void run()
    {
        while(true)
        {
            window.clear(sf::Color::Black);

            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) break;

            // Il tasto `P` gestirà la pausa.
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::P))
            {
                // Prima di mettere/togliere la pausa, controlliamo
                // se il tasto era già stato pressato.
                if(!pausePressedLastFrame)
                {
                    if(state == State::Paused)
                        state = State::InProgress;
                    else if(state == State::InProgress)
                        state = State::Paused;
                }

                pausePressedLastFrame = true;
            }
            else
                pausePressedLastFrame = false;

            // Il tasto `R` farà ricominciare il gioco.
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::R)) restart();

            // Se il gioco è in pausa, non aggiorneremo i game
            // object.
            if(state != State::Paused)
            {
                ball.update();
                paddle.update();
                for(auto& brick : bricks)
                {
                    brick.update();
                    solveBrickBallCollision(brick, ball);
                }

                bricks.erase(
                    std::remove_if(std::begin(bricks), std::end(bricks),
                        [](const auto& mBrick)
                        {
                            return mBrick.destroyed;
                        }),
                    std::end(bricks));

                solvePaddleBallCollision(paddle, ball);
            }

            ball.draw(window);
            paddle.draw(window);
            for(auto& brick : bricks) brick.draw(window);

            window.display();
        }
    }
开发者ID:SuperV1234,项目名称:itcpp2015,代码行数:60,代码来源:p09.cpp

示例5: Paddle

Paddle* Paddle::paddleWithTexture(CCTexture2D* aTexture)
{
	Paddle* pPaddle = new Paddle();
	pPaddle->initWithTexture( aTexture );
	pPaddle->autorelease();

	return pPaddle;
}
开发者ID:charlesa101,项目名称:cocos2d-x,代码行数:8,代码来源:Paddle.cpp

示例6: collisionWithPaddle

bool Power::collisionWithPaddle(Paddle& paddle, Ball &ball, Bricks &bricks)
{
	if(ball.gameStatus== CONTINUE)
	{	
		if(position[1]- width/2<= paddle.position[1]+ paddle.width/2)
		{
			if(position[0]+ length/2>= paddle.position[0]- paddle.length/2 && position[0]- length/2<= paddle.position[0]+ paddle.length/2)
			{
				if(type== EXPAND)
				{
					
					engine1->play2D("media/powerGood.wav");
					paddle.enlarge();
					return true;
				}

				else if(type== SHORTEN)
				{engine1->play2D("media/powerBad.wav");
					paddle.shorten();
					return true;
				}

				else if(type== GLUE)
				{engine1->play2D("media/powerGood.wav");
					ball.isGlue= 1;
					return true;
				}

				else if(type== SHOOT)
				{engine1->play2D("media/powerGood.wav");
					paddle.shoot= 1;
					return true;
				}

				else if(type== UNGLUE)
				{engine1->play2D("media/powerBad.wav");
					ball.isGlue= 0;
					return true;
				}

				else if(type== NOSHOOT)
				{engine1->play2D("media/powerBad.wav");
					paddle.shoot= 0;
					return true;
				}

				else if(type== ONEUP)
				{engine1->play2D("media/powerGood.wav");
					ball.lives++;
					return true;
				}
			}
		}
	}
	return false;
}
开发者ID:crg91,项目名称:demoBricks,代码行数:56,代码来源:Power.cpp

示例7: updateLeftPlayer

void WorldManager::updateLeftPlayer(PaddleMove direction) {
	Paddle *leftPlayer = mWorld->getLeftPlayer();
	if (direction == MOVE_DOWN && !isLeftPlayerHitBottomWall()) {
		leftPlayer->setDirection(PADDLE_DIRECTION_DOWN);
	} else if (direction == MOVE_UP && !isLeftPlayerHitTopWall()) {
		leftPlayer->setDirection(PADDLE_DIRECTION_UP);
	} else {
		leftPlayer->stop();
	}
}
开发者ID:schen59,项目名称:Pong,代码行数:10,代码来源:WorldManager.cpp

示例8: putBallAtLeftPaddleEdge

void WorldManager::putBallAtLeftPaddleEdge() {
	Paddle *leftPaddle = mWorld->getLeftPaddle();
	Ball *ball = mWorld->getBall();
	Ogre::Vector3 leftPaddlePosition = leftPaddle->getPosition();
	Ogre::Vector3 leftPaddleDimension = leftPaddle->getDimension();
	Ogre::Vector3 ballPosition = ball->getPosition();
	Ogre::Vector3 ballDimension = ball->getDimension();
	ballPosition.x = leftPaddlePosition.x + (leftPaddleDimension.x + ballDimension.x)/2;
	ball->setPosition(ballPosition);
}
开发者ID:schen59,项目名称:Pong,代码行数:10,代码来源:WorldManager.cpp

示例9: putBallAtRightPaddleEdge

void WorldManager::putBallAtRightPaddleEdge() {
	Paddle *rightPaddle = mWorld->getRightPaddle();
	Ball *ball = mWorld->getBall();
	Ogre::Vector3 rightPaddlePosition = rightPaddle->getPosition();
	Ogre::Vector3 rightPaddleDimension = rightPaddle->getDimension();
	Ogre::Vector3 ballPosition = ball->getPosition();
	Ogre::Vector3 ballDimension = ball->getDimension();
	ballPosition.x = rightPaddlePosition.x - (rightPaddleDimension.x + ballDimension.x)/2;
	ball->setPosition(ballPosition);
}
开发者ID:schen59,项目名称:Pong,代码行数:10,代码来源:WorldManager.cpp

示例10: updateRightPlayer

void WorldManager::updateRightPlayer(PaddleMove direction) {
	Paddle *rightPlayer = mWorld->getRightPlayer();
	if (direction == MOVE_DOWN && !isRightPlayerHitBottomWall()) {
		rightPlayer->setDirection(Ogre::Vector3(0, -1, 0));
	} else if (direction == MOVE_UP && !isRightPlayerHitTopWall()) {
		rightPlayer->setDirection(Ogre::Vector3(0, 1, 0));
	} else {
		rightPlayer->stop();
	}
}
开发者ID:schen59,项目名称:Pong,代码行数:10,代码来源:WorldManager.cpp

示例11: update

bool GameWorld::update()
{
    Ball * ball = dynamic_cast<Ball*>(worldObjects.at(1));
    ball->updatePosition();
    Paddle * paddle = dynamic_cast<Paddle*>(worldObjects.at(0));
    paddle->CheckBallCollision();
    if (worldObjects.size() == 2 || life == 0 || curLevel == 10){
        return false;
    }
    return true;
}
开发者ID:ssidw,项目名称:cps111brickbreaker,代码行数:11,代码来源:gameworld.cpp

示例12: new

Paddle* Paddle::createWithSide(Paddle::Side side)
{
    Paddle *paddle = new (std::nothrow) Paddle();
    CCASSERT(paddle, "You must unlearn, what you have learned");
    
    if (paddle->initWithSide(side))
    {
        paddle->autorelease();
        return paddle;
    }
    CC_SAFE_DELETE(paddle);
    return nullptr;
}
开发者ID:Ratel13,项目名称:migration-demo-x,代码行数:13,代码来源:Paddle.cpp

示例13: Paddle

Paddle * Paddle::create () {

    Paddle * paddle = new Paddle();
    if (paddle && paddle->initWithFile("blank.png")) {
        paddle->setTextureRect(CCRectMake(0, 0, paddle->_paddleWidth, paddle->_paddleHalfWidth));
        paddle->setColor(ccc3(124,252,0));
        //paddle->initPaddle();
        paddle->autorelease();
        return paddle;
    }
    CC_SAFE_DELETE(paddle);
    return NULL;
}
开发者ID:jlpjavi,项目名称:ArkanoidCocos2D,代码行数:13,代码来源:Paddle.cpp

示例14: Touch

	void ExtraBallItem::Touch(Paddle& paddle, TouchInfo info) {
		SetPhysicsModel(PHY_GHOST);
		SetCollisionModel(PHY_GHOST);
		Die();

		entPtr_t ball = entPtr_t(new ENT::Ball(GetRules()));
		ball->SetPosition(paddle.GetPosition() + 
				MATH::Vector2((paddle.GetBBox().lowerRight.x / 2.0f) - (BALL_SIZE / 2.0f), 
				-(BALL_SIZE + 1.0f)));
		Entity::LinkToWorld(ball);

		paddle.AttachEntity(ball);
	}
开发者ID:plainoldcj,项目名称:breaking_bricks,代码行数:13,代码来源:ent_extraballitem.cpp

示例15: createRootEntity

Paddle* Application::createPaddle(Ogre::String nme, GameObject::objectType tp, Ogre::String meshName, int x, int y, int z, Ogre::Real scale, Ogre::SceneManager* scnMgr, GameManager* ssm, Ogre::Real mss, Ogre::Real rest, Ogre::Real frict, bool kinematic, Simulator* mySim) {

	createRootEntity(nme, meshName, x, y, z);
	Ogre::SceneNode* sn = mSceneManager->getSceneNode(nme);
	Ogre::Entity* ent = SceneHelper::getEntity(mSceneManager, nme, 0);
	sn->setScale(scale,scale,scale);
	const btTransform pos;
	OgreMotionState* ms = new OgreMotionState(pos, sn);

	Paddle* obj = new Paddle(nme, tp, mSceneManager, ssm, sn, ent, ms, mySim, mss, rest, frict, scale, kinematic);
	obj->addToSimulator();

	return obj;
}
开发者ID:David-Parker,项目名称:Paddle-Game,代码行数:14,代码来源:Application.cpp


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