Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability.old/src/world_entities/projectiles/projectile.cc @ 10621

Last change on this file since 10621 was 10104, checked in by nicolasc, 18 years ago

some beautifications, nothing new

File size: 4.1 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
26#include <cmath>
27
28#include "debug.h"
29
30ObjectListDefinition(Projectile);
31
32/**
33 *  standard constructor
34*/
35Projectile::Projectile () : WorldEntity()
36{
37  this->registerObject(this, Projectile::_objectList);
38
39  this->lifeCycle = 0.0;
40  this->lifeSpan = 1.0f; /* sec */
41  this->target = NULL;
42  this->removeNode();
43
44  /* character attributes */
45  this->setHealth(1.0f);
46  this->setDamage(1.0f); // default damage of a projectile set to 100.0 damage points
47
48  this->physDamage = 0.0f;
49  this->elecDamage = 0.0f;
50  //this->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
51}
52
53
54/**
55 *  standard deconstructor
56*/
57Projectile::~Projectile ()
58{
59  /*
60     do not delete the test projectModel, since it is pnode
61     and will be cleaned out by world
62  */
63  //delete this->projectileModel;
64}
65
66Projectile::Projectile (float pDamage, float eDamage, PNode* target) : WorldEntity()
67{
68  this->registerObject(this, Projectile::_objectList);
69
70  this->lifeCycle = 0.0;
71  this->lifeSpan = 1.0f; /* sec */
72  this->removeNode();
73
74  /* character attributes */
75  this->setHealth(1.0f);
76  this->setDamage(1.0f); // default damage of a projectile set to 100.0 damage points
77
78  this->physDamage = pDamage;
79  this->elecDamage = eDamage;
80  this->target = target;
81
82  //this->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
83}
84
85void Projectile::initialize(float pDamage, float eDamage, PNode* target)
86{
87  /* character attributes*/
88  this->physDamage = pDamage;
89  this->elecDamage = eDamage;
90  this->target = target;
91}
92
93
94void Projectile::loadExplosionSound(const std::string& explosionSound)
95{
96  if (!explosionSound.empty())
97    this->explosionBuffer = OrxSound::ResourceSoundBuffer(explosionSound);
98  else
99    this->explosionBuffer = OrxSound::SoundBuffer();
100}
101
102
103void Projectile::loadEngineSound(const std::string& engineSound)
104{
105  if (!engineSound.empty())
106    this->engineBuffer = OrxSound::ResourceSoundBuffer(engineSound);
107  else
108    this->engineBuffer = OrxSound::SoundBuffer();
109}
110
111
112void Projectile::setMinEnergy(float energyMin)
113{
114  this->energyMin = energyMin;
115}
116
117
118/**
119 *  this sets the flight direction of the projectile
120 * @param directin in which to flight
121
122   this function will calculate a vector out of this to be used in the
123   tick function
124*/
125void Projectile::setFlightDirection(const Quaternion& flightDirection)
126{
127  Vector v(1, 0, 0);
128  this->flightDirection = flightDirection.apply(v);
129  this->flightDirection.normalize();
130}
131
132/**
133 *  sets the velocity vector to a spec speed
134 * @param velocity: vector of the velocity
135*/
136void Projectile::setVelocity(const Vector &velocity)
137{
138  //Vector offsetVel =
139  this->velocity = velocity;
140  // offsetVel.normalize();
141  //this->velocity += (offsetVel * 50.0);
142}
143
144
145
146void Projectile::setTarget(PNode* target)
147{
148  if (this->target == NULL)
149    this->target = new PNode(target, PNODE_REPARENT_ON_PARENTS_REMOVE | PNODE_REPARENT_TO_NULL | PNODE_PROHIBIT_DELETE_WITH_PARENT);
150  else
151    this->target->setParent(target);
152}
153
154
155void Projectile::collidesWith (WorldEntity* target, const Vector& location)
156{
157  dynamic_cast<SpaceShip*>(target)->damage(this->getPhysDamage(),this->getElecDamage());
158//   this->destroy(NULL);
159  this->destroy(target);
160}
161
162
163
164/**
165 * signal tick, time dependent things will be handled here
166 * @param dt since last tick
167*/
168void Projectile::tick (float dt)
169{
170  if (this->tickLifeCycle(dt))
171    this->destroy( NULL );
172}
173
174
175/**
176 *  the function gets called, when the projectile is destroyed
177*/
178void Projectile::destroy (WorldEntity* killer)
179{
180  if (this->explosionBuffer.loaded())
181    this->soundSource.play(this->explosionBuffer);
182}
183
Note: See TracBrowser for help on using the repository browser.