⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 twogp2xplayersstate.cpp

📁 Source code (C++) of the Amoebax game for Symbian OS UIQ3.x。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    return mustShowGoLabel () || mustShowReadyLabel ();}////// \brief Tells if the "Ready?" label should be displayed.////// \return \a true If the "Ready?" label should be displayed,///         \a false otherwise.///inline boolTwoGP2XPlayersState::mustShowReadyLabel (void) const{    return getReadyTime () > 0;}voidTwoGP2XPlayersState::redrawBackground (SDL_Rect *region, SDL_Surface *screen){    m_Background->blit (region->x, region->y, region->w, region->h,                        region->x, region->y, screen);}voidTwoGP2XPlayersState::render (SDL_Surface *screen){    // Draw left grid's amoebas.    {        SDL_Rect gridRectangle;        gridRectangle.x = getLeftGrid ()->getGridPositionX () -                          getAmoebaSize () * 12;        gridRectangle.y = getLeftGrid ()->getGridPositionY ();        gridRectangle.w = getAmoebaSize () * 12;        gridRectangle.h = getLeftGrid ()->getQueuePositionY () +                          getAmoebaSize () - gridRectangle.y;        SDL_SetClipRect (screen, &gridRectangle);        // Draw the main falling amoeba's silhouette.        const Grid::FallingAmoeba mainAmoeba =            getLeftGrid ()->getFallingMainAmoeba ();        if ( 0 != mainAmoeba.amoeba )        {            int8_t silhouetteFrame = getLeftGrid ()->getSilhouetteFrame ();            if ( 0 < silhouetteFrame )            {                Amoeba *amoeba = mainAmoeba.amoeba;                uint8_t silhouetteSize = getAmoebaSize () +                    2 * getSilhouetteBorder ();                m_SilhouettesLeft->blit (silhouetteSize * silhouetteFrame,                        silhouetteSize * amoeba->getColour (),                        silhouetteSize, silhouetteSize,                        amoeba->getX () - getSilhouetteBorder (),                        amoeba->getY () - getSilhouetteBorder (),                        screen);            }        }        const std::list<Amoeba *> &leftActiveAmoebas =            getLeftGrid ()->getActiveAmoebas ();        std::for_each (leftActiveAmoebas.begin (), leftActiveAmoebas.end (),                       DrawAmoeba (getAmoebaSize (), m_AmoebasLeft.get (),                                   screen));    }    // Draw left queued amoebas.    {        SDL_Rect queueRectangle;        queueRectangle.x = getLeftGrid ()->getQueuePositionX () -                           4 * getAmoebaSize ();        queueRectangle.y = getLeftGrid ()->getQueuePositionY ();        queueRectangle.w = 4 * getAmoebaSize ();        queueRectangle.h = getAmoebaSize ();        SDL_SetClipRect (screen, &queueRectangle);        const std::list<Amoeba *> &queuedAmoebas = getLeftGrid ()->getQueuedAmoebas ();        for_each (queuedAmoebas.begin (), queuedAmoebas.end (),                DrawAmoeba (getAmoebaSize (), m_AmoebasLeft.get (), screen));    }    // Draw left waiting amoebas.    {        SDL_Rect waitingGhosts;        waitingGhosts.x = getLeftGrid ()->getWaitingGhostPositionX () -                          getAmoebaSize ();        waitingGhosts.y = getLeftGrid ()->getWaitingGhostPositionY ();        waitingGhosts.w = getAmoebaSize ();        waitingGhosts.h = getAmoebaSize () * 6;        SDL_SetClipRect (screen, &waitingGhosts);        const std::vector<Amoeba *> &leftGhostAmoebas =            getLeftGrid ()->getWaitingGhostAmoebas ();        std::for_each (leftGhostAmoebas.begin (), leftGhostAmoebas.end (),                       DrawAmoeba (getAmoebaSize (), m_AmoebasLeft.get (),                                   screen));    }    // Draw right grid's amoebas.    {        SDL_Rect gridRectangle;        gridRectangle.x = getRightGrid ()->getQueuePositionX ();        gridRectangle.y = getRightGrid ()->getQueuePositionY () -                          getAmoebaSize ();        gridRectangle.w = getAmoebaSize () * 12;        gridRectangle.h = getRightGrid ()->getGridPositionY () -                          gridRectangle.y;        SDL_SetClipRect (screen, &gridRectangle);        // Draw the main falling amoeba's silhouette.        const Grid::FallingAmoeba mainAmoeba =            getRightGrid ()->getFallingMainAmoeba ();        if ( 0 != mainAmoeba.amoeba )        {            int8_t silhouetteFrame = getRightGrid ()->getSilhouetteFrame ();            if ( 0 < silhouetteFrame )            {                Amoeba *amoeba = mainAmoeba.amoeba;                uint8_t silhouetteSize = getAmoebaSize () +                    2 * getSilhouetteBorder ();                m_SilhouettesRight->blit (silhouetteSize * silhouetteFrame,                        silhouetteSize * amoeba->getColour (),                        silhouetteSize, silhouetteSize,                        amoeba->getX () - getSilhouetteBorder (),                        amoeba->getY () - getSilhouetteBorder (),                        screen);            }        }        const std::list<Amoeba *> &rightActiveAmoebas =            getRightGrid ()->getActiveAmoebas ();        std::for_each (rightActiveAmoebas.begin (),                       rightActiveAmoebas.end (),                       DrawAmoeba (getAmoebaSize (), m_AmoebasRight.get (),                                   screen));    }    // Draw right queued amoebas.    {        SDL_Rect queueRectangle;        queueRectangle.x = getRightGrid ()->getQueuePositionX ();        queueRectangle.y = getRightGrid ()->getQueuePositionY () -                           getAmoebaSize ();        queueRectangle.w = 4 * getAmoebaSize ();        queueRectangle.h = getAmoebaSize ();        SDL_SetClipRect (screen, &queueRectangle);        const std::list<Amoeba *> &queuedAmoebas = getRightGrid ()->getQueuedAmoebas ();        for_each (queuedAmoebas.begin (), queuedAmoebas.end (),                DrawAmoeba (getAmoebaSize (), m_AmoebasRight.get (), screen));    }    // Draw right waiting amoebas.    {        SDL_Rect waitingGhosts;        waitingGhosts.x = getRightGrid ()->getWaitingGhostPositionX ();        waitingGhosts.y = getRightGrid ()->getWaitingGhostPositionY () -                          getAmoebaSize () * 6;        waitingGhosts.w = getAmoebaSize ();        waitingGhosts.h = getAmoebaSize () * 6;        SDL_SetClipRect (screen, &waitingGhosts);        const std::vector<Amoeba *> &rightGhostAmoebas =            getRightGrid ()->getWaitingGhostAmoebas ();        std::for_each (rightGhostAmoebas.begin (), rightGhostAmoebas.end (),                       DrawAmoeba (getAmoebaSize (), m_AmoebasRight.get (),                                   screen));    }    // Remove any clipping area.    SDL_SetClipRect (screen, 0);    // Draw the current player's score.  The right player has its    // score right aligned and the left player left aligned.    std::ostringstream leftScoreString;    leftScoreString << getLeftPlayerScore ();    uint16_t leftScoreX = k_PositionXLeftScore;    uint16_t leftScoreY = k_PositionYLeftScore;    std::ostringstream rightScoreString;    rightScoreString << getRightPlayerScore ();    uint16_t rightScoreWidth =        m_ScoreFont->getTextWidth (rightScoreString.str ());    uint16_t rightScoreX = k_PositionXRightScore - rightScoreWidth;    uint16_t rightScoreY = k_PositionYRightScore;    m_ScoreFont->write (leftScoreString.str (), leftScoreX, leftScoreY, screen);    m_ScoreFont->write (rightScoreString.str (), rightScoreX, rightScoreY,                        screen);    if ( gameIsOver () )    {        // Draw left grid's result graphic.        {            uint16_t sourceWidth = m_WinnerLoser->getWidth () / 2;            uint16_t sourceHeight = m_WinnerLoser->getHeight () / 2;            uint16_t sourceY =                (IPlayer::RightSide == getWinnerSide ()) ? sourceHeight : 0;            uint16_t sourceX = 0;            uint16_t destinationX = getLeftGrid ()->getGridPositionX () -                                    getAmoebaSize () * 6 - sourceWidth / 2;            uint16_t destinationY = getLeftGrid ()->getGridPositionY () +                                    getAmoebaSize () * 3 - sourceHeight / 2;            m_WinnerLoser->blit (sourceX, sourceY, sourceWidth, sourceHeight,                                 destinationX, destinationY, screen);        }        // Draw right grid's result graphic.        {            uint16_t sourceWidth = m_WinnerLoser->getWidth () / 2;            uint16_t sourceHeight = m_WinnerLoser->getHeight () / 2;            uint16_t sourceY =                (IPlayer::LeftSide == getWinnerSide ()) ? sourceHeight : 0;            uint16_t sourceX = sourceWidth;            uint16_t destinationX = getRightGrid ()->getGridPositionX () +                                    getAmoebaSize () * 6 - sourceWidth / 2;            uint16_t destinationY = getRightGrid ()->getGridPositionY () -                                    getAmoebaSize () * 3 - sourceHeight / 2;            m_WinnerLoser->blit (sourceX, sourceY, sourceWidth, sourceHeight,                                 destinationX, destinationY, screen);        }    }    else if ( mustShowInitialLabels () )    {        if ( mustShowReadyLabel () )        {            uint16_t sourceWidth = m_Ready->getWidth () / 2;            uint16_t sourceHeight = m_Ready->getHeight ();            uint16_t leftDestinationX = getLeftGrid ()->getGridPositionX () -                getAmoebaSize () * 6 - sourceWidth / 2;            uint16_t leftDestinationY = getLeftGrid ()->getGridPositionY () +                getAmoebaSize () * 3 - sourceHeight / 2;            uint16_t rightDestinationX = getRightGrid ()->getGridPositionX () +                getAmoebaSize () * 6 - sourceWidth / 2;            uint16_t rightDestinationY = getRightGrid ()->getGridPositionY () -                getAmoebaSize () * 3 - sourceHeight / 2;            m_Ready->blit (0, 0, sourceWidth, sourceHeight,                           leftDestinationX, leftDestinationY, screen);            m_Ready->blit (sourceWidth, 0, sourceWidth, sourceHeight,                           rightDestinationX, rightDestinationY, screen);        }        else        {            uint16_t sourceWidth = m_Go->getWidth () / 2;            uint16_t sourceHeight = m_Go->getHeight ();            uint16_t leftDestinationX = getLeftGrid ()->getGridPositionX () -                getAmoebaSize () * 6 - sourceWidth / 2;            uint16_t leftDestinationY = getLeftGrid ()->getGridPositionY () +                getAmoebaSize () * 3 - sourceHeight / 2;            uint16_t rightDestinationX = getRightGrid ()->getGridPositionX () +                getAmoebaSize () * 6 - sourceWidth / 2;            uint16_t rightDestinationY = getRightGrid ()->getGridPositionY () -                getAmoebaSize () * 3 - sourceHeight / 2;            m_Go->blit (0, 0, sourceWidth, sourceHeight,                        leftDestinationX, leftDestinationY, screen);            m_Go->blit (sourceWidth, 0, sourceWidth, sourceHeight,                        rightDestinationX, rightDestinationY, screen);        }    }}////// \brief The game is over.////// Check which is the winner player's side and marks the/// game as over.  If there's an attached observer, also/// notifies it.///voidTwoGP2XPlayersState::setGameOver (void){    m_GameIsOver = true;    m_Winner = getLeftGrid ()->isFilled () ? IPlayer::RightSide :                                             IPlayer::LeftSide;    if ( m_Observer != 0 )    {        m_Observer->endOfMatch (m_Winner,                                getLeftGrid ()->getScore (),                                getRightGrid ()->getScore ());    }}////// \brief Sets the time to display the "Go!!" label.////// \param time The time to set as time to show the "Go!!" label. If it's///             negative, the "Go!!" label gets deleted.///inline voidTwoGP2XPlayersState::setGoTime (int32_t time){    m_GoTime = time;    if ( 0 > time )    {        m_Go.reset (0);    }}////// \brief Sets the time to show the "Ready?" label.////// \param time The time to set to show the "Ready?" label. If it's negative///             the "Ready?" label gets deleted.///inline voidTwoGP2XPlayersState::setReadyTime (int32_t time){    m_ReadyTime = time;    if ( 0 > time )    {        m_Ready.reset (0);    }}////// \brief Sets the size of the silhouettes' border.////// \param border The size of the silhouettes' border.///inline voidTwoGP2XPlayersState::setSilhouetteBorder (uint8_t border){    m_SilhouetteBorder = border;}voidTwoGP2XPlayersState::update (uint32_t elapsedTime){    // Only update if no grid is filled.    if ( !gameIsOver () )    {        if ( mustShowInitialLabels () )        {            if ( mustShowReadyLabel () )            {                setReadyTime (getReadyTime () - elapsedTime);            }            else            {                setGoTime (getGoTime () - elapsedTime);            }        }        else        {            // Update both grids.            getLeftGrid ()->update (elapsedTime);            getRightGrid ()->update (elapsedTime);            // Update the waiting ghost amoebas.            getLeftGrid ()->incrementNumberOfWaitingGhosts (                    getRightGrid ()->getOpponentGhostAmoebas ());            getRightGrid ()->incrementNumberOfWaitingGhosts (                    getLeftGrid ()->getOpponentGhostAmoebas ());            if ( getLeftGrid ()->isFilled () || getRightGrid ()->isFilled () )            {                setGameOver ();                Music::stop ();            }        }    }}voidTwoGP2XPlayersState::videoModeChanged (void){    loadGraphicsResources ();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -