Changeset 177 for code/branches/main_reto_vs05/src/weapon_manager.cc
- Timestamp:
- Nov 7, 2007, 12:39:30 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/main_reto_vs05/src/weapon_manager.cc
r169 r177 27 27 28 28 #include "OgreSceneManager.h" 29 #include "OgreEntity.h" 30 #include "OgreSceneNode.h" 31 #include "OgreVector3.h" 32 #include "OgreStringConverter.h" 29 33 30 34 #include "weapon.h" 35 #include "bullet.h" 36 #include "bullet_manager.h" 31 37 #include "weapon_manager.h" 38 39 #define ACTION_LIST_SIZE 4 32 40 33 41 … … 38 46 39 47 WeaponManager::WeaponManager(SceneManager *sceneMgr, SceneNode *node, 40 int slotSize) 41 : sceneMgr_(sceneMgr), node_(node), slotSize_(slotSize), slotIndex_(0) 48 BulletManager *bulletManager, int slotSize) 49 : sceneMgr_(sceneMgr), node_(node), slotSize_(slotSize), slotIndex_(0), 50 bulletCounter_(0), primaryFireRequest_(false), currentState_(IDLE), 51 secondaryFireRequest_(false), selectedWeapon_(0), 52 bulletManager_(bulletManager), 53 actionListReadIndex_(0), actionListWriteIndex_(0) 42 54 { 43 55 slots_ = new Weapon*[slotSize]; 56 actionList_ = new Action[ACTION_LIST_SIZE]; 57 for (int i = 0; i < ACTION_LIST_SIZE; i++) 58 actionList_[i] = NOTHING; 44 59 } 45 60 … … 49 64 if (slots_) 50 65 delete slots_; 66 if (actionList_) 67 delete actionList_; 51 68 } 52 69 … … 54 71 bool WeaponManager::addWeapon(const Ogre::String &name) 55 72 { 73 if (!weaponList_s) 74 return false; 75 56 76 if (name == weaponList_s[0]->name_) 57 77 { 58 78 // this is ugly, but for the time being, it has to fit. 79 selectedWeapon_ = slotIndex_; 59 80 slots_[slotIndex_++] = weaponList_s[0]; 60 81 return true; … … 65 86 66 87 88 bool WeaponManager::addAction(const Action act) 89 { 90 if (actionList_[actionListWriteIndex_] == NOTHING) 91 { 92 actionList_[actionListWriteIndex_] = act; 93 actionListWriteIndex_ = (actionListWriteIndex_ + 1) % ACTION_LIST_SIZE; 94 return true; 95 } 96 else 97 return false; 98 } 99 100 101 void WeaponManager::primaryFireRequest() 102 { 103 primaryFireRequest_ = true; 104 } 105 106 107 void WeaponManager::primaryFire() 108 { 109 currentState_ = PRIMARY_FIRE; 110 111 // TODO: add the name of the weapon manager. but for that, 112 // the factory is required. 113 SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode( 114 "BulletNode" + StringConverter::toString(bulletCounter_), 115 node_->getWorldPosition(), node_->getWorldOrientation()); 116 temp->setScale(Vector3(1, 1, 1) * 10); 117 temp->yaw(Degree(-90)); 118 Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity" 119 + StringConverter::toString(bulletCounter_++), "Barrel.mesh"); 120 Vector3 speed = (node_->getOrientation() * Vector3(0, 0, -1)) 121 .normalisedCopy() * slots_[selectedWeapon_]->bulletSpeed_; 122 bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed)); 123 124 currentState_ = IDLE; 125 } 126 127 128 void WeaponManager::secondaryFireRequest() 129 { 130 secondaryFireRequest_ = true; 131 } 132 133 void WeaponManager::secondaryFire() 134 { 135 } 136 137 138 bool WeaponManager::tick(unsigned long time, Real deltaTime) 139 { 140 // return if no weapon has been added 141 if (!slots_[slotIndex_]) 142 return true; 143 144 switch (currentState_) 145 { 146 case IDLE: 147 // first, process actions 148 if (actionList_[actionListReadIndex_] != NOTHING) 149 { 150 actionListReadIndex_ = (actionListReadIndex_ + 1) % ACTION_LIST_SIZE; 151 break; 152 } 153 154 switch (actionList_[actionListReadIndex_]) 155 { 156 case RELOAD: 157 break; 158 159 case ZOOM_IN: 160 break; 161 162 case ZOOM_OUT: 163 break; 164 165 default: 166 break; 167 } 168 169 // secondly, execute firing 170 if (primaryFireRequest_) 171 primaryFire(); 172 else if (secondaryFireRequest_) 173 secondaryFire(); 174 175 break; 176 177 case PRIMARY_FIRE: 178 break; 179 180 case SECONDARY_FIRE: 181 break; 182 183 case RELOADING: 184 break; 185 } 186 187 primaryFireRequest_ = false; 188 secondaryFireRequest_ = false; 189 190 return true; 191 } 192 193 67 194 // static 68 195 bool WeaponManager::loadWeapons() 69 196 { 70 weaponList_s[0] = new Weapon("Barrel Gun", 10, 2); 197 weaponList_s = new Weapon*[5]; 198 for (int i = 0; i < 5; i++) 199 weaponList_s[i] = NULL; 200 weaponList_s[0] = new Weapon("Barrel Gun", 10, 2, 500); 71 201 return true; 72 202 } … … 76 206 void WeaponManager::destroyWeapons() 77 207 { 78 delete weaponList_s[0]; 208 if (weaponList_s) 209 { 210 for (int i = 0; i < 5; i++) 211 if (weaponList_s[i]) 212 delete weaponList_s[i]; 213 delete weaponList_s; 214 } 79 215 } 80 216
Note: See TracChangeset
for help on using the changeset viewer.