C:/DevKitPro/!MDuel/source/pickupSpawner.cpp

Go to the documentation of this file.
00001 /*
00002  * Marshmallow Duel DS v2
00003  * Copyright © 2007 Sam Pospischil http://pospi.spadgos.com
00004  * 
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00018  */
00019 
00020 #include "pickupSpawner.h"
00021 #include "pickup.h"
00022 #include "gameManager.h"
00023 #include "menuGBottom.h"
00024 
00032 pickupSpawner::pickupSpawner(spriteManager *newgm) :
00033         spriteObject(newgm), pickupDir(SDIR_DOWN)
00034 {
00035         #ifdef __MDDEBUG
00036         className = "pickupSpawner";
00037         macros::debugMessage(className, "constructor");
00038         #endif
00039         setLayer(3);
00040 }
00041 
00042 pickupSpawner::~pickupSpawner()
00043 {
00044         
00045 }
00046 
00051 void pickupSpawner::updateSprite()
00052 {
00053         gameManager *gm = dynamic_cast<gameManager*>(sm);
00054         
00055         vector<pendingPickup>::iterator pk = pendingPickups.begin();
00056         while (pk != pendingPickups.end())
00057         {
00058                 if ((*pk).framesUntilSpawn == 0)
00059                 {
00060                         u8 lifeTime = PA_RandMinMax(PICKUPLIFEMIN, PICKUPLIFEMAX);
00061                         s16 tempx = PA_RandMinMax(PICKUPSPEEDMIN, PICKUPSPEEDMAX);
00062                         s16 tempy = PA_RandMinMax(PICKUPSPEEDMIN, PICKUPSPEEDMAX);
00063                         s8 xoffset = 0, yoffset = 0;
00064                         s16 puffPosx = getx();
00065                         s16 puffPosy = gety()-4;
00066                         
00067                         if (pickupDir == SDIR_DOWN)
00068                         {
00069                                 tempx = PA_RandMax(PICKUPSPEEDMAX);
00070                                 if (PA_RandMax(1))
00071                                         tempx *= -1;
00072                                 yoffset = 8;
00073                                 puffPosy+=8;
00074                         } else if (pickupDir == SDIR_LEFT)
00075                         {
00076                                 tempy = PA_RandMax(PICKUPSPEEDMAX);
00077                                 if (PA_RandMax(1))
00078                                         tempy *= -1;
00079                                 tempx *= -1;
00080                                 xoffset = -8;
00081                                 puffPosx-=8;
00082                         } else if (pickupDir == SDIR_RIGHT)
00083                         {
00084                                 tempy = PA_RandMax(PICKUPSPEEDMAX);
00085                                 if (PA_RandMax(1))
00086                                         tempy *= -1;
00087                                 xoffset = 8;
00088                                 puffPosx+=8;
00089                         }
00090                         float speedx = (float)tempx / 256;
00091                         float speedy = (float)tempy / 256;
00092                         
00093                         Pickup *temp = new Pickup(gm, this, lifeTime, getx()+xoffset, gety()+yoffset,
00094                                                                                 (*pk).nextType, gm->getNextAvailablePickupGFXSet());
00095                         
00096                         if (temp != NULL)               //if it is, welll shit!
00097                                 temp->setSpeed(speedx, speedy);                         
00098                         
00099                         //this one has spawned, clear it from the queue.
00100                         pk = pendingPickups.erase(pk);
00101                         continue;
00102                 } 
00103                 if ((*pk).framesUntilSpawn > 0) {
00104                         (*pk).framesUntilSpawn--;
00105                 }
00106                 ++pk;
00107         }
00108         spriteObject::updateSprite();
00109 }
00110 
00115 void pickupSpawner::pickupDied()
00116 {
00117         resetIdleTime();
00118 }
00119 
00124 void pickupSpawner::resetIdleTime()
00125 {
00126         menuGBottom *mb = dynamic_cast<menuGBottom*>(dynamic_cast<gameManager*>(sm)->gameBottom);
00127         mb->resetIdleTime(pickupDir);
00128         mb->pickupsActive--;
00129 }
00130 
00137 void pickupSpawner::addSpawnTime(u8 secs, u8 type)
00138 {
00139         pendingPickup p;
00140         p.framesUntilSpawn = secs*ANIMSPEED*TICKSPERFRAME;
00141         p.nextType = type;
00142         pendingPickups.push_back(p);
00143 }

Generated on Tue Mar 13 23:27:53 2007 for MDuel DS by  doxygen 1.5.1-p1