tournamentsetupstate.cpp
来自「Source code (C++) of the Amoebax game fo」· C++ 代码 · 共 781 行 · 第 1/2 页
CPP
781 行
//// Cross-platform free Puyo-Puyo clone.// Copyright (C) 2006, 2007 Emma's Software//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.//#if defined (HAVE_CONFIG_H)#include <config.h>#endif // HAVE_CONFIG_H#include <sstream>#include "File.h"#include "System.h"#include "TournamentSetupState.h"#include "TournamentState.h"using namespace Amoebax;static const uint16_t k_CharacterImageX = 993;static const uint16_t k_CharacterImageY = 412;static const uint8_t k_ComputerFacesRow = 2;static const uint16_t k_ComputerFacesRowY = 730;static const uint8_t k_ComputerCharactersColumns = 6;static const uint16_t k_ComputerCharactersLabelY = 645;static const uint16_t k_FaceHeight = 128;static const uint16_t k_FaceSpan = 154;static const uint8_t k_FacesPerRow = 7;static const uint16_t k_FaceStartX = 160;static const uint16_t k_FaceWidth = 128;static const uint8_t k_FemaleFacesRow = 0;static const uint16_t k_FemaleFacesRowY = 350;static const uint8_t k_HumanCharactersColumns = 4;static const uint16_t k_HumanCharactersLabelY = 265;static const uint8_t k_MaleFacesRow = 1;static const uint16_t k_MaleFacesRowY = 504;static const uint8_t k_NumCharacters = 14;static const uint8_t k_NumCharactersRows = 3;static const uint16_t k_SelectPlayerX = 160;static const uint16_t k_SelectPlayerY = 190;static const int32_t k_TimeToWait = 2500;////// \brief Default constructor.////// \param players The number of players.///TournamentSetupState::TournamentSetupState (uint8_t players): IState (), m_Background (0), m_CurrentPlayer (0), m_Font (0), m_NumPlayers (players), m_Characters (), m_SelectedCharacters (), m_SelectedCol (0), m_SelectedRow (0), m_Selection (0), m_TimeToWait (k_TimeToWait){ m_Characters[0].name = "Kim"; m_Characters[1].name = "Sasha"; m_Characters[2].name = "Brooke"; m_Characters[3].name = "Lem"; m_Characters[4].name = "Tom"; m_Characters[5].name = "Ed"; m_Characters[6].name = "Gary"; m_Characters[7].name = "Nicholas"; m_Characters[8].name = "K.Quita"; m_Characters[9].name = "Angus"; m_Characters[10].name = "Kerberos"; m_Characters[11].name = "Spike"; m_Characters[12].name = "Mr.Bones"; m_Characters[13].name = "Pen"; loadGraphicResources ();}voidTournamentSetupState::activate (void){}////// \brief Tells if all characters are selected.////// \return \a true if all players have selected a characters,/// \a false otherwise.///inline boolTournamentSetupState::allCharactersSelected (void) const{ return getCurrentPlayer () == getNumPlayers ();}////// \brief Deselects the last selected character.////// If there's now selected character, this function return to the main/// menu.///voidTournamentSetupState::deselectCharacter (void){ if ( m_SelectedCharacters.empty () ) { System::getInstance ().returnToMainMenu (); } else { setSelectedCol (m_SelectedCharacters.back ().col); setSelectedRow (m_SelectedCharacters.back ().row); m_SelectedCharacters.pop_back (); setPreviousPlayer (); }}////// \brief Gets the player that currently selects a character.////// \return The player index in the range of 0..getNumPlayers()-1.///inline uint8_tTournamentSetupState::getCurrentPlayer (void) const{ return m_CurrentPlayer;}////// \brief Gets the number of players that will select a character.////// \return The number of players that need to select a player.///inline uint8_tTournamentSetupState::getNumPlayers (void) const{ return m_NumPlayers;}////// \brief Gets the time to wait before changing to the tournament state.////// \return The number of milliseconds to wait before we can change/// the current state to the tournament state.///inline int32_tTournamentSetupState::getTimeToWait (void) const{ return m_TimeToWait;}////// \brief Gets the unscaled X position of a column of the character grid.////// \param col The column to compute the X position of./// \return The unscaled X position of column \p col.///inline uint16_tTournamentSetupState::getXPositionOfCol (uint8_t col) const{ return k_FaceStartX + k_FaceSpan * col;}////// \brief Gets the unscaled Y position of a row of the characters grid.////// \param row The row to compute the Y position of./// \return The unscaled Y position of row \p row.///uint16_tTournamentSetupState::getYPositionOfRow (uint8_t row) const{ uint16_t y; switch ( row ) { case k_FemaleFacesRow: y = k_FemaleFacesRowY; break; case k_MaleFacesRow: y = k_MaleFacesRowY; break; case k_ComputerFacesRow: y = k_ComputerFacesRowY; break; default: y = k_FemaleFacesRowY; break; } return y;}////// \brief Tells if the currently selected grid position is valid.////// A valid position is any position where there's no selected character.///boolTournamentSetupState::isSelectedPositionValid (void) const{ for ( std::vector<SelectedCharacter>::const_iterator currentCharacter = m_SelectedCharacters.begin () ; currentCharacter != m_SelectedCharacters.end () ; ++currentCharacter ) { if ( currentCharacter->col == getSelectedCol () && currentCharacter->row == getSelectedRow () ) { return false; } } return true;}voidTournamentSetupState::joyMotion (uint8_t joystick, uint8_t axis, int16_t value){}voidTournamentSetupState::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: selectCharacter (); break; case GP2X_BUTTON_DOWN: selectNextRow (); break; case GP2X_BUTTON_LEFT: selectPreviousCol (); break; case GP2X_BUTTON_RIGHT: selectNextCol (); break; case GP2X_BUTTON_UP: selectPreviousRow (); break; case GP2X_BUTTON_X: deselectCharacter (); break; }#endif // IS_GP2X_HOST}voidTournamentSetupState::joyUp (uint8_t joystick, uint8_t button){}#if !defined (IS_GP2X_HOST)|| defined (__SYMBIAN32__)voidTournamentSetupState::keyDown (uint32_t key){ switch (key) { case SDLK_DOWN:
case SDLK_PAGEDOWN: selectNextRow (); break; case SDLK_ESCAPE: deselectCharacter (); break; case SDLK_LEFT: selectPreviousCol (); break; case SDLK_RETURN:
case SDLK_F5: selectCharacter (); break; case SDLK_RIGHT: selectNextCol (); break; case SDLK_UP:
case SDLK_PAGEUP: selectPreviousRow (); break; }}voidTournamentSetupState::keyUp (uint32_t key){}#endif // !IS_GP2X_HOST////// \brief Gets the currently selected column.////// \return The index of the column of the currently selected character.///inline uint8_tTournamentSetupState::getSelectedCol (void) const{ return m_SelectedCol;}////// \brief Gets the currently selected character.////// \return The currently selected character.///inline const TournamentSetupState::CharacterInfo &TournamentSetupState::getSelectedCharacter (void) const{ return m_Characters[getSelectedCharacterIndex ()];}////// \brief Gets the index of the currently selected character.////// \return The index of the currently selected character.///inline uint8_tTournamentSetupState::getSelectedCharacterIndex (void) const{ return getSelectedRow () * 4 + getSelectedCol ();}////// \brief Gets the currently selelected row.////// \return The index of the column of the selected character.///inline uint8_tTournamentSetupState::getSelectedRow (void) const{ return m_SelectedRow;}////// \brief Loads graphic resources.///voidTournamentSetupState::loadGraphicResources (void){ const float screenScale = System::getInstance ().getScreenScaleFactor ();#if defined (IS_GP2X_HOST) const float originalScale = screenScale; const uint16_t faceHeight = static_cast<uint16_t>(k_FaceHeight * screenScale); const uint16_t faceWidth = static_cast<uint16_t>(k_FaceWidth * screenScale);#else // !IS_GP2X_HOST const float originalScale = 1.0f; const uint16_t faceHeight = k_FaceHeight; const uint16_t faceWidth = k_FaceWidth ;#endif // IS_GP2X_HOST m_Background.reset ( Surface::fromFile (File::getGraphicsFilePath ("menuBackground.png"))); { std::auto_ptr<Surface> faces ( Surface::fromFile (File::getGraphicsFilePath ("faces.png"))); for ( uint16_t currentCharacter = 0, x = static_cast<uint16_t> (k_FaceStartX * originalScale); currentCharacter < 4 ; currentCharacter++, x += static_cast<uint16_t> (k_FaceSpan * originalScale) ) { faces->blit ((currentCharacter % k_FacesPerRow) * faceWidth, 0, faceWidth, faceHeight, x, static_cast<uint16_t> (k_FemaleFacesRowY * originalScale), m_Background->toSDLSurface()); } for ( uint16_t currentCharacter = 4, x = static_cast<uint16_t> (k_FaceStartX * originalScale); currentCharacter < 8 ;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?