Пример #1
0
    //---------------------------------------------------------------------
    void BillboardSetElement::updateRenderInstance( Real time, TransformInfo &info )
    {
        if (mBillboardSet)
        {
            bool updateTexIndex = false;

            if (mSlices > 1 || mStacks > 1)
            {
                mCurrentTexIntervalTime += time;

                if (mCurrentTexIntervalTime >= mTexIntervalTime)
                {
                    updateTexIndex = true;
                    mCurrentTexIntervalTime = 0.0f;
                }            
            }

            for ( int i = 0; i < mBillboardSet->getNumBillboards(); ++i )
            {
                Ogre::Billboard* billboard = mBillboardSet->getBillboard(i);

                if (updateTexIndex)
                {
                    uint16 texIndex = billboard->getTexcoordIndex();
                    ++texIndex;

                    if (texIndex == mStacks * mSlices)
                        texIndex = 0;

                    billboard->setTexcoordIndex(texIndex);
                }
                
                if (mColourChanged)
                    billboard->setColour(mBillboardColour * mAlphaValue);

                if (mSizeChanged)
                {
                    _CurrentScaleInfo& info = mCurrentScaleInfos[i];
                    info.mCurrentScaleIntervalTime += time;

                    float colourPersent = fmod( info.mCurrentScaleIntervalTime, mScaleIntervalTime );

                    if (info.mCurrentScaleIntervalTime > mScaleIntervalTime)
                    {
                        info.mCurrentScaleIntervalTime  = colourPersent;

                        ++(info.mCurrentIndex);

                        if (info.mCurrentIndex == MAX_STAGES)
                            info.mCurrentIndex = 0;
                    }

                    Ogre::Vector3 resultColour;

                    Real rate = colourPersent / mScaleIntervalTime;

                    int incIndex = info.mCurrentIndex + 1;
                    if (incIndex == MAX_STAGES)
                        incIndex = 0;

                    resultColour = mBillboardScale[info.mCurrentIndex] * (1-rate) + mBillboardScale[incIndex] * rate;

                    billboard->setDimensions(mBillboardWidth * resultColour.x,
                        mBillboardHeight * resultColour.y);
                }
            }

            if (mColourChanged)
                mColourChanged = false;
        }
    }
Пример #2
0
void JumpTape::updateStateFrame(double simulation_frame_time) {
    mRuntime += simulation_frame_time;
    mKeyboard = dt::InputManager::get()->getKeyboard();
    double field_speed = mRuntime/1000; 
    
    // Move each tile. 
    for(uint8_t i=0; i<TILES; ++i) {
        Ogre::Billboard* tile = mTiles->getBillboard(i);
        tile->setPosition(tile->getPosition() - Ogre::Vector3(field_speed, 0, 0));
    }
    
    // Wheater the next tile should be blank or present.
    bool blank = _GetTileType();
    
    // Move the first tile at the end of the group if it went beyond left margin.
    static uint8_t i = 0; //  index for selecting the right tile.
    Ogre::Billboard* tile = mTiles->getBillboard(i);
    if(tile->getPosition().x < (-GAME_WITDH/2)-4) {
        // Get position of the last (precedent) tile.
        double last_tile_x = mTiles->getBillboard((i+TILES-1) % TILES)->getPosition().x;
        // Append billboard to end.
        tile->setPosition(last_tile_x+TILE_X, dt::Random::get(-3, 3), 0);
        tile->setTexcoordIndex(blank);
        i++; // Switch to next tile...
        i %= TILES; // ...in a cicle.
    }
    
    // Move player.
    // Player and tile variables.
    tile = mTiles->getBillboard((i+2) % TILES); // The tile on which the player is.
    static float jump_height = 0; // The height of each jump.
    static bool jump_allowed = false; // Jump is not allowed when the player is already on air.
    bool blank_tile = tile->getTexcoordIndex(); // Wheater the tile under the player is blank.
    Ogre::Vector3 player_pos = mPlayer->getPosition();
    Ogre::Vector3 tile_pos = tile->getPosition(); // Position of the tile under the player.
    
    // Jump.
    if(mKeyboard->isKeyDown(OIS::KC_SPACE) 
        && (jump_height < MAX_JUMP_HEIGHT) && jump_allowed) {
        player_pos += Ogre::Vector3(0, JUMP_POWER, 0);
        mPlayer->setPosition(player_pos);
        jump_height += JUMP_POWER;
    }
    else {
        jump_allowed = false; // Once the player release space he can't go up anymore.
    }
    
    
    float tile_top = tile_pos.y + TILE_Y * 2; // Top of the tile.
    // Wheater the player is running on the tile.
    bool on_tile = (player_pos.y <= tile_top+0.1) && (player_pos.y >= tile_top-0.1); 
    
    // Gravity.
    if((blank_tile || !on_tile) && !jump_allowed) {
        player_pos -= Ogre::Vector3(0, G_POWER, 0);
        mPlayer->setPosition(player_pos);
    }
    
    // Evaluate if jump is allowed.
    if(on_tile && !blank_tile) {
        jump_height = 0;
        jump_allowed = true;
        // The player is running, change animation.
        mPlayer->setTexcoordIndex(static_cast<uint8_t>(mRuntime*10) % PLAYER_FRAME);
    }
    
    // Reset game.
    if(mKeyboard->isKeyDown(OIS::KC_N)) {
        mRuntime=0;
        mPlayer->setPosition(mPlayer->getPosition().x, tile_pos.y+4, 0);
        tile->setTexcoordIndex(0);
    }
    
    // Show reset game info.
    static QString time;
    if(player_pos.y < -4) {
        mGameInfo->setText("You ran for " + time + " seconds, press N for a new game");
    }
    else {
        time = dt::Utils::toString(static_cast<uint32_t>(mRuntime));
        mGameInfo->setText("You ran for " + time + " seconds");
    }
}