C:/DevKitPro/!MDuel/source/wp_boomerang_proj.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 "wp_boomerang_proj.h"
00021 #include "player.h"
00022 #include "gameManager.h"
00023 #include "wp_boomerang.h"
00024 
00025 #include <math.h>
00026 
00027 wp_boomerang_proj::wp_boomerang_proj(spriteManager* newsm, Player* p, wp_boomerang* w) :
00028         spriteObject(newsm), weapon(w), owner(p), bReturning(false), returnx(0), returny(0)
00029 {
00030         #ifdef __MDDEBUG
00031         className = "wp_boomerang_proj";
00032         macros::debugMessage(className, "constructor");
00033         #endif
00034         gameManager *gm = dynamic_cast<gameManager *>(sm);
00035         setPallete(gm->pickupSprite.palleteID);
00036         //GFX warning!
00037         giveSprite(gm->pickupSprite.spriteData, OBJ_SIZE_16X16, 8, 8, 60);
00038         setBounds(-2, 3, 3, -2);
00039         setAnim(20, 23, ANIMSPEED);
00040         setCollision(COL_SOLID);
00041         setLayer(2);
00042         #ifdef __WITHSOUND
00043         playSound(&gm->boomerangLoop, true);
00044         #endif
00045 }
00046 
00047 wp_boomerang_proj::~wp_boomerang_proj()
00048 {
00049         if (weapon != NULL)
00050                 weapon->boomerangReturned();
00051 }
00052 
00053 void wp_boomerang_proj::updateSprite()
00054 {
00055         if (getx() < -16 || getx() > 271)
00056         {
00057                 if (!bReturning || owner->isDisabled() || !owner->hasBoomerang() || weapon == NULL)     //out of screen and not returning
00058                 {
00059                         destroy();
00060                         return;
00061                 }
00062                 vx = 0;
00063         } else if ((getx() <= 0) || (getx() >= 255))
00064                 returnToPlayer();
00065         else if (y >= (s32)SCREENH+4096)        //fell out of bottom so make a splash, go low enough to hide death FX
00066         {
00067                 #ifdef __WITHSOUND
00068                 playSound(&owner->gm->smallSplash);
00069                 #endif
00070                 //GFX warning!
00071                 u8 f[3] = {13, 14, 15};
00072                 vector<u8> temp(f, f+3);
00073                 sm->createSingleFireSprite(owner->gm->FXSprite.palleteID, owner->gm->FXSprite.spriteData, temp, TICKSPERFRAME*2, getx(), gameManager::MALLOWYPOS, OBJ_SIZE_32X32, 16, 16);
00074                 destroy();
00075                 return;
00076         }
00077         
00078         if (bReturning)
00079                 returnTick();
00080         
00081         spriteObject::updateSprite();
00082 }
00083 
00084 void wp_boomerang_proj::returnTick()
00085 {
00086         if (!owner->isDisabled() && owner->hasBoomerang() && weapon != NULL)
00087         {
00088                 returnx = owner->getx();
00089                 returny = owner->gety();
00090         } else {                                                                //player has died, so just fly away inconspicuously
00091                 returnx = (vx > 0 ? 306 : -50);         //basically move it off the screen is the point here
00092                 returny = gety();
00093         }
00094         
00095         s32 myx = getx();
00096         s32 myy = gety();
00097         
00098         s32 dist = (s32)sqrt((myx-returnx)*(myx-returnx)+(myy-returny)*(myy-returny));
00099         
00100         setRawSpeed(getRawvx()-((myx-returnx)/(dist/RETURNSTR)), getRawvy()-((myy-returny)/(dist/RETURNSTR)));
00101 }

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