C:/DevKitPro/!MDuel/source/wp_weasel_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_weasel_proj.h"
00021 #include "player.h"
00022 #include "floorTile.h"
00023 #include "gameManager.h"
00024 #include "macros.h"
00025 
00026 const s8 wp_weasel_proj::standingBounds[4] = {-13, 2, 0, -7};
00027 const s8 wp_weasel_proj::hangingBounds[4] = {0, 2, 13, -7};
00028 const s8 wp_weasel_proj::fallingBounds[4] = {-7, 2, 7, -7};
00029 
00030 wp_weasel_proj::wp_weasel_proj(spriteManager* newsm, Player* p) : 
00031         massObject(newsm), owner(p), idleTime(0), justStoppedIdling(false)
00032 {
00033         #ifdef __MDDEBUG
00034         className = "wp_weasel_proj";
00035         macros::debugMessage(className, "constructor");
00036         #endif
00037         gameManager *gm = dynamic_cast<gameManager *>(sm);
00038         setPallete(gm->FXSprite.palleteID);
00039         //GFX warning!
00040         giveSprite(gm->FXSprite.spriteData, OBJ_SIZE_32X32, 16, 16, 60);
00041         setBounds(standingBounds[0], standingBounds[1], standingBounds[2], standingBounds[3]);
00042         setFrame(26);
00043         setFlipped(!owner->getFlippedh(), false);
00044         setIdlePeriod(INITIALDELAY);
00045         setCollision(COL_SOLID);
00046         setCheckCollision(true);
00047         setLayer(2);
00048         //setSoundChannel(SLOT_WEASEL);
00049         playRandomSnarl();
00050 }
00051 
00052 wp_weasel_proj::~wp_weasel_proj()
00053 {
00054         
00055 }
00056 
00057 void wp_weasel_proj::updateSprite()
00058 {
00059         if (getx() < -16 || getx() > 271)       //out of the screen now
00060         {
00061                 destroy();
00062                 return;
00063         } else if (y >= (s32)SCREENH+4096)      //fell out of bottom so make a splash, go low enough to hide death FX
00064         {
00065                 #ifdef __WITHSOUND
00066                 playSound(&owner->gm->bigSplash);
00067                 #endif
00068                 //GFX warning!
00069                 u8 f[3] = {13, 14, 15};
00070                 vector<u8> temp(f, f+3);
00071                 sm->createSingleFireSprite(owner->gm->FXSprite.palleteID, owner->gm->FXSprite.spriteData, temp, TICKSPERFRAME*2, getx(), gameManager::MALLOWYPOS, OBJ_SIZE_32X32, 16, 16);
00072                 destroy();
00073                 return;
00074         }
00075         
00076         //bouncing off the walls
00077         if (getLeft() <= 0)
00078         {
00079                 runRight();
00080         } else if (getRight() >= 255)
00081         {
00082                 runLeft();
00083         }
00084         
00085         if (idleTime == 0)
00086         {
00087                 if (PA_RandMax(30) > 29)
00088                 {
00089                         changeDirection();
00090                         playRandomSnarl();
00091                 }
00092                 
00093                 if (!isOnGround() && wasOnGround())
00094                 {
00095                         hangDown();
00096                         return;
00097                 }
00098                 
00099                 if (justStoppedIdling)
00100                 {
00101                         changeDirection();
00102                         playWalking();
00103                         justStoppedIdling = false;
00104                 }
00105         }
00106         else {
00107                 vx = 0;
00108                 if (isOnGround())
00109                         setFrame(frame);
00110                 idleTime--;
00111                 if (idleTime == 0)
00112                         justStoppedIdling = true;
00113         }
00114         
00115         massObject::updateSprite();
00116 }
00117 
00118 void wp_weasel_proj::playWalking()
00119 {
00120         u8 f[4] = {24, 25, 26, 25};
00121         vector<u8> temp(f, f+4);
00122         setArbitraryAnim(temp, true, WALKANIMSPEED);
00123 }
00124 
00125 void wp_weasel_proj::playFalling()
00126 {
00127         u8 f[8] = {27, 28, 29, 30, 29, 28, 27, 26};
00128         vector<u8> temp(f, f+8);
00129         setArbitraryAnim(temp, true, 30/8);
00130 }
00131 
00132 void wp_weasel_proj::hangDown()
00133 {
00134         vx = 0;
00135         vy = 0;
00136         setIdlePeriod(HANGDELAY);
00137         playFalling();
00138 }
00139 
00140 bool wp_weasel_proj::atEdge()
00141 {
00142         bool aboutToFall = true;
00143         for (vector<spriteObject*>::iterator it = sm->gameSprites.begin(); it != sm->gameSprites.end(); ++it)
00144         {
00145                 if (*it == this || !(*it)->isBaseable())
00146                         continue;
00147                 if ((*it)->pointCollision((flippedh ? getRight() : getLeft()), getBottom()+2))
00148                 {
00149                         aboutToFall = false;
00150                         break;
00151                 }
00152         }
00153         return aboutToFall;
00154 }
00155 
00156 void wp_weasel_proj::playRandomSnarl()
00157 {
00158         #ifdef __WITHSOUND
00159         gameManager *gm = dynamic_cast<gameManager*>(sm);
00160         playSound(&gm->weaselSounds[PA_RandMax(6)]);
00161         #endif
00162 }

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