C:/DevKitPro/!MDuel/source/pickup.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 "pickup.h"
00021 #include "floorTile.h"
00022 #include "gameManager.h"
00023 #include "player.h"
00024 #include "weaponIncludes.h"
00025 
00030 Pickup::Pickup(spriteManager *newgm, pickupSpawner *mySpawner, u8 lifeSeconds, s16 nx, s16 ny, u8 type, gameManager::pickupGraphics* graphicSet) :
00031         spriteObject(newgm), gm(dynamic_cast<gameManager*>(newgm)), spawner(mySpawner), exploding(false), 
00032         myGFXset(graphicSet), myIcon(NULL)
00033 {
00034         #ifdef __MDDEBUG
00035         className = "pickup";
00036         macros::debugMessage(className, "constructor");
00037         #endif
00038         
00039         //important setup routines
00040         type %= NUMPICKUPVARIATIONS;
00041         gm->addPickup(this);
00042         setLifetime(lifeSeconds);
00043         if (myGFXset != NULL)
00044                 myGFXset->bInUse = true;
00045 
00046         //create spawn puff
00047         u8 f[3] = {18, 19, 20};
00048         vector<u8> vect(f, f+3);
00049         if (myGFXset != NULL)
00050                 gm->createSingleFireSprite(gm->FXSprite.palleteID, myGFXset->spawnGFX, vect, TICKSPERFRAME*2, nx, ny, OBJ_SIZE_32X32, 16, 16);
00051         else
00052                 gm->createSingleFireSprite(gm->FXSprite.palleteID, gm->FXSprite.spriteData, vect, TICKSPERFRAME*2, nx, ny, OBJ_SIZE_32X32, 16, 16);
00053         
00054         //create icon sprite to match me        
00055         myIcon = new spriteObject(sm);
00056         myIcon->setPallete(gm->pickupSprite.palleteID);
00057         if (myGFXset != NULL)
00058                 myIcon->giveGFX(myGFXset->iconGFX, OBJ_SIZE_16X16, 8, 8);
00059         else
00060                 myIcon->giveSprite(gm->pickupSprite.spriteData, OBJ_SIZE_16X16, 8, 8);
00061         myIcon->setLayer(1);
00062         myIcon->setFrame(0);
00063         addChild(myIcon);
00064         
00065         //create graphics
00066         setPallete(gm->pickupSprite.palleteID);
00067         if (myGFXset != NULL)
00068                 giveGFX(myGFXset->blobGFX, OBJ_SIZE_16X16, 8, 8);
00069         else
00070                 giveSprite(gm->pickupSprite.spriteData, OBJ_SIZE_16X16, 8, 8);
00071         
00072         setBounds(-6, 6, 6, -6);
00073         setCollision(COL_SOLID);
00074         setLayer(1);
00075         
00076         //set other properties
00077         setType(type);
00078         setPos(nx, ny);
00079 }
00080 
00086 Pickup::~Pickup()
00087 {
00088         if (gm->isResetting())
00089         {
00090                 /*
00091                 So, WHAT FOR BOWDGE!?, you might say. From what I can gather, it looks like I exceeded no$gba's
00092                 ability to remove things from OAM. Take the wait out, and compile a non-debug build. Go on, I'll
00093                 wait. Do it pussy! What's the matter? never-
00094                 So that's done. Now open the game in no$gba, wait for a pickup to spawn, and jump in the drink.
00095                 See? What the shit! Now compile in debug mode. Works fine, right? I imagine it's because of the
00096                 execution slowdown with all the logging going on. So yeah, solution is to have a wait here. You
00097                 don't even notice it. Don't look at me like that.
00098                 */
00099                 PA_WaitForVBL();
00100                 return;
00101         }
00102 
00103         gm->removePickup(this); //remove from pickups array
00104 
00105         //myIcon->destroy();            <-- already done for us via spriteObject::deleteSprite
00106 
00107         if (spawner != NULL)
00108                 spawner->pickupDied();
00109 
00110         vector<u8> temp;
00111         if (!exploding)
00112         {
00113                 u8 dieAnim[2] = {16, 17};
00114                 temp = vector<u8>(dieAnim, dieAnim+2);
00115         } else {
00116                 u8 dieAnim[4] = {0, 1, 2, 3};
00117                 temp = vector<u8>(dieAnim, dieAnim+4);
00118                 #ifdef __WITHSOUND
00119                 playSound(&gm->platformExplode);
00120                 #endif
00121         }
00122         if (myGFXset != NULL)
00123                 gm->createSingleFireSprite(gm->FXSprite.palleteID, myGFXset->dieGFX, temp, TICKSPERFRAME*2, getx(), gety(), OBJ_SIZE_32X32, 16, 16);
00124         else
00125                 gm->createSingleFireSprite(gm->FXSprite.palleteID, gm->FXSprite.spriteData, temp, TICKSPERFRAME*2, getx(), gety(), OBJ_SIZE_32X32, 16, 16);
00126         
00127         if (myGFXset != NULL)
00128                 myGFXset->bInUse = false;
00129 }
00130 
00137 void Pickup::playerTouchAction(Player* other)
00138 {
00139         switch (myType)
00140         {
00141                 case PT_SKULL:
00142                         gm->playerSkulled(other);
00143                 break;
00144                 case PT_1000V:
00145                         other->setWeapon(new wp_1000V(other));
00146                 break;
00147                 case PT_INVIS:
00148                         other->setWeapon(new wp_invis(other));
00149                 break;
00150                 case PT_MINE:
00151                         other->setWeapon(new wp_mine(other));
00152                 break;
00153                 case PT_GUN:
00154                         other->setWeapon(new wp_gun(other));
00155                 break;
00156                 case PT_TNT:
00157                 break;
00158                 case PT_BOOT:
00159                         other->setWeapon(new wp_boot(other));
00160                 break;
00161                 case PT_GRENADE:
00162                         other->setWeapon(new wp_gren(other));
00163                 break;
00164                 case PT_PUCK:
00165                         other->setWeapon(new wp_puck(other));
00166                 break;
00167                 case PT_CHUT:
00168                         other->setWeapon(new wp_chut(other));
00169                 break;
00170                 case PT_HOOK:
00171                         other->setWeapon(new wp_hook(other));
00172                 break;
00173                 case PT_WARP:
00174                         other->setWeapon(new wp_warp(other));
00175                 break;
00176                 case PT_MAGNET:
00177                         other->setWeapon(new wp_magnet(other));
00178                 break;
00179                 case PT_NET:
00180                         other->setWeapon(new wp_net(other));
00181                 break;
00182                 case PT_SHIELD:
00183                         other->setWeapon(new wp_shield(other));
00184                 break;
00185                 case PT_DUNCE:
00186                         other->setWeapon(new wp_dunce(other));
00187                 break;
00188                 case PT_WEASEL:
00189                         other->setWeapon(new wp_weasel(other));
00190                 break;
00191                 case PT_BOOMERANG:
00192                         other->setWeapon(new wp_boomerang(other));
00193                 break;
00194                 default:
00195                         other->clearWeapon();
00196                 break;
00197         }
00198 }
00199 
00206 void Pickup::setType(u8 newType)
00207 {       
00208         myType = (pickupType)(newType%NUMPICKUPVARIATIONS);
00209         
00210         #ifdef __WITHSOUND
00211         stopSound();
00212         #endif
00213         setCheckCollision(false);
00214         
00215         switch (myType)
00216         {
00217                 case PT_SKULL:
00218                         #ifdef __WITHSOUND
00219                         playSound(&gm->skullLoop, true, 64);
00220                         #endif
00221                         makeIcon(3);
00222                 break;
00223                 case PT_1000V:
00224                         makeIcon(4);
00225                 break;
00226                 case PT_INVIS:
00227                         makeIcon(5);
00228                 break;
00229                 case PT_MINE:
00230                         makeIcon(6);
00231                 break;
00232                 case PT_GUN:
00233                         makeIcon(7);
00234                 break;
00235                 case PT_TNT:
00236                         setCollision(COL_CENTERPOINT);
00237                         setCheckCollision(true);        //doesnt interact with players
00238                         makeIcon(8);
00239                 break;
00240                 case PT_BOOT:
00241                         makeIcon(9);
00242                 break;
00243                 case PT_GRENADE:
00244                         makeIcon(10);
00245                 break;
00246                 case PT_PUCK:
00247                         makeIcon(11);
00248                 break;
00249                 case PT_CHUT:
00250                         makeIcon(12);
00251                 break;
00252                 case PT_HOOK:
00253                         makeIcon(13);
00254                 break;
00255                 case PT_WARP:
00256                         makeIcon(14);
00257                 break;
00258                 case PT_MAGNET:
00259                         makeIcon(15);
00260                 break;
00261                 case PT_NET:
00262                         makeIcon(16);
00263                 break;
00264                 case PT_SHIELD:
00265                         makeIcon(17);
00266                 break;
00267                 case PT_DUNCE:
00268                         makeIcon(18);
00269                 break;
00270                 case PT_WEASEL:
00271                         makeIcon(19);
00272                 break;
00273                 case PT_BOOMERANG:
00274                         makeIcon(20);
00275                 break;
00276         }
00277         
00278         //reset the anim so that not all Pickup%s are looping at the same time
00279         setAnim(0, 2, ANIMSPEED);
00280 }
00281 
00287 void Pickup::makeIcon(u8 frame)
00288 {
00289         myIcon->setFrame(frame);
00290 }
00291 
00299 void Pickup::collidingWith(spriteObject *other)
00300 {
00301         if (dynamic_cast<floorTile*>(other) != NULL)
00302         {
00303                 if (gm->player1->isStandingOn(const_cast<spriteObject*>(other)))
00304                         gm->player1->groundDeleted(Player::CS_TNTFALL);
00305                 if (gm->player2->isStandingOn(const_cast<spriteObject*>(other)))
00306                         gm->player2->groundDeleted(Player::CS_TNTFALL);
00307                 
00308                 other->destroy();
00309                 
00310                 for (vector<spriteObject*>::iterator it = sm->gameSprites.begin(); it != sm->gameSprites.end(); ++it)
00311                 {
00312                         if (dynamic_cast<floorTile*>(*it) != NULL &&
00313                                 ((*it)->pointCollision(getLeft(), gety()) || 
00314                                 (*it)->pointCollision(getRight(), gety())))
00315                         {
00316                                 (*it)->destroy();
00317                         }
00318                 }
00319                 
00320                 destroy();
00321                 exploding = true;       //play smoke FX
00322                 return;
00323         } 
00324         spriteObject::collidingWith(other);
00325 }
00326 
00338 bool Pickup::isColliding(spriteObject *other, bool checkReverse) const
00339 {
00340         if ((dynamic_cast<floorTile*>(other) == NULL && getType() == PT_TNT) ||
00341                 (dynamic_cast<Player*>(other) == NULL && getType() != PT_TNT))
00342                 return false;
00343         
00344         return spriteObject::isColliding(other, checkReverse);
00345 }
00346 
00350 void Pickup::updateSprite()
00351 {
00352         spriteObject::updateSprite();
00353         
00354         //bounce off any walls
00355         if (getx() <= MINX || getx() >= MAXX)
00356                 vx *= -1;
00357         if (gety() <= MINY || gety() >= MAXY)
00358                 vy *= -1;
00359 }

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