• Main Page
  • Classes
  • Files
  • File List
  • File Members

code/source/Powerup.cpp

Go to the documentation of this file.
00001 /*
00002  * TetriCycle
00003  * Copyright (C) 2009, 2010 Cale Scholl
00004  *
00005  * This file is part of TetriCycle.
00006  *
00007  * TetriCycle is free software: you can redistribute it and/or modify
00008  * it under the terms of the GNU Lesser General Public License as published
00009  * by the Free Software Foundation, either version 3 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * TetriCycle is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with TetriCycle.  If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00021 /** @file Powerup.cpp
00022  * @author Cale Scholl / calvinss4
00023  */
00024 
00025 #include "Powerup.h"
00026 
00027 #include "Options.h"       // for Options
00028 #include "Player.h"        // for Player
00029 #include "libwiigui/gui.h" // for GuiSound
00030 
00031 extern Options *g_options; ///< the global options
00032 extern Player *g_players;  ///< the player instances
00033 
00034 GuiSound *Powerup::defaultSound = 
00035   new GuiSound(powerup_default_pcm, powerup_default_pcm_size, SOUND_PCM);
00036 
00037 /**
00038  * Do not override this function. 
00039  * This function is called automatically whenever a powerup is dropped on a 
00040  * player.
00041  * @param targetPlayer The target player index.
00042  * @return True if the powerup was successfully used on a player.
00043  */
00044 bool Powerup::Initiate(u8 targetPlayer)
00045 {
00046   int slot;
00047   Powerup *powerup = NULL;
00048 
00049   switch (GetTargetType())
00050   {
00051     case POWERUP_TARGET_ONE:
00052     {
00053       slot = g_players[targetPlayer].GetEffectQueueSlot();
00054       if (slot >= 0)
00055       {
00056         if (!powerup)
00057           powerup = GetInstance();
00058 
00059         g_players[targetPlayer].QueueEffect(powerup, slot);
00060         StartEffect(targetPlayer);
00061       }
00062       break;
00063     }
00064 
00065     case POWERUP_TARGET_ALL:
00066     {
00067       for (int i = 0; i < g_options->players; ++i)
00068       {
00069         slot = g_players[i].GetEffectQueueSlot();
00070         if (slot >= 0)
00071         {
00072           if (!powerup)
00073             powerup = GetInstance();
00074 
00075           g_players[i].QueueEffect(powerup, slot);
00076           StartEffect(i);
00077         }
00078       }
00079       break;
00080     }
00081 
00082     case POWERUP_TARGET_ALL_BUT_ONE:
00083     {
00084       for (int i = 0; i < g_options->players; ++i)
00085       {
00086         if (i != targetPlayer)
00087         {
00088           slot = g_players[i].GetEffectQueueSlot();
00089           if (slot >= 0)
00090           {
00091             if (!powerup)
00092               powerup = GetInstance();
00093           
00094             g_players[i].QueueEffect(powerup, slot);
00095             StartEffect(i);
00096           }
00097         }
00098       }
00099       break;
00100     }
00101   }
00102 
00103   if (powerup)
00104   {
00105     GetSound()->Play();
00106     powerup->startTime = gettime();
00107   }
00108   
00109   return powerup != NULL;
00110 }
00111   
00112 void Powerup::Terminate()
00113 {
00114   for (int i = 0; i < g_options->players; ++i)
00115   {
00116     if (g_players[i].RemoveEffect(this))
00117       StopEffect(i);
00118   }
00119 
00120   delete this;
00121 }

Generated on Wed Oct 20 2010 17:06:58 for TetriCycle by  doxygen 1.7.1