Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/projectile.cc @ 10146

Last change on this file since 10146 was 10013, checked in by patrick, 18 years ago

merged the collision reaction branche back to trunk

File size: 3.3 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific
14   main-programmer: Patrick Boenzli
15   co-programmer:
16*/
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
18
19#include "projectile.h"
20
21#include "world_entity.h"
22#include "world_entities/weapons/weapon.h"
23#include "model.h"
24#include "sound/resource_sound_buffer.h"
25#include "playable.h"
26
27#include "debug.h"
28
29ObjectListDefinition(Projectile);
30
31/**
32 *  standard constructor
33*/
34Projectile::Projectile () : WorldEntity()
35{
36  this->registerObject(this, Projectile::_objectList);
37
38  this->lifeCycle = 0.0;
39  this->lifeSpan = 1.0f; /* sec */
40  this->target = NULL;
41  this->removeNode();
42
43  /* character attributes */
44  this->setHealth(1.0f);
45  this->setDamage(1.0f); // default damage of a projectile set to 100.0 damage points
46  this->subscribeReaction( CoRe::CREngine::CR_PHYSICS_FULL_WALK, Playable::staticClassID());
47
48  //this->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
49}
50
51
52/**
53 *  standard deconstructor
54*/
55Projectile::~Projectile ()
56{
57  /*
58     do not delete the test projectModel, since it is pnode
59     and will be cleaned out by world
60  */
61  //delete this->projectileModel;
62}
63
64
65void Projectile::loadExplosionSound(const std::string& explosionSound)
66{
67  if (!explosionSound.empty())
68    this->explosionBuffer = OrxSound::ResourceSoundBuffer(explosionSound);
69  else
70    this->explosionBuffer = OrxSound::SoundBuffer();
71}
72
73
74void Projectile::loadEngineSound(const std::string& engineSound)
75{
76  if (!engineSound.empty())
77    this->engineBuffer = OrxSound::ResourceSoundBuffer(engineSound);
78  else
79    this->engineBuffer = OrxSound::SoundBuffer();
80}
81
82
83void Projectile::setMinEnergy(float energyMin)
84{
85  this->energyMin = energyMin;
86}
87
88
89/**
90 *  this sets the flight direction of the projectile
91 * @param directin in which to flight
92
93   this function will calculate a vector out of this to be used in the
94   tick function
95*/
96void Projectile::setFlightDirection(const Quaternion& flightDirection)
97{
98  Vector v(1, 0, 0);
99  this->flightDirection = flightDirection.apply(v);
100  this->flightDirection.normalize();
101}
102
103/**
104 *  sets the velocity vector to a spec speed
105 * @param velocity: vector of the velocity
106*/
107void Projectile::setVelocity(const Vector &velocity)
108{
109  //Vector offsetVel =
110  this->velocity = velocity;
111  // offsetVel.normalize();
112  //this->velocity += (offsetVel * 50.0);
113}
114
115
116
117void Projectile::setTarget(PNode* target)
118{
119  if (this->target == NULL)
120    this->target = new PNode(target, PNODE_REPARENT_ON_PARENTS_REMOVE | PNODE_REPARENT_TO_NULL | PNODE_PROHIBIT_DELETE_WITH_PARENT);
121  else
122    this->target->setParent(target);
123}
124
125
126/**
127 * signal tick, time dependent things will be handled here
128 * @param dt since last tick
129*/
130void Projectile::tick (float dt)
131{
132  Vector v = this->velocity * (dt);
133  this->shiftCoor(v);
134
135  if (this->tickLifeCycle(dt))
136    this->destroy( NULL );
137}
138
139
140/**
141 *  the function gets called, when the projectile is destroyed
142*/
143void Projectile::destroy (WorldEntity* killer)
144{
145  if (this->explosionBuffer.loaded())
146    this->soundSource.play(this->explosionBuffer);
147}
148
Note: See TracBrowser for help on using the repository browser.