本文整理汇总了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;
}
示例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");
}
示例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;
}
示例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();
}
}
示例5: Paddle
Paddle* Paddle::paddleWithTexture(CCTexture2D* aTexture)
{
Paddle* pPaddle = new Paddle();
pPaddle->initWithTexture( aTexture );
pPaddle->autorelease();
return pPaddle;
}
示例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;
}
示例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();
}
}
示例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);
}
示例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);
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}