C:/DevKitPro/!MDuel/source/rope.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 "rope.h"
00021 
00030 Rope::Rope(spriteManager *newsm, bool isCap) : spriteObject(newsm), childGFX(0)
00031 {
00032         #ifdef __MDDEBUG
00033         className = "rope";
00034         macros::debugMessage(className, "constructor");
00035         #endif
00036         if (isCap)
00037         {
00038                 setBounds(-8, 8, 8, -8);
00039                 setFrame(4);
00040                 setCollision(COL_NONE);
00041         } else {
00042                 setBounds(-8, 0, 8, 0);
00043                 setFrame(5);
00044                 setCollision(COL_SOLID);
00045         }
00046         setLayer(2);
00047 }
00048 
00049 Rope::~Rope()
00050 {
00051         //spritemanager always handles this garbage cleanup!
00052 }
00053 
00058 void Rope::makeStatic()
00059 {
00060         for (u8 i=0; i<childRopes.size(); ++i)
00061                 childRopes[i]->makeStatic();
00062         spriteObject::makeStatic();
00063 }
00064 
00071 bool Rope::setLength(u8 numRopes)
00072 {
00073         if (numRopes > childRopes.size())       //add ropes
00074         {
00075                 for (u8 i=childRopes.size(); i<numRopes; ++i)
00076                 {
00077                         Rope * temp = new Rope(sm, false);
00078                         temp->setPallete(palleteID);
00079                         temp->giveGFX(childGFX, OBJ_SIZE_16X16, 8, 8);
00080                         temp->setPos(getx(), gety() + centery*2*(i+1));
00081                         temp->parentRope = this;
00082                         childRopes.push_back(temp);
00083                         //sm->gameSprites.push_back(temp);
00084                 }
00085         } else if (numRopes < childRopes.size())        //delete ropes TODO: its old and crashy but im not using it
00086         {
00087                 for (u8 i=childRopes.size()-1; i>=numRopes; i--)
00088                         delete childRopes[i];
00089                 childRopes.erase(childRopes.end() - numRopes, childRopes.end());
00090                 //TODO! not sure if this is working, cos I don't really use it at all :S
00091         }
00092         return true;
00093 }
00094 
00098 void Rope::setPos(s16 nx, s16 ny)
00099 {
00100         spriteObject::setPos(nx, ny);
00101         for (u8 i=0; i<childRopes.size(); ++i)
00102         {
00103                 childRopes[i]->setPos(nx, ny + centery*2*(i+1));
00104         }
00105 }

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