00001 #include "Weapon.h" 00002 #include "Sprite.h" 00003 #include "Person.h" 00004 #include "Parser.h" 00005 #include "glfuncs.h" 00006 #include "Command.h" 00007 #include "CollisionHandler.h" 00008 #include "CommandManager.h" 00009 00010 #include <sstream> 00011 00012 using namespace std; 00013 00014 WeaponPunch::WeaponPunch() 00015 :Weapon() 00016 { 00017 00018 } 00019 00020 WeaponPunch::WeaponPunch(std::string filename, Person *shooter) 00021 :Weapon(filename, shooter) 00022 { 00023 List *info = Parser::parse(filename); 00024 00025 load(info); 00026 00027 delete info; 00028 } 00029 00030 WeaponPunch *WeaponPunch::copy(Person *shooter) 00031 { 00032 WeaponPunch *copy = new WeaponPunch(*this); 00033 copy->_shooter = shooter; 00034 return copy; 00035 } 00036 00037 void WeaponPunch::shoot() 00038 { 00039 if( _framesSinceShoot >= _waitShoot) 00040 { 00041 //This is here to make sure that the sound effect only plays once per shot 00042 00043 vector<Object*> objs; 00044 00045 int pels = 32; 00046 SDL_Rect box; 00047 00048 if(_shooter->getXDirection() == LEFT){ 00049 box = _shooter->getBox(); 00050 box.x-=pels; 00051 _shooter->setPos(box.x, box.y); 00052 objs = CollisionHandler::ObjsColliding( _shooter , true); 00053 box.x+=pels; 00054 _shooter->setPos(box.x, box.y); 00055 } 00056 else{ 00057 box = _shooter->getBox(); 00058 box.x+=pels; 00059 _shooter->setPos(box.x, box.y); 00060 objs = CollisionHandler::ObjsColliding(_shooter , true); 00061 box.x-=pels; 00062 _shooter->setPos(box.x, box.y); 00063 } 00064 00065 for(int i=0; i<objs.size(); i++){ 00066 if(objs[i]->getType()==ENEMY){ 00067 //((Person *)objs[i])->addHealth(-((Person *)objs[i])->getHealth()); 00068 ((Person *)objs[i])->die(); 00069 CommandManager::instance()->execute(new PlaySoundCommand("sounds/punch.wav")); 00070 } 00071 } 00072 00073 00074 _framesSinceShoot = 0; 00075 _ammo -= _ammoSize; 00076 } 00077 }
1.4.6-NO