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 "massObject.h" 00021 00027 massObject::massObject(spriteManager* newsm) 00028 : spriteObject(newsm), grounded(false), wasGrounded(false), bStasis(false) 00029 { 00030 #ifdef __MDDEBUG 00031 className = "massObject"; 00032 macros::debugMessage(className, "constructor"); 00033 #endif 00034 setCollision(COL_SOLID); 00035 setCheckCollision(true); 00036 } 00037 00038 massObject::~massObject() 00039 { 00040 00041 } 00042 00047 void massObject::updateSprite() 00048 { 00049 spriteObject::updateSprite(); //move sprite first 00050 00051 wasGrounded = grounded; 00052 if (!isOnGround() && !bStasis) 00053 { 00054 vy += GRAVITY; 00055 if (vy > TERMINALVEL) 00056 vy = TERMINALVEL; 00057 checkPenetration(); 00058 } 00059 00060 grounded = false; //is re-checked in collidingWith() later in the tick 00061 } 00062 00068 void massObject::collidingWith(spriteObject *other) 00069 { 00070 if (isStandingOn(const_cast<spriteObject*>(other))) 00071 { 00072 grounded = true; 00073 vy = 0; 00074 } 00075 } 00076 00081 void massObject::checkPenetration() 00082 { 00083 for (vector<spriteObject*>::iterator it = sm->gameSprites.begin(); it != sm->gameSprites.end(); ++it) 00084 { 00085 if (*it == this || !(*it)->isBaseable()) 00086 continue; 00087 if (inVertPlaneOf(*it) && isOver(*it)) 00088 { 00089 y += vy; 00090 if (isUnder(*it) || inHorizPlaneOf(*it)) 00091 { 00092 y -= vy; 00093 //round y off first 00094 s16 rounds = y % 256; 00095 y += rounds; 00096 //adjust vertical velocity accordingly. 00097 vy = (*it)->getTop() - getBottom(); 00098 vy = vy<<8; 00099 } else { 00100 y -= vy; 00101 } 00102 } 00103 } 00104 }