C:/DevKitPro/!MDuel/source/weapon.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 "weapon.h"
00021 #include "player.h"
00022 
00029 Weapon::Weapon(Player *p) : 
00030         pawn(p), canFireStanding(false), canFireInAir(false), canFireCrouching(false), canMoveWhileFiring(false), 
00031         ammo(-1), bHeldFire(false), fireAnimSpeed(spriteObject::TICKSPERFRAME), bFiring(false), bWasFiring(false)
00032 {
00033         #ifdef __MDDEBUG
00034         className = "weapon";
00035         macros::debugMessage(className, "constructor");
00036         #endif
00037 }
00038 
00039 Weapon::~Weapon()
00040 {
00041         #ifdef __MDDEBUG
00042         macros::debugMessage(className, "destructor");
00043         #endif
00044         stopFiring();
00045         pawn->weaponDestroyed();
00046 }
00047 
00054 bool Weapon::fire()
00055 {
00056         if (pawn->isOnRope())
00057                 return false;
00058         
00059         if (pawn->isOnGround() && pawn->isCrouched())
00060                 bFiring = canFireCrouching;
00061         else if (pawn->isOnGround())
00062                 bFiring = canFireStanding;
00063         else
00064                 bFiring = canFireInAir;
00065         
00066         if (bFiring && !bHeldFire)
00067         {
00068                 weaponFireAction();
00069                 if (bFiring)    //this gives weaponFireAction in child classes a chance to override the animation playing
00070                         handleMovementAndAmmo();
00071         }
00072         
00073         return bFiring;
00074 }
00075 
00079 void Weapon::stopFiring()
00080 {
00081         #ifdef __MDDEBUG
00082         macros::debugMessage(className, "stopFiring");
00083         #endif
00084         bFiring = false;
00085 }
00086 
00090 void Weapon::weaponTick()
00091 {
00092         if (bHeldFire && bFiring)
00093         {
00094                 weaponFireAction();
00095                 handleMovementAndAmmo();
00096         }
00097         bWasFiring = bFiring;
00098 }
00099 
00104 void Weapon::handleMovementAndAmmo()
00105 {
00106         if (!canMoveWhileFiring)
00107                 pawn->setvx(0);
00108         
00109         if (firingAnim.size() > 0 && !bHeldFire)
00110         {
00111                 pawn->setArbitraryAnim(firingAnim, false, fireAnimSpeed);
00112                 pawn->setInputInterrupt(fireAnimSpeed * firingAnim.size());
00113         }
00114                 
00115         if (ammo != -1)         //negative 1 means unlimited ammo
00116                 ammo--;
00117         if (ammo == 0)
00118                 delete this;
00119 }

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