Changeset 194 for code/branches/main_reto_vs05/src
- Timestamp:
- Nov 11, 2007, 2:24:50 PM (16 years ago)
- Location:
- code/branches/main_reto_vs05/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/main_reto_vs05/src/orxonox_ship.cc
r193 r194 26 26 */ 27 27 28 #include "OgreSceneManager.h" 28 #include "OgreMath.h" 29 #include "OgreVector3.h" 30 #include "OgreQuaternion.h" 29 31 #include "OgreSceneNode.h" 30 32 #include "OgreEntity.h" 31 #include "OgreVector3.h" 32 #include "OgreStringConverter.h" 33 #include "OgreSceneManager.h" 33 34 34 35 #include "inertial_node.h" … … 197 198 * @return Bullet containing speed and entity. 198 199 */ 199 void OrxonoxShip::fire()200 { 201 mainWeapon_->primaryFireRequest();200 WeaponManager* OrxonoxShip::getMainWeapon() 201 { 202 return mainWeapon_; 202 203 } 203 204 -
code/branches/main_reto_vs05/src/orxonox_ship.h
r189 r194 54 54 Ogre::Vector3 getSpeed(); 55 55 56 void fire();56 weapon::WeaponManager* getMainWeapon(); 57 57 58 58 bool tick(unsigned long, Ogre::Real); -
code/branches/main_reto_vs05/src/run_manager.cc
r193 r194 88 88 */ 89 89 RunManager::RunManager(OgreControl * ogre) 90 : ogre_(ogre), window_(ogre->getRenderWindow()), leftButtonDown_(false),90 : ogre_(ogre), window_(ogre->getRenderWindow()), //leftButtonDown_(false), 91 91 statsOn_(true), screenShotCounter_(0), timeUntilNextToggle_(0), 92 92 filtering_(TFO_BILINEAR), aniso_(1), sceneDetailIndex_(0), … … 109 109 bulletManager_ = new BulletManager(sceneMgr_); 110 110 WeaponManager::loadWeapons(); 111 112 // TODO: Use STL to make life easier. But it works this way too..113 /*bullets_ = new Bullet*[10];114 bulletsIndex_ = 0;115 bulletsSize_ = 10;*/116 111 117 112 … … 220 215 221 216 WeaponManager::destroyWeapons(); 222 223 // clean up the bullet list224 /*for (int i = 0; i < bulletsIndex_; i++)225 delete bullets_[i];226 delete bullets_;*/227 217 } 228 218 … … 256 246 bulletManager_->tick(time, deltaTime); 257 247 258 /*for (int i = 0; i < bulletsIndex_; i++)259 {260 bullets_[i]->node_->translate(bullets_[i]->speed_*deltaTime);261 bullets_[i]->node_->yaw(Degree(deltaTime*100));262 bullets_[i]->node_->roll(Degree(deltaTime*300));263 }*/264 248 265 249 // HUMAN INTERFACE … … 366 350 else 367 351 playerShip_->setYThrust(0); 352 353 if (keyboard_->isKeyDown(KC_G)) 354 playerShip_->getMainWeapon()->addAction(WeaponManager::RELOAD); 368 355 369 356 if( keyboard_->isKeyDown(KC_ESCAPE) || keyboard_->isKeyDown(KC_Q) ) … … 457 444 const MouseState &ms = mouse_->getMouseState(); 458 445 459 // This is a 'hack' to show some flying barrels.. 460 // Usually, the Bullet created by the ship should be managed 461 // by the physics engine.. 462 if (ms.buttonDown(MB_Left) && !leftButtonDown_) 463 { 464 // Prevent continuous fire for the moment. 465 leftButtonDown_ = true; 466 467 playerShip_->fire(); 468 469 // let ship fire one shot with its only weapon (Barrels..) 470 /*Bullet *tempBullet = playerShip_->fire(); 471 472 // resize array if neccessary (double the size then) 473 if (bulletsIndex_ >= bulletsSize_) 474 { 475 // redimension the array 476 Bullet **tempArray = new Bullet*[2*bulletsSize_]; 477 for (int i = 0; i < bulletsSize_; i++) 478 tempArray[i] = bullets_[i]; 479 bulletsSize_ *= 2; 480 delete bullets_; 481 bullets_ = tempArray; 482 } 483 484 // add the bullet to the list 485 bullets_[bulletsIndex_++] = tempBullet;*/ 486 487 } 488 else if (!ms.buttons) 489 leftButtonDown_ = false; 490 491 // space ship steering. This should definitely be done in the steering object 492 // Simply give it the mouse movements. 446 if (ms.buttonDown(MB_Left)) 447 playerShip_->getMainWeapon()->primaryFireRequest(); 448 449 if (ms.buttonDown(MB_Right)) 450 playerShip_->getMainWeapon()->secondaryFireRequest(); 451 493 452 playerShip_->turnUpAndDown(Radian(ms.Y.rel * mouseSensitivity_)); 494 453 playerShip_->turnLeftAndRight(Radian(ms.X.rel * mouseSensitivity_)); 495 //playerShip_->mRootNode->pitch(Degree(-ms.Y.rel * 0.13), Ogre::Node::TransformSpace::TS_LOCAL);496 //playerShip_->mRootNode->yaw(Degree(-ms.X.rel * 0.13), Ogre::Node::TransformSpace::TS_PARENT);497 454 498 455 // keep rendering -
code/branches/main_reto_vs05/src/run_manager.h
r189 r194 93 93 // just to stop toggles flipping too fast 94 94 Ogre::Real timeUntilNextToggle_; 95 bool leftButtonDown_;95 //bool leftButtonDown_; 96 96 Ogre::TextureFilterOptions filtering_; 97 97 int aniso_; -
code/branches/main_reto_vs05/src/weapon/weapon_manager.cc
r189 r194 52 52 bulletCounter_(0), primaryFireRequest_(false), currentState_(IDLE), 53 53 secondaryFireRequest_(false), selectedWeapon_(0), 54 bulletManager_(bulletManager), 55 actionListReadIndex_(0), actionListWriteIndex_(0)54 bulletManager_(bulletManager), secondaryFired_(false), 55 timeSinceNextActionAdded_(0), actionAdded_(false), nextAction_(NOTHING) 56 56 { 57 57 slots_ = new Weapon*[slotSize]; 58 actionList_ = new Action[ACTION_LIST_SIZE];59 for (int i = 0; i < ACTION_LIST_SIZE; i++)60 actionList_[i] = NOTHING;61 58 } 62 59 … … 66 63 if (slots_) 67 64 delete slots_; 68 if (actionList_)69 delete actionList_;70 65 } 71 66 … … 90 85 bool WeaponManager::addAction(const Action act) 91 86 { 92 if ( actionList_[actionListWriteIndex_] == NOTHING)93 { 94 actionList_[actionListWriteIndex_]= act;95 action ListWriteIndex_ = (actionListWriteIndex_ + 1) % ACTION_LIST_SIZE;87 if (nextAction_ != NOTHING) 88 { 89 nextAction_ = act; 90 actionAdded_ = true; 96 91 return true; 97 92 } … … 109 104 void WeaponManager::primaryFire() 110 105 { 111 currentState_ = PRIMARY_FIRE;112 113 // TODO: add the name of the weapon manager. but for that,114 // the factory is required.115 106 SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode( 116 107 node_->getSceneNode()->getWorldPosition(), … … 124 115 speed += node_->getWorldSpeed(); 125 116 117 temp->setScale(Vector3(1, 1, 1) * 4); 118 temp->yaw(Degree(-90)); 119 120 bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed)); 121 } 122 123 124 void WeaponManager::primaryFiring(unsigned int time) 125 { 126 if (time > 100) 127 { 128 currentState_ = IDLE; 129 } 130 } 131 132 133 void WeaponManager::secondaryFireRequest() 134 { 135 secondaryFireRequest_ = true; 136 } 137 138 139 void WeaponManager::secondaryFire() 140 { 141 SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode( 142 node_->getSceneNode()->getWorldPosition(), 143 node_->getSceneNode()->getWorldOrientation()); 144 145 Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity" 146 + StringConverter::toString(bulletCounter_++), "Barrel.mesh"); 147 148 Vector3 speed = (temp->getOrientation() * Vector3(0, 0, -1)) 149 .normalisedCopy() * slots_[selectedWeapon_]->bulletSpeed_*0.5; 150 speed += node_->getWorldSpeed(); 151 126 152 temp->setScale(Vector3(1, 1, 1) * 10); 127 153 temp->yaw(Degree(-90)); 128 154 129 155 bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed)); 130 131 currentState_ = IDLE; 132 } 133 134 135 void WeaponManager::secondaryFireRequest() 136 { 137 secondaryFireRequest_ = true; 138 } 139 140 void WeaponManager::secondaryFire() 141 { 156 } 157 158 159 void WeaponManager::secondaryFiring(unsigned int time) 160 { 161 if (time > 250) 162 currentState_ = IDLE; 142 163 } 143 164 … … 149 170 return true; 150 171 172 // process action adder 173 if (actionAdded_) 174 { 175 timeSinceNextActionAdded_ = time; 176 actionAdded_ = false; 177 } 178 151 179 switch (currentState_) 152 180 { 153 181 case IDLE: 154 // first, process actions155 if ( actionList_[actionListReadIndex_]!= NOTHING)182 // first, process next action 183 if (nextAction_ != NOTHING) 156 184 { 157 actionListReadIndex_ = (actionListReadIndex_ + 1) % ACTION_LIST_SIZE; 158 break; 185 actionStartTime_ = time; 186 switch (nextAction_) 187 { 188 case RELOAD: 189 break; 190 191 case CHANGE_AMMO: 192 break; 193 194 case SPECIAL: 195 break; 196 197 default: 198 break; 199 } 200 201 // pay attention when multithreaded! 202 nextAction_ = NOTHING; 159 203 } 160 161 switch (actionList_[actionListReadIndex_]) 204 else 162 205 { 163 case RELOAD: 164 break; 165 166 case ZOOM_IN: 167 break; 168 169 case ZOOM_OUT: 170 break; 171 172 default: 173 break; 206 // secondly, execute firing 207 if (primaryFireRequest_ && !(secondaryFired_ && secondaryFireRequest_)) 208 { 209 actionStartTime_ = time; 210 currentState_ = PRIMARY_FIRE; 211 secondaryFired_ = false; 212 primaryFire(); 213 } 214 else if (secondaryFireRequest_) 215 { 216 actionStartTime_ = time; 217 currentState_ = SECONDARY_FIRE; 218 secondaryFired_ = true; 219 secondaryFire(); 220 } 174 221 } 175 222 176 // secondly, execute firing177 if (primaryFireRequest_)178 primaryFire();179 else if (secondaryFireRequest_)180 secondaryFire();181 182 223 break; 183 224 184 225 case PRIMARY_FIRE: 226 primaryFiring((unsigned int)(time - actionStartTime_)); 185 227 break; 186 228 187 229 case SECONDARY_FIRE: 230 secondaryFiring((unsigned int)(time - actionStartTime_)); 188 231 break; 189 232 190 233 case RELOADING: 234 break; 235 236 case CHANGING_AMMO: 191 237 break; 192 238 } … … 194 240 primaryFireRequest_ = false; 195 241 secondaryFireRequest_ = false; 242 243 if (time - timeSinceNextActionAdded_ > nextActionValidityPeriod_) 244 nextAction_ = NOTHING; 196 245 197 246 return true; … … 205 254 for (int i = 0; i < 5; i++) 206 255 weaponList_s[i] = NULL; 207 weaponList_s[0] = new Weapon("Barrel Gun", 10, 2, 500);256 weaponList_s[0] = new Weapon("Barrel Gun", 10, 2, 1000); 208 257 return true; 209 258 } -
code/branches/main_reto_vs05/src/weapon/weapon_manager.h
r189 r194 44 44 NOTHING = 0, 45 45 RELOAD = 1, 46 ZOOM_IN= 2,47 ZOOM_OUT= 346 CHANGE_AMMO = 2, 47 SPECIAL = 3 48 48 }; 49 49 … … 53 53 PRIMARY_FIRE = 1, 54 54 SECONDARY_FIRE = 2, 55 RELOADING = 4 55 RELOADING = 3, 56 CHANGING_AMMO = 4, 56 57 }; 57 58 … … 77 78 void primaryFire(); 78 79 80 void primaryFiring(unsigned int); 81 79 82 void secondaryFire(); 83 84 void secondaryFiring(unsigned int); 80 85 81 86 public: … … 97 102 bool secondaryFireRequest_; 98 103 104 unsigned long actionStartTime_; 105 99 106 State currentState_; 107 bool secondaryFired_; 100 108 101 Action *actionList_; 102 int actionListReadIndex_; 103 int actionListWriteIndex_; 109 Action nextAction_; 110 bool actionAdded_; 111 unsigned long timeSinceNextActionAdded_; 112 static const unsigned long nextActionValidityPeriod_ = 500; 104 113 105 114 static Weapon **weaponList_s;
Note: See TracChangeset
for help on using the changeset viewer.