tournamentstate.cpp

来自「Source code (C++) of the Amoebax game fo」· C++ 代码 · 共 629 行 · 第 1/2 页

CPP
629
字号
inline TournamentState::Match *TournamentState::getCurrentMatch (void){    return m_CurrentMatch;}////// \brief Gets the time remaining to change the current match blink state.////// \return The time remaining until the application should change the///         blinking state of the current match's opponents.///inline int32_tTournamentState::getCurrentMatchBlinkTime (void) const{    return m_CurrentMatchBlinkTime;}////// \brief Gets the time remaining to start the current match.////// \return The time remaining until the current match starts.///inline int32_tTournamentState::getCurrentMatchStartTime (void) const{    return m_CurrentMatchStartTime;}////// \brief Gets a player of a match.////// \param player The definition of the match's player to create the object///               from./// \param side The side the player will play on./// \return The IPlayer created from the definition of \p player.///IPlayer *TournamentState::getMatchPlayer (const Player &player,                                 IPlayer::PlayerSide side) const{    IPlayer *matchPlayer = 0;    if ( player.isComputerPlayer )    {        matchPlayer = AIPlayerFactory::create (player.computerPlayerLevel, side);    }    else    {        matchPlayer = new HumanPlayer (side);    }    return matchPlayer;}voidTournamentState::joyMotion (uint8_t joystick, uint8_t axis, int16_t value){}voidTournamentState::joyDown (uint8_t joystick, uint8_t button){#if defined (IS_GP2X_HOST)&& !defined (__SYMBIAN32__)    switch (button)    {        case GP2X_BUTTON_A:        case GP2X_BUTTON_B:        case GP2X_BUTTON_CLICK:            startCurrentMatch ();            break;        case GP2X_BUTTON_START:        case GP2X_BUTTON_X:            System::getInstance ().pause ();            break;    }#endif // IS_GP2X_HOST}voidTournamentState::joyUp (uint8_t joystick, uint8_t button){}#if !defined (IS_GP2X_HOST)|| defined (__SYMBIAN32__)voidTournamentState::keyDown (uint32_t key){    switch ( key )    {        case SDLK_ESCAPE:            System::getInstance ().pause ();            break;        case SDLK_RETURN:
		case SDLK_F5:            startCurrentMatch ();            break;    }}voidTournamentState::keyUp (uint32_t key){}#endif // !IS_GP2X_HOST////// \brief Loads graphic resources.///voidTournamentState::loadGraphicResources (void){    const float screenScale = System::getInstance ().getScreenScaleFactor ();    m_Background.reset (            Surface::fromFile (File::getGraphicsFilePath ("menuBackground.png")));    {        std::ostringstream fileName;        fileName << "Tournament";        fileName << m_NumPlayers;        fileName << "p.png";        std::auto_ptr<Surface> grid (                Surface::fromFile (File::getGraphicsFilePath (fileName.str ())));        grid->blit (m_Background->getWidth () / 2 - grid->getWidth () / 2,                    m_Background->getHeight () / 2 - grid->getHeight () / 2,                    m_Background->toSDLSurface ());    }    m_Background->resize (screenScale);    m_Faces.reset (            Surface::fromFile (File::getGraphicsFilePath ("faces.png")));    m_Faces->resize (screenScale);}voidTournamentState::redrawBackground (SDL_Rect *region, SDL_Surface *screen){    m_Background->blit (region->x, region->y, region->w, region->h,                        region->x, region->y, screen);}voidTournamentState::render (SDL_Surface *screen){    renderMatch (&m_Matches, screen, k_InitialHorizontalPosition);}////// \brief Recursively draw a match and all its children.////// Renders a match and all its children in their appropriate position.////// \param match The match to render along with all its children./// \param screen The screen surface to render the matches to./// \param initialX The central X where the matches should be rendered to.///                 This function takes into account the horizontal offset///                 between the position of the opponents./// \param level The current recursive level.  The first call it must be 0.///voidTournamentState::renderMatch (Match *match, SDL_Surface *screen,                              uint16_t initialX, uint8_t level){    const float screenScale = System::getInstance ().getScreenScaleFactor ();    const uint16_t faceSize = static_cast<uint16_t> (k_FaceSize * screenScale);    if ( 0 != match )    {        if ( getCurrentMatch () != match || showCurrentOpponents () )        {            if ( match->opponents.first.characterIndex != k_InvalidCharacterIndex )            {                uint8_t character = match->opponents.first.characterIndex;                uint16_t x = static_cast<uint16_t> ((initialX                                                     - m_HorizontalOffset[level]) *                                                    screenScale);                uint16_t y = static_cast<uint16_t> (m_VerticalPosition[level] *                                                    screenScale);                m_Faces->blit (character % k_FacesPerRow * faceSize,                               character / k_FacesPerRow * faceSize,                               faceSize, faceSize, x, y, screen);            }            if ( match->opponents.second.characterIndex != k_InvalidCharacterIndex )            {                uint8_t character = match->opponents.second.characterIndex;                uint16_t x = static_cast<uint16_t> ((initialX                                                     + m_HorizontalOffset[level]) *                                                    screenScale);                uint16_t y = static_cast<uint16_t> (m_VerticalPosition[level] *                                                    screenScale);                m_Faces->blit (character % k_FacesPerRow * faceSize,                               character / k_FacesPerRow * faceSize,                               faceSize, faceSize, x, y, screen);            }        }        renderMatch (match->children.first, screen,                     initialX - m_HorizontalOffset[level], level + 1);        renderMatch (match->children.second, screen,                     initialX + m_HorizontalOffset[level], level + 1);    }}////// \brief Tells if the current match's opponents should be shown.////// \return \a true if the current match's opponents should be rendered,///         \a false otherwise.///inline boolTournamentState::showCurrentOpponents (void) const{    return m_ShowCurrentOpponents;}////// \brief Changes the current match.////// \param match The pointer to the match to set as current.///inline voidTournamentState::setCurrentMatch (Match *match){    m_CurrentMatch = match;}////// \brief Sets the time until the blink state should change.////// \param blinkTime The time to wait until the blink state of the current///                  match's opponents should change.///inline voidTournamentState::setCurrentMatchBlinkTime (int32_t blinkTime){    m_CurrentMatchBlinkTime = blinkTime;}////// \brief Sets the time until the current match starts.////// \param startTime The time to wait until the current match starts.///inline voidTournamentState::setCurrentMatchStartTime (int32_t startTime){    m_CurrentMatchStartTime = startTime;}////// \brief Sets if show the current match's opponents or not.////// \param showCurrentOpponents set to \a true if the match's opponents should///                             be shown.  Otherwise set to \a false.///inline voidTournamentState::setShowCurrentOpponents (bool showCurrentOpponents){    m_ShowCurrentOpponents = showCurrentOpponents;}////// \brief Starts the current match.///voidTournamentState::startCurrentMatch (void){    if ( getCurrentMatch () == &m_Matches )    {        System::getInstance ().removeActiveState (false);        Player winner = m_Matches.opponents.first;        // We don't want a computer player to enter as high score.        uint32_t score = winner.isComputerPlayer ? 0 : winner.score;        System::getInstance ().setActiveState (                new CongratulationsState (winner.name, score));    }    else    {        System::getInstance ().setActiveState (                getBestTwoPlayersState (getCurrentMatch ()->opponents.first,                                        getCurrentMatch ()->opponents.second),                                        System::FadeIn);        System::getInstance ().setActiveState (                new VersusState (getCurrentMatch ()->opponents.second.name,                                 getCurrentMatch ()->opponents.first.name));        setCurrentMatchStartTime (k_MatchStartTime);    }}voidTournamentState::update (uint32_t elapsedTime){    setCurrentMatchBlinkTime (getCurrentMatchBlinkTime () - elapsedTime);    if ( 0 >= getCurrentMatchBlinkTime () )    {        setCurrentMatchBlinkTime (getCurrentMatchBlinkTime () + k_BlinkTime);        setShowCurrentOpponents (!showCurrentOpponents ());    }    setCurrentMatchStartTime (getCurrentMatchStartTime () - elapsedTime);    if ( 0 >= getCurrentMatchStartTime () )    {        startCurrentMatch ();    }}voidTournamentState::videoModeChanged (void){    loadGraphicResources ();}

⌨️ 快捷键说明

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