Changeset 10694 in orxonox.OLD for branches/adm/src/world_entities/weapons
- Timestamp:
- Jun 14, 2007, 3:50:14 PM (18 years ago)
- Location:
- branches/adm/src/world_entities/weapons
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/adm/src/world_entities/weapons/bsp_weapon.cc
r10690 r10694 21 21 22 22 #include "environments/bsp_entity.h" 23 #include "loading/fast_factory.h" 23 24 24 25 ObjectListDefinition(BspWeapon); 25 26 CREATE_FACTORY(BspWeapon); 27 28 ObjectListDefinition(MuzzleFlash); 26 29 27 30 /** … … 73 76 LOAD_PARAM_START_CYCLE(root, element); 74 77 { 75 LoadParam_CYCLE(element, "addPoint", this, BspWeapon, addPoint) 76 .describe("Adds a new Point for Gunfire"); 78 if (root != 0){ 79 LoadParam_CYCLE(element, "addPoint", this, BspWeapon, addPoint) 80 .describe("Adds a new Point for Gunfire"); 81 } 77 82 } 78 83 LOAD_PARAM_END_CYCLE(element); … … 82 87 void BspWeapon::addPoint(float x, float y, float z) 83 88 { 84 if (element == 1 ){ 85 gunFire1->setRelCoor(Vector(x,y,z)); 86 element++; 87 } 88 if (element == 2 ){ 89 gunFire2->setRelCoor(Vector(x,y,z)); 90 } 89 gunFire.push_back( new MuzzleFlash() ); 90 gunFire.back()->setParent( this->getParent() ); 91 gunFire.back()->setRelCoor(x, y, z); 91 92 } 92 93 … … 107 108 bRate = 0; 108 109 } 110 109 111 } 110 112 … … 112 114 { 113 115 bRate = 0; 114 bFire = true;116 bFire = false; 115 117 range = 1000; 116 118 damage = 10; 117 119 fireRate = 0.5; 118 120 alwaysHits = true; 119 element=1;120 121 121 122 this->registerObject(this, BspWeapon::_objectList); … … 123 124 this->aimingSystem->setParent( this ); 124 125 this->aimingSystem->toList(OM_GROUP_00); 126 125 127 } 126 128 127 129 void BspWeapon::shoot() 128 130 { 129 gunFire.explode(gunFire1,Vector(2,2,2)); 130 gunFire.explode(gunFire2,Vector(2,2,2)); 131 //gunFirExpl.explode(gunFire1,Vector(2,2,2)); 132 //gunFirExpl.explode(gunFire2,Vector(2,2,2)); 133 134 for ( std::list<MuzzleFlash*>::iterator it = gunFire.begin(); it!=gunFire.end(); it++) 135 { 136 (*it)->explode( 0.2 ); 137 } 138 131 139 std::list<WorldEntity*>::iterator entityIterator; 132 140 // for all bsp managers check all entities … … 151 159 152 160 if ( target == NULL ) 153 printf("NO TING HIT\n");161 printf("NO TARGET\n"); 154 162 else 155 163 { 156 printf( "HIT %s\n", target->getClassName().c_str() );157 158 164 if (!alwaysHits){ 159 165 float r = rand(); … … 161 167 float res = (target->getAbsCoor() - this->getAbsCoor()).len(); 162 168 float p = 1 - res*res/range/range; 163 if (r < p ) 169 if (r < p ){ 164 170 hit = true; 171 printf( "HIT %s\n", target->getClassName().c_str() ); 172 } 173 else 174 printf( "MISHIT %s\n", target->getClassName().c_str() ); 175 165 176 } 166 177 else hit = true; … … 169 180 if ( !hit ) 170 181 { 171 Vector explosionPos = this->getAbsCoor() + this->getAbsDir().apply( Vector( 1, 0, 0 ) )*shortestDist;182 //Vector explosionPos = this->getAbsCoor() + this->getAbsDir().apply( Vector( 1, 0, 0 ) )*shortestDist; 172 183 173 184 //TODO create explosion at explosionPos 174 185 } 175 186 176 187 177 188 } … … 181 192 WorldEntity::draw(); 182 193 183 194 for ( std::list<MuzzleFlash*>::const_iterator it = gunFire.begin(); it!=gunFire.end(); it++) 195 { 196 (*it)->draw(); 197 } 198 #if 0 184 199 glMatrixMode(GL_MODELVIEW); 185 200 glPushMatrix(); … … 207 222 glPopAttrib(); 208 223 glPopMatrix(); 209 210 } 224 #endif 225 } 226 227 void MuzzleFlash::draw( ) const 228 { 229 if (explosionParticles) explosionParticles->draw(); 230 } 231 232 void MuzzleFlash::activate() 233 { 234 if (unlikely(explosionParticles == NULL)) 235 { 236 explosionParticles = new SpriteParticles(5000); 237 explosionParticles->setName("MuzzleFlashExplosionParticles"); 238 explosionParticles->setMaterialTexture("textures/radial-trans-noise.png"); 239 explosionParticles->setLifeSpan(0.1, 0); 240 explosionParticles->setRadius(0.0, 8); 241 explosionParticles->setRadius(.5, 6.0); 242 explosionParticles->setRadius(1.0, 2.0); 243 explosionParticles->setColor(0.0, 1,0.7,0,1); 244 explosionParticles->setColor(0.4, 0.8,.5,0,1); 245 explosionParticles->setColor(0.8, 0.5,0,0,.8); 246 explosionParticles->setColor(1.0, 0,0,0,.6); 247 explosionParticles->toList(OM_DEAD_TICK); 248 } 249 250 this->emitter->setSystem(explosionParticles); 251 this->emitter->updateNode(.01); 252 this->emitter->updateNode(.01); 253 this->toList(OM_DEAD_TICK); 254 this->lifeCycle = 0.0; 255 } 256 257 void MuzzleFlash::explode(float lifetime) 258 { 259 MuzzleFlash* explosion = this; 260 //explosion->setAbsCoor(this->getAbsCoor()); 261 explosion->emitter->setSize(1, 1, 1); 262 explosion->activate(); 263 explosion->lifeTime = lifetime; 264 } 265 266 MuzzleFlash::MuzzleFlash () 267 { 268 this->explosionParticles = NULL; 269 this->registerObject(this, MuzzleFlash::_objectList); 270 this->toList(OM_DEAD_TICK); 271 272 this->emitter = new BoxEmitter(Vector(10,10,10), 200, 45, M_2_PI); 273 this->emitter->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); 274 this->emitter->setParent(this); 275 this->emitter->setSpread(M_PI, M_PI); 276 277 this->lifeCycle = 0.0f; 278 this->lifeTime = .5f; 279 280 } 281 282 283 /** 284 * standard deconstructor 285 */ 286 MuzzleFlash::~MuzzleFlash () 287 { 288 delete this->emitter; 289 290 /* this is normaly done by World.cc by deleting the ParticleEngine */ 291 if (explosionParticles != NULL) 292 { 293 delete explosionParticles; 294 MuzzleFlash::explosionParticles = NULL; 295 } 296 } 297 298 void MuzzleFlash::deactivate() 299 { 300 this->emitter->setSystem(NULL); 301 this->toList(OM_DEAD); 302 } 303 304 305 /** 306 * signal tick, time dependent things will be handled here 307 * @param time since last tick 308 */ 309 void MuzzleFlash::tick (float dt) 310 { 311 this->lifeCycle += dt; 312 if(this->lifeTime < this->lifeCycle) 313 this->deactivate(); 314 } 315 316 317 -
branches/adm/src/world_entities/weapons/bsp_weapon.h
r10690 r10694 10 10 #include "aiming_system.h" 11 11 #include "effects/explosion.h" 12 13 #include <list> 14 15 #include "particles/box_emitter.h" 16 #include "particles/sprite_particles.h" 17 18 class MuzzleFlash : public WorldEntity 19 { 20 ObjectListDeclaration(MuzzleFlash); 21 public: 22 void explode (float lifetime); 23 24 MuzzleFlash (); 25 virtual ~MuzzleFlash (); 26 27 virtual void activate(); 28 virtual void deactivate(); 29 30 virtual void tick (float time); 31 virtual void draw() const; 32 33 void setLifeTime( float lifeTime ){ this->lifeTime = lifeTime; } 34 35 void drawParticles(){ if (explosionParticles) explosionParticles->draw(); } 36 37 protected: 38 //static FastFactory* fastFactory; 39 40 float lifeTime; 41 float lifeCycle; 42 43 SpriteParticles* explosionParticles; 44 BoxEmitter* emitter; 45 46 }; 47 12 48 13 49 class BspWeapon : public WorldEntity … … 38 74 void setAlwaysHits( bool r ){ this->alwaysHits = r; } 39 75 void addPoint(float x, float y, float z); 40 PNode* gunFire1;41 PNode* gunFire2;76 77 std::list<MuzzleFlash*> gunFire; 42 78 43 79 float bRate; 44 80 bool bFire; 45 int element;46 47 Explosion gunFire;48 81 49 82 AimingSystem* aimingSystem;
Note: See TracChangeset
for help on using the changeset viewer.