C:/DevKitPro/!MDuel/source/player.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 "player.h"
00021 #include "pickup.h"
00022 #include "weapon.h"
00023 #include "gameManager.h"
00024 #include "weaponIncludes.h"
00025 #include "menuBottom.h"
00026 
00027 //some shortcuts to make life easier
00028 #define HU (Pad.Held.Up && !bIgnoreInput)
00029 #define HR (Pad.Held.Right && !bIgnoreInput)
00030 #define HD (Pad.Held.Down && !bIgnoreInput)
00031 #define HL (Pad.Held.Left && !bIgnoreInput)
00032 #define HA (Pad.Held.A && !bIgnoreInput)
00033 #define HB (Pad.Held.B && !bIgnoreInput)
00034 #define HX (Pad.Held.X && !bIgnoreInput)
00035 #define HY (Pad.Held.Y && !bIgnoreInput)
00036 #define HRT (Pad.Held.R && !bIgnoreInput)
00037 #define HLT (Pad.Held.L && !bIgnoreInput)
00038 #define NU (Pad.Newpress.Up && !bIgnoreInput)
00039 #define NR (Pad.Newpress.Right && !bIgnoreInput)
00040 #define ND (Pad.Newpress.Down && !bIgnoreInput)
00041 #define NL (Pad.Newpress.Left && !bIgnoreInput)
00042 #define NA (Pad.Newpress.A && !bIgnoreInput)
00043 #define NB (Pad.Newpress.B && !bIgnoreInput)
00044 #define NX (Pad.Newpress.X && !bIgnoreInput)
00045 #define NY (Pad.Newpress.Y && !bIgnoreInput)
00046 #define NRT (Pad.Newpress.R && !bIgnoreInput)
00047 #define NLT (Pad.Newpress.L && !bIgnoreInput)
00048 /*#define RU Pad.Released.Up && !bIgnoreInput
00049 #define RR Pad.Released.Right && !bIgnoreInput
00050 #define RD Pad.Released.Down && !bIgnoreInput
00051 #define RL Pad.Released.Left && !bIgnoreInput
00052 #define RA Pad.Released.A && !bIgnoreInput
00053 #define RB Pad.Released.B && !bIgnoreInput
00054 #define RX Pad.Released.X && !bIgnoreInput
00055 #define RY Pad.Released.Y && !bIgnoreInput
00056 #define RRT Pad.Released.R && !bIgnoreInput
00057 #define RLT Pad.Released.L && !bIgnoreInput*/
00058 
00064 Player::Player(gameManager *newgm)
00065         : massObject(dynamic_cast<spriteManager*>(newgm)), gm(newgm), lastCollision(CS_NONE), playerNum(-1), 
00066         bCrouching(false), bRolling(false), bUnstable(false), justJumped(false), bIgnoreInput(false), startx(0), 
00067         starty(0), startFlipped(false), touchingRope(NULL), wasTouchingRope(NULL), bClimbingRope(false), currWeapon(NULL),
00068         inputInterrupt(0), forceAnimUpdate(false), lastWeaponChangeTime(0), weaponJustCleared(false), nettedStrength(0), 
00069         bJustUnwarped(false)
00070 {
00071         #ifdef __MDDEBUG
00072         className = "player";
00073         macros::debugMessage(className, "constructor");
00074         #endif
00075         setBounds(standingBounds[0], standingBounds[1], standingBounds[2], standingBounds[3]);
00076         setCollision(COL_SOLID);
00077         setCheckCollision(true);
00078         setLayer(2);
00079         
00080         //initialise the weapon timer
00081         lastWeaponChangeTime = Tick(gm->statTimerID);
00082 }
00083 
00088 Player::~Player()
00089 {
00090         PA_SetSpriteRotDisable(gm->screen, spriteID);
00091         
00092         clearWeapon();
00093 }
00094 
00096 const s8 Player::standingBounds[4] = {-11, 5, 11, -5};
00098 const s8 Player::fallingBounds[4] = {-11, 5, 11, -5};
00100 const s8 Player::crouchingBounds[4] = {-2, 5, 11, -5};
00101 
00112 void Player::setControls(u8 nplayerNum)
00113 {
00114         playerNum = nplayerNum;
00115         //if (nplayerNum==0 || nplayerNum==1)
00116         //      setSoundChannel(SLOT_PLAYER1);
00117         //else if (nplayerNum==2)
00118         //      setSoundChannel(SLOT_PLAYER2);
00119 }
00120 
00124 void Player::checkPad()
00125 {
00126         switch (playerNum)
00127         {
00128                 case -1:                //disable controls
00129                         //vx = 0;
00130                 break;
00131                 case 0:                 //singleplayer controls
00132                         basicInput(HR, HL, HA, HD, NR, NL, NA, ND, HB, NB);
00133                 break;  
00134                 case 1:                 //P1 controls
00135                         basicInput(HR, HL, HU, HD, NR, NL, NU, ND, HLT, NLT);
00136                 break;
00137                 case 2:                 //P2 controls
00138                         basicInput(HA, HY, HX, HB, NA, NY, NX, NB, HRT, NRT);
00139                 break;
00140                 case 3:                 //wifi controls
00141                         //TODO!
00142                 break;
00143         }
00144         
00145         if (inputInterrupt > 0)
00146                 inputInterrupt--;
00147         wasTouchingRope = touchingRope;
00148         touchingRope = NULL;    //will be recalculated in collision cycle
00149 }
00150 
00166 void Player::basicInput(bool hr, bool hl, bool hu, bool hd, bool nr, bool nl, bool nu, bool nd, bool hf, bool nf)
00167 {
00168         //weapon animation refreshes
00169         if (inputInterrupt == 0 && forceAnimUpdate)
00170         {
00171                 if (isOnRope()) {
00172                         if (vy > 0)
00173                                 playClimbingDown();
00174                         else
00175                                 playClimbingUp();
00176                 }
00177                 else if (isOnGround())
00178                         playRunning();
00179                 else if (bUnstable)
00180                         playPushedForward();
00181                 else
00182                         playFalling();
00183                 
00184                 if (hl || hr)
00185                         setFlipped(hl, getFlippedv());
00186                         
00187                 forceAnimUpdate = false;
00188         }
00189         
00190         //netted physics
00191         if (nettedStrength > 0)
00192         {
00193                 handleNetted(nu);
00194                 return;
00195         }
00196         
00197         //bouncing off the walls
00198         if (getLeft() <= 0)
00199         {
00200                 setFlipped(true);
00201                 bounce();
00202         } else if (getRight() >= 255)
00203         {
00204                 setFlipped(false);
00205                 bounce();
00206         }
00207         
00208         //regular controls
00209         else if (inputInterrupt == 0) {
00210                 if (bClimbingRope)
00211                 {
00212                         if (touchingRope == NULL)
00213                         {
00214                                 vy = 0;
00215                                 vx = (hr - hl) * WALKSPEED;
00216                                 bClimbingRope = false;
00217                                 justfell();
00218                         } else {
00219                                 vy = (hd - hu) * CLIMBSPEED;
00220                                 //don't allow to climb off rope via up/down keys
00221                                 if (touchingRope->childRopes[touchingRope->childRopes.size()-1]->getBottom() < getBottom() && vy > 0)
00222                                         vy = 0;
00223                                 else if (touchingRope->childRopes[0]->getTop() > getTop() && vy < 0)
00224                                         vy = 0;
00225                                 if (nd)
00226                                         playClimbingDown();
00227                                 else if (nu)
00228                                         playClimbingUp();
00229                                 if (vy == 0) setFrame(frame);
00230                                 if (hr || hl)   //jump off!
00231                                 {
00232                                         vx = (hr - hl) * WALKSPEED;
00233                                         vy = 0;
00234                                         bClimbingRope = false;
00235                                         setFlipped(hl);
00236                                         justfell();
00237                                 }
00238                         }
00239                 } else if (isOnGround())
00240                 {                       
00241                         if (!wasOnGround())
00242                                 justlanded(hr, hl);     //reset collision bounds, etc
00243                         
00244                         bUnstable = false;
00245                         
00246                         if (touchingRope != NULL && (hu || nu || hd || nd) && !(hl || hr) && !bCrouching && !bRolling)
00247                         {
00248                                 climbRope(hd);
00249                         } else if (bRolling)
00250                         {
00251                                 if (arbitraryAnim == 0) //anim finished, so stop moving (PROBABLY A BAD IDEA)
00252                                 {
00253                                         bRolling = false;
00254                                         bCrouching = true;
00255                                         
00256                                         //recovered from a roll, so reset collision & warp usage state
00257                                         lastCollision = CS_NONE;
00258                                         bJustUnwarped = false;
00259                                 }
00260                         } else if (bCrouching)
00261                         {
00262                                 vx = 0;
00263                                 if (!hd)
00264                                         uncrouch(hr, hl);
00265                         } else {
00266                                 vx = (hr - hl) * WALKSPEED;             //walking speed
00267                                 if (nr)
00268                                 {
00269                                         setFlipped(false);
00270                                         playRunning();
00271                                 }
00272                                 else if (nl)
00273                                 {
00274                                         setFlipped(true);
00275                                         playRunning();
00276                                 } else if (hd)  //crouch
00277                                         crouch();
00278                                 else if (!hr && !hl)
00279                                 {
00280                                         //standing still
00281                                         playIdle();
00282                                 }
00283                                 
00284                                 if (nu)
00285                                         jump();
00286                         }
00287                 } else {
00288                         if (wasOnGround() && !justJumped)
00289                                 justfell();
00290                         justJumped = false;
00291                         if (usingChut())                //parachut midair controls
00292                         {
00293                                 vx = (vx==0 && !hr && !hl ? 0 : (flippedh ? WALKSPEED*-1 : WALKSPEED));
00294                                 //vx = (flippedh ? WALKSPEED*-1 : WALKSPEED);
00295                                 //vx = (hr - hl) * WALKSPEED;
00296                                 if (nr)
00297                                         setFlipped(false);
00298                                 else if (nl)
00299                                         setFlipped(true);
00300                         }
00301                 }
00302         }
00303         
00304         //weapon stuffs
00305         if (currWeapon != NULL)
00306         {
00307                 if (nf && !currWeapon->isFiring())
00308                         currWeapon->fire();
00309                 if (!hf && currWeapon->isFiring())
00310                         currWeapon->stopFiring();
00311         }
00312 }
00313 
00314 //=================================================================
00315 
00321 void Player::handleNetted(bool upPressed)
00322 {
00323         setFrame(67);
00324         setRotation(getx()*NETSPINSPEED);
00325         
00326         s32 testvel = vx >= 0 ? vx : vx * -1;
00327         if (testvel < NETROLLDECEL)
00328                 vx -= (vx > 0 ? testvel : testvel * -1);
00329         else
00330                 vx -= (vx > 0 ? NETROLLDECEL : NETROLLDECEL * -1);
00331         
00332         if (upPressed)
00333         {
00334                 nettedStrength--;
00335                 if (isOnGround())
00336                         vy += NETJUMPIMPULSE;
00337         }
00338         if (nettedStrength == 0)
00339                 stopNetted();
00340 }
00341 
00348 void Player::startNetted()
00349 {
00350         bClimbingRope = false;
00351         nettedStrength = PA_RandMinMax(6, 10);
00352         enableRotation();
00353         setBounds(crouchingBounds[0], crouchingBounds[1], crouchingBounds[2], crouchingBounds[3]);
00354 }
00355 
00359 void Player::stopNetted()
00360 {
00361         nettedStrength = 0;
00362         disableRotation();
00363         setFlipped(flippedh);   //have to refresh any flipping that might be applied
00364         setBounds(standingBounds[0], standingBounds[1], standingBounds[2], standingBounds[3]);
00365 }
00366 
00367 //=================================================================
00368 
00375 void Player::collidingWith(spriteObject *other)
00376 {
00377         bool dontMove = false;  //true if should bounce straight up
00378         
00379         //=====================================================================================
00380         //PLAYER
00381         if (dynamic_cast<Player*>(other) != NULL)
00382         {
00383                 Player *o = dynamic_cast<Player*>(other);
00384                 
00385                 if (currWeapon != NULL && currWeapon->isFiring())
00386                         currWeapon->stopFiring();
00387                 if (o->currWeapon != NULL && o->currWeapon->isFiring())
00388                         o->currWeapon->stopFiring();
00389                 
00390                 //shield handling
00391                 if (o->hasShield() && hasShield())
00392                 {
00393                         if (isFacing(o) && !o->isFacing(this))
00394                         {
00395                                 o->collideNormally(this);
00396                                 o->lastCollision = CS_SHIELDPLAYER;
00397                         }
00398                         else if (o->isFacing(this) && !isFacing(o))
00399                         {
00400                                 collideNormally(o);
00401                                 lastCollision = CS_SHIELDPLAYER;
00402                         }
00403                         else {
00404                                 o->collideNormally(this);
00405                                 collideNormally(o);
00406                                 o->lastCollision = CS_SHIELDPLAYER;
00407                                 lastCollision = CS_SHIELDPLAYER;
00408                         }
00409                         return;
00410                 }
00411                 else if (o->hasShield() && !hasShield() && o->isFacing(this))
00412                 {
00413                         collideNormally(o);
00414                         lastCollision = CS_SHIELDPLAYER;
00415                         return;
00416                 }
00417                 else if (hasShield() && !o->hasShield() && isFacing(o))
00418                 {
00419                         o->collideNormally(this);
00420                         o->lastCollision = CS_SHIELDPLAYER;
00421                         return;
00422                 }
00423                 
00424                 //lightning handling
00425                 if (o->has1000V() && !has1000V())       //we die
00426                 {
00427                         gm->playerLightningd(this);
00428                         return;
00429                 }       
00430                 else if (has1000V() && !o->has1000V())  //they die
00431                 {
00432                         gm->playerLightningd(o);
00433                         return;
00434                 }
00435                 else if (has1000V() && o->has1000V())   //nobody dies, weapons destroyed
00436                 {
00437                         clearWeapon();
00438                         o->clearWeapon();
00439                 }
00440                 
00441                 //regular contact
00442                 if (!bCrouching || (bCrouching && (o->bRolling || !o->wasOnGround())))
00443                 {
00444                         //if other player gets under your feet
00445                         if ((o->bCrouching || o->bRolling) && wasOnGround() && !bCrouching && !bRolling)
00446                         {
00447                                 dontMove = (vx == 0 && o->bRolling);
00448                                 bounce(true);
00449                                 if (dontMove) vx = 0;
00450                                 
00451                                 ignoreUntilUntouched = other;
00452                                 
00453                                 vy = JUMPIMPULSE*2/3;
00454                                 
00455                                 if (o->usingInvis())
00456                                         lastCollision = CS_INVISPLAYER;
00457                                 else if (o->bJustUnwarped)
00458                                         lastCollision = CS_WARPEDPLAYER;
00459                                 else
00460                                         lastCollision = CS_BASICHIT;
00461                         } 
00462                         //if you get under other player's feet
00463                         else if (bRolling && o->wasOnGround() && !o->bCrouching && !o->bRolling)
00464                         {
00465                                 dontMove = (o->getvx() == 0);
00466                                 o->bounce(true);
00467                                 if (dontMove) o->setvx(0);
00468                                 
00469                                 ignoreUntilUntouched = other;
00470                                 
00471                                 o->vy = JUMPIMPULSE*2/3;
00472                                 
00473                                 if (usingInvis())
00474                                         o->lastCollision = CS_INVISPLAYER;
00475                                 else if (bJustUnwarped)
00476                                         o->lastCollision = CS_WARPEDPLAYER;
00477                                 else
00478                                         o->lastCollision = CS_BASICHIT;
00479                         }
00480                         //otherwise we must be talking a normal bump!
00481                         else {
00482                                 o->collideNormally(this);
00483                                 collideNormally(o);
00484                                 
00485                                 if (o->usingInvis())
00486                                         lastCollision = CS_INVISPLAYER;
00487                                 else if (o->bJustUnwarped)
00488                                         lastCollision = CS_WARPEDPLAYER;
00489                                 else
00490                                         lastCollision = CS_BASICHIT;
00491                                 
00492                                 if (usingInvis())
00493                                         o->lastCollision = CS_INVISPLAYER;
00494                                 else if (bJustUnwarped)
00495                                         o->lastCollision = CS_WARPEDPLAYER;
00496                                 else
00497                                         o->lastCollision = CS_BASICHIT;
00498                         }
00499                 }
00500         }
00501         //=====================================================================================
00502         //ROPE
00503         else if (dynamic_cast<Rope*>(other) != NULL)
00504         {
00505                 Rope *o = dynamic_cast<Rope*>(other);
00506                 s16 diff = getx() - o->getx();
00507                 if (diff < 0) diff *= -1;
00508                 
00509                 Rope * parent = o->getParent(); 
00510                 diff < Rope::ROPETOLERANCE ? touchingRope = parent : touchingRope = NULL;
00511         }
00512         //=====================================================================================
00513         
00514         else if (dynamic_cast<Pickup*>(other) != NULL)
00515         {
00516                 Pickup *o = dynamic_cast<Pickup*>(other);
00517                 o->playerTouchAction(this);
00518                 if (o->getType() != Pickup::PT_TNT)
00519                 {
00520                         #ifdef __WITHSOUND
00521                         playSound(&gm->gotPickup);
00522                         #endif
00523                         o->destroy();
00524                 }
00525         }
00526         //=====================================================================================
00527         
00528         else if (dynamic_cast<wp_mine_proj*>(other) != NULL && wasOnGround())
00529         {
00530                 gm->playerMined(this);
00531                 other->destroy();
00532         }
00533         
00534         else if (dynamic_cast<wp_net_proj*>(other) != NULL)// && dynamic_cast<wp_net_proj*>(other)->owner != this)
00535         {
00536                 if (hasShield() && isFacing(other))
00537                 {
00538                         other->turnAround();
00539                 } else {
00540                         startNetted();
00541                         other->destroy();
00542                 }
00543         }
00544         
00545         else if (dynamic_cast<wp_weasel_proj*>(other) != NULL)
00546         {
00547                 if (hasShield() && isFacing(other))
00548                 {
00549                         other->turnAround();
00550                 } else {
00551                         gm->playerWeaseled(this);
00552                 }
00553         }
00554         
00555         else if (dynamic_cast<wp_boomerang_proj*>(other) != NULL)
00556         {
00557                 wp_boomerang_proj *o = dynamic_cast<wp_boomerang_proj*>(other);
00558                 
00559                 if (o->owner == this)
00560                 {
00561                         if (hasBoomerang() && o->weapon != NULL)
00562                                 o->weapon->boomerangReturned();
00563                         #ifdef __WITHSOUND
00564                         o->stopSound(); //doesnt seem to be working through the destructor as it should...
00565                         #endif
00566                         o->destroy();
00567                 } else {
00568                         if (hasShield() && isFacing(other))
00569                         {
00570                                 other->turnAround();
00571                         } else {
00572                                 bounce(isFacing(o));
00573                                 lastCollision = CS_BOOMERANG;
00574                                 o->returnToPlayer();
00575                         }
00576                 }
00577         }
00578         
00579         //=====================================================================================
00580         
00581         //only check for ground if not climbing a rope
00582         if (!bClimbingRope)
00583                 massObject::collidingWith(other);
00584 }
00585 
00595 bool Player::isColliding(const spriteObject *other, bool checkReverse)
00596 {
00597         const Pickup *p = dynamic_cast<const Pickup*>(other);
00598         if (p != NULL && p->getType() == Pickup::PT_TNT)
00599                 return false;
00600         
00601         return massObject::isColliding(other, checkReverse);
00602 }
00603 
00609 void Player::collideNormally(Player *o)
00610 {
00611         bClimbingRope = false;
00612         if (getx() == o->getx())
00613                 gety() < o->gety() ? bounce(flippedh) : bounce(!flippedh);
00614         else
00615                 getx() < o->getx() ? bounce(flippedh) : bounce(!flippedh);
00616         vy = JUMPIMPULSE*2/3;
00617 }
00618 
00625 void Player::updateSprite()
00626 {
00627         //calling this first gives the weapon a chance to override anims, etc
00628         if (currWeapon != NULL)
00629                 currWeapon->weaponTick();
00630                 
00631         //if player is outside the screen (not the bottom) from a death anim, freeze them in place to stop wrapping
00632         if (bStasis && (getx() < -32 || getx() > (s16)(SCREENW>>8) + 32 || gety() < -32))
00633         {
00634                 setvx(0);
00635                 setvy(0);
00636         }
00637         
00638         massObject::updateSprite();
00639         
00640         if (y >= (s32)SCREENH)
00641         {
00642                 gm->playerSank(this);
00643                 y = (s32)SCREENH - 2;
00644         }
00645 }
00646 
00647 //=============================================================
00648 
00656 bool Player::jump(bool bootsJump)
00657 {
00658         if (!isOnGround())
00659                 return false;
00660         //setBasePos(getBottom() - 1);  //move off the ground
00661         justJumped = true;      //stops routine 'just airborne' checks happening
00662         bCrouching = false;
00663         bRolling = false;
00664         vy = JUMPIMPULSE;
00665         if (bootsJump) vy = vy *3/2;
00666         if (vx == 0)
00667                 playJumpedStanding();
00668         else
00669                 playJumpedMoving();
00670         setBounds(fallingBounds[0], fallingBounds[1], fallingBounds[2], fallingBounds[3]);
00671         return true;
00672 }
00673 
00679 bool Player::crouch()
00680 {
00681         if (!isOnGround())
00682                 return false;
00683         bCrouching = true;
00684         if (vx == 0 && !bUnstable)
00685                 playCrouching();
00686         else
00687                 roll();
00688         setBounds(crouchingBounds[0], crouchingBounds[1], crouchingBounds[2], crouchingBounds[3]);
00689         return true;
00690 }
00691 
00697 bool Player::roll(bool backwards)
00698 {
00699         if (!isOnGround())
00700                 return false;
00701         if (!backwards)
00702                 playRolling();
00703         else
00704                 playRollingBack();
00705         bRolling = true;
00706         bCrouching = false;
00707         bUnstable = false;
00708         setBounds(crouchingBounds[0], crouchingBounds[1], crouchingBounds[2], crouchingBounds[3]);
00709         return true;
00710 }
00711 
00717 void Player::bounce(bool pushedForwards)
00718 {
00719         if (currWeapon != NULL && currWeapon->isFiring())
00720                 currWeapon->stopFiring();
00721         justJumped = true;
00722         bUnstable = true;
00723         bCrouching = false;
00724         bRolling = false;
00725         bClimbingRope = false;
00726         setBounds(fallingBounds[0], fallingBounds[1], fallingBounds[2], fallingBounds[3]);
00727         if (pushedForwards)
00728         {
00729                 vx = (flippedh ? -WALKSPEED : WALKSPEED);
00730                 playPushedForward();
00731         } else {
00732                 vx = (flippedh ? WALKSPEED : -WALKSPEED);
00733                 playPushedBackward();
00734         }
00735         //setBasePos(getBottom() - 1);
00736         if (isOnGround())
00737                 vy = JUMPIMPULSE*2/3;
00738 }
00739 
00747 void Player::uncrouch(bool hr, bool hl)
00748 {
00749         bCrouching = false;
00750         
00751         ignoreUntilUntouched = NULL;    //stop the whole tripping thing
00752         
00753         setBounds(standingBounds[0], standingBounds[1], standingBounds[2], standingBounds[3]);
00754         setFlipped((hr-hl==0 ? flippedh : hr-hl < 0), flippedv);
00755         playRunning();
00756 }
00757 
00763 void Player::climbRope(bool hd)
00764 {
00765         if (touchingRope != NULL)
00766                 setPos(touchingRope->getx(), gety());
00767         else if (wasTouchingRope != NULL)               //this is mainly for the hook's way of doing it
00768                 setPos(wasTouchingRope->getx(), gety());
00769         else
00770                 return;
00771         bClimbingRope = true;
00772         hd ? playClimbingDown() : playClimbingUp();
00773 }
00774 
00782 void Player::justlanded(bool hr, bool hl)
00783 {
00784         setBounds(standingBounds[0], standingBounds[1], standingBounds[2], standingBounds[3]);
00785         setFlipped((hr-hl==0 ? flippedh : hr-hl < 0), flippedv);
00786         if (bUnstable)
00787         {
00788                 roll(vx > 0 && flippedh || vx < 0 && !flippedh);
00789         } else {
00790                 vx = 0;
00791                 playRunning();
00792                 lastCollision = CS_NONE;        //back to normal!
00793                 bJustUnwarped = false;          //reset the warp usage state.
00794         }
00795 }
00796 
00801 void Player::justfell()
00802 {
00803         //if (bRolling)
00804         //      bUnstable = true;
00805         bRolling = false;
00806         bCrouching = false;
00807         //if (vx == 0)
00808         //      vx = (flippedh ? -WALKSPEED : WALKSPEED);
00809         setBounds(fallingBounds[0], fallingBounds[1], fallingBounds[2], fallingBounds[3]);
00810         if (!bUnstable)
00811                 playFalling();
00812         else
00813                 vx < 0 && flippedh || vx > 0 && !flippedh ? playPushedForward() : playPushedBackward();
00814 }
00815 
00822 void Player::groundDeleted(collisionState newCollState)
00823 {
00824         justfell();
00825         //vy = FLOOREXPLOSIONIMPULSE;
00826         setPos(getx(), gety()-1);
00827         lastCollision = newCollState;
00828 }
00829 
00835 bool Player::readyForVictory()
00836 {
00837         return (inputInterrupt == 0 && !bStasis && !bUnstable && ((isOnGround() && !bCrouching && !bRolling) || bClimbingRope));                
00838 }
00839 
00840 //==============================================================================
00841 //anims
00842 
00844 void Player::playVictory()
00845 {
00846         if (!gm->menuBase->dieWhileDancing)
00847                 freezePlayer();
00848         if (bClimbingRope)
00849         {
00850                 u8 f[2] = {46, 47};
00851                 vector<u8> temp(f, f+2);
00852                 setArbitraryAnim(temp, false);
00853         } else {
00854                 if (PA_RandMax(1))
00855                 {
00856                         u8 f[6] = {58, 59, 60, 61, 62, 63};
00857                         vector<u8> temp(f, f+6);
00858                         setArbitraryAnim(temp, false);
00859                 } else {
00860                         u8 f[2] = {44, 45};
00861                         vector<u8> temp(f, f+2);
00862                         setArbitraryAnim(temp, false);
00863                 }
00864         }
00865 }
00866 
00868 void Player::playCrouching()
00869 {
00870         u8 f[2] = {6, 5};
00871         vector<u8> temp(f, f+2);
00872         setArbitraryAnim(temp, false);
00873 }
00874 
00876 void Player::playJumpedStanding()
00877 {
00878         u8 f[8] = {6, 12, 13, 14, 15, 16, 17, 21};
00879         vector<u8> temp(f, f+8);
00880         setArbitraryAnim(temp, false, TICKSPERFRAME);
00881 }
00882 
00884 void Player::playJumpedMoving()
00885 {
00886         u8 f[6] = {17, 18, 19, 20, 20, 21};
00887         vector<u8> temp(f, f+6);
00888         setArbitraryAnim(temp, false, TICKSPERFRAME*2);
00889 }
00890 
00892 void Player::playRolling()
00893 {
00894         u8 f[5] = {7, 8, 9, 10, 5};
00895         vector<u8> temp(f, f+5);
00896         setArbitraryAnim(temp, false, TICKSPERFRAME);
00897 }
00898 
00900 void Player::playRollingBack()
00901 {
00902         u8 f[6] = {6, 22, 23, 24, 25, 5};
00903         vector<u8> temp(f, f+6);
00904         setArbitraryAnim(temp, false, TICKSPERFRAME);
00905 }
00906 
00908 void Player::playClimbingDown()
00909 {
00910         u8 f[4] = {41, 40, 39, 42};
00911         vector<u8> temp(f, f+4);
00912         setArbitraryAnim(temp, true, TICKSPERFRAME);
00913 }
00914 
00916 void Player::playClimbingUp()
00917 {
00918         u8 f[4] = {39, 40, 41, 42};
00919         vector<u8> temp(f, f+4);
00920         setArbitraryAnim(temp, true, TICKSPERFRAME);
00921 }
00922 
00923 //===================================================================
00927 void Player::clearWeapon()
00928 {
00929         weaponChange();
00930         weaponJustCleared = true;       //stop weaponDestroyed() from calling weaponChange()
00931         if (currWeapon != NULL)
00932                 delete currWeapon;
00933         currWeapon = NULL;
00934         weaponJustCleared = false;
00935 }
00936 
00940 void Player::weaponChange()
00941 {
00942         u32 newTime = Tick(gm->statTimerID);
00943         u16 numSecs = (newTime-lastWeaponChangeTime) / 1000;
00944         u8 playerID = (this == gm->player1 ? gm->menuBase->player1id : gm->menuBase->player2id);
00945         
00946         u8 weaponID;
00947         if (currWeapon == NULL)
00948                 weaponID = 18;
00949         else
00950                 weaponID = currWeapon->getType();
00951                 
00952         if (!gm->isGamePaused())
00953         {               
00954                 //if we record this when the game is paused we'll get mucho random numbers
00955                 gm->menuBase->scoreTime(playerID, weaponID, numSecs);
00956         }
00957         
00958         lastWeaponChangeTime = newTime;
00959 }
00960 
00961 //Weapon checks, for Weapons that modify touching behaviour
00963 bool Player::has1000V()
00964 {
00965         return dynamic_cast<wp_1000V *>(currWeapon) != NULL;
00966 }
00967 
00969 bool Player::hasShield()
00970 {
00971         //for all intents and purposes, you can't have the shield when on a rope
00972         return dynamic_cast<wp_shield *>(currWeapon) != NULL && !bClimbingRope;
00973 }
00974 
00976 bool Player::usingChut()
00977 {
00978         return dynamic_cast<wp_chut *>(currWeapon) != NULL && currWeapon->isFiring();
00979 }
00980 
00982 bool Player::hasBoomerang()
00983 {
00984         return dynamic_cast<wp_boomerang *>(currWeapon) != NULL;
00985 }
00986 
00988 bool Player::usingMagnet()
00989 {
00990         return dynamic_cast<wp_magnet *>(currWeapon) != NULL && currWeapon->isFiring();
00991 }
00992 
00994 bool Player::usingInvis()
00995 {
00996         return dynamic_cast<wp_invis *>(currWeapon) != NULL && currWeapon->getAmmo() == 1;
00997 }
00998 
00999 //===================================================================
01000 //sounds and effects
01001 
01003 void Player::playWarpEffect()
01004 {
01005         u8 f[3] = {21, 22, 23};
01006         vector<u8> temp(f, f+3);
01007         gm->createSingleFireSprite(gm->FXSprite.palleteID, (this == gm->player1 ? gm->spawnGFX[0] : gm->spawnGFX[1]), temp, TICKSPERFRAME*2, getx(), gety(), OBJ_SIZE_32X32, 16, 16);
01008         #ifdef __WITHSOUND
01009         playSound(&gm->teleport);
01010         #endif
01011 }
01012 
01014 void Player::playSplashEffect()
01015 {
01016         u8 f[4] = {4, 5, 6, 7};
01017         vector<u8> temp(f, f+4);
01018         gm->createSingleFireSprite(gm->FXSprite.palleteID, (this == gm->player1 ? gm->spawnGFX[0] : gm->spawnGFX[1]), temp, spriteObject::TICKSPERFRAME, getx(), gameManager::MALLOWYPOS, OBJ_SIZE_32X32, 16, 16);
01019         #ifdef __WITHSOUND
01020         playSound(&gm->bigSplash);
01021         #endif
01022 }
01023 
01025 void Player::playSkulled()
01026 {
01027         u8 f[5] = {50, 51, 52, 53, 66};
01028         vector<u8> temp(f, f+5);
01029         setArbitraryAnim(temp, false, TICKSPERFRAME);
01030         #ifdef __WITHSOUND
01031         playSound(&gm->skullPickup);
01032         #endif
01033 }
01034 
01036 void Player::playDisintegrated()
01037 {
01038         u8 f[5] = {54, 55, 56, 57, 66};
01039         vector<u8> temp(f, f+5);
01040         setArbitraryAnim(temp, false, TICKSPERFRAME);
01041 }
01042 
01044 void Player::play1000VHitEffect()
01045 {
01046         u8 f[2] = {8, 9};
01047         vector<u8> temp(f, f+2);
01048         gm->createSingleFireSprite(gm->FXSprite.palleteID, (this == gm->player1 ? gm->spawnGFX[0] : gm->spawnGFX[1]), temp, spriteObject::TICKSPERFRAME, getx(), gety(), OBJ_SIZE_32X32, 16, 16);
01049         
01050         setFrame(48);
01051         if (this == gm->player1)
01052                 vx = (getx() < gm->player2->getx() ? POWERHITSPEED*-1 : POWERHITSPEED);
01053         else if (this == gm->player2)
01054                 vx = (getx() < gm->player1->getx() ? POWERHITSPEED*-1 : POWERHITSPEED);
01055         vy = JUMPIMPULSE;
01056         #ifdef __WITHSOUND
01057         playSound(&gm->lightningHit);
01058         #endif
01059 }
01060 
01062 void Player::playMineHitEffect()
01063 {
01064         setFrame(48);
01065         vy = POWERHITSPEED*-1;
01066 }

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