1 // 2 // Cross-platform free Puyo-Puyo clone. 3 // Copyright (C) 2006, 2007 Emma's Software 4 // 5 // This program is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation; either version 2 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 // 19 #if !defined (AMOEBAX_TOURNAMENT_STATE_H) 20 #define AMOEBAX_TOURNAMENT_STATE_H 21 22 #include "IMatchObserver.h" 23 #include "IState.h" 24 #include "IPlayer.h" 25 26 namespace Amoebax 27 { 28 29 /// 30 /// \class TournamentState. 31 /// \brief Tournament mode. 32 /// 33 class TournamentState: public IState, public IMatchObserver 34 { 35 public: 36 /// 37 /// \struct Player 38 /// \brief A player of the tournament. 39 /// 40 struct Player 41 { 42 /// The name of the player's character. 43 std::string name; 44 /// The index of the player's characer. 45 uint8_t characterIndex; 46 /// Tells the computer level, if isComputerPlayer is \a true. 47 uint8_t computerPlayerLevel; 48 /// Tells if the players is computer controlled or not. 49 bool isComputerPlayer; 50 /// The player's score. 51 uint32_t score; 52 }; 53 54 TournamentState (const std::vector <Player> &players); 55 ~TournamentState (void); 56 57 virtual void activate (void); 58 virtual void endOfMatch (IPlayer::PlayerSide winner, 59 uint32_t leftPlayerScore, 60 uint32_t rightPlayerScore); 61 virtual void joyMotion (uint8_t joystick, uint8_t axis, 62 int16_t value); 63 virtual void joyDown (uint8_t joystick, uint8_t button); 64 virtual void joyUp (uint8_t joystick, uint8_t button); 65 #if !defined (IS_GP2X_HOST) 66 virtual void keyDown (uint32_t key); 67 virtual void keyUp (uint32_t key); 68 #endif // !IS_GP2X_HOST 69 virtual void redrawBackground (SDL_Rect *region, SDL_Surface *screen); 70 virtual void render (SDL_Surface *screen); shouldBePaused(void)71 virtual bool shouldBePaused (void) { return true; } 72 virtual void update (uint32_t elapsedTime); 73 virtual void videoModeChanged (void); 74 75 private: 76 /// 77 /// \struct Match 78 /// \brief A match between two players. 79 /// 80 struct Match 81 { 82 /// The parent match of this match. Used to level up the winner. 83 Match *parent; 84 /// The match's children. To traverse the tree. 85 std::pair<Match *, Match *> children; 86 /// The players that "fight" in this match. 87 std::pair<Player, Player> opponents; 88 }; 89 90 void createMatchTree (const std::vector<Player> &players); 91 void deleteMatch (Match *match); 92 IState *getBestTwoPlayersState (const Player &leftCharacter, 93 const Player &rightCharacter); 94 Match *getCurrentMatch (void); 95 int32_t getCurrentMatchBlinkTime (void) const; 96 int32_t getCurrentMatchStartTime (void) const; 97 IPlayer *getMatchPlayer (const Player &player, 98 IPlayer::PlayerSide side) const; 99 void loadGraphicResources (void); 100 void renderMatch (Match *match, SDL_Surface *screen, 101 uint16_t x, uint8_t level = 0); 102 bool showCurrentOpponents (void) const; 103 void setCurrentMatch (Match *match); 104 void setCurrentMatchBlinkTime (int32_t blinkTime); 105 void setCurrentMatchStartTime (int32_t startTime); 106 void setShowCurrentOpponents (bool showCurrentOpponents); 107 void startCurrentMatch (void); 108 109 /// The current match. 110 Match *m_CurrentMatch; 111 /// The background. 112 std::auto_ptr<Surface> m_Background; 113 /// The background music. 114 std::auto_ptr<Music> m_BackgroundMusic; 115 /// The time for toggling the show current match. 116 int32_t m_CurrentMatchBlinkTime; 117 /// The time for starting the current match. 118 int32_t m_CurrentMatchStartTime; 119 /// The player's faces. 120 std::auto_ptr<Surface> m_Faces; 121 /// Horizontal offset of players. 122 std::vector<uint16_t> m_HorizontalOffset; 123 /// The matches. 124 Match m_Matches; 125 /// The number of players. 126 size_t m_NumPlayers; 127 /// Tells if show the current match's opponents. 128 bool m_ShowCurrentOpponents; 129 /// The sound of when you lose. 130 std::auto_ptr<Sound> m_SoundLose; 131 /// The sound of when you win. 132 std::auto_ptr<Sound> m_SoundWin; 133 /// Vertical position of players. 134 std::vector<uint16_t> m_VerticalPosition; 135 }; 136 } 137 138 #endif // !AMOEBAX_TOURNAMENT_STATE_H 139