Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/projectiles/projectile.cc @ 9171

Last change on this file since 9171 was 9162, checked in by rennerc, 18 years ago
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 "util/loading/resource_manager.h"
25
26#include "debug.h"
27
28
29/**
30 *  standard constructor
31*/
32Projectile::Projectile () : WorldEntity()
33{
34  this->setClassID(CL_PROJECTILE, "Projectile");
35
36  this->lifeCycle = 0.0;
37  this->lifeSpan = 1.0f; /* sec */
38  this->target = NULL;
39  this->removeNode();
40
41  /* character attributes */
42  this->setHealth(1.0f);
43  this->setDamage(100.0f); // default damage of a projectile set to 100.0 damage points
44
45  this->explosionBuffer = NULL;
46  this->engineBuffer = NULL;
47}
48
49
50/**
51 *  standard deconstructor
52*/
53Projectile::~Projectile ()
54{
55  if (this->explosionBuffer != NULL)
56    ResourceManager::getInstance()->unload(this->explosionBuffer);
57  if (this->engineBuffer != NULL)
58    ResourceManager::getInstance()->unload(this->engineBuffer);
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
66
67void Projectile::loadExplosionSound(const std::string& explosionSound)
68{
69  if (this->explosionBuffer != NULL)
70    ResourceManager::getInstance()->unload(this->explosionBuffer);
71
72  else if (!explosionSound.empty())
73  {
74    this->explosionBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load(explosionSound, WAV);
75    if (this->explosionBuffer != NULL)
76    {
77      PRINTF(4)("Loaded sound %s to Pickup: %s.\n", explosionSound.c_str(), this->getName());
78    }
79    else
80    {
81      PRINTF(2)("Failed to load sound %s to explosion %s.\n.", explosionSound.c_str(), this->getName());
82    }
83  }
84  else
85    this->explosionBuffer = NULL;
86}
87
88
89void Projectile::loadEngineSound(const std::string& engineSound)
90{
91  if (this->engineBuffer != NULL)
92    ResourceManager::getInstance()->unload(this->engineBuffer);
93
94  else if (!engineSound.empty())
95  {
96    this->engineBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load(engineSound, WAV);
97    if (this->engineBuffer != NULL)
98    {
99      PRINTF(4)("Loaded sound %s to Pickup: %s.\n", engineSound.c_str(), this->getName());
100    }
101    else
102    {
103      PRINTF(2)("Failed to load sound %s to engine %s.\n.", engineSound.c_str(), this->getName());
104    }
105  }
106  else
107    this->engineBuffer = NULL;
108}
109
110
111void Projectile::setMinEnergy(float energyMin)
112{
113  this->energyMin = energyMin;
114}
115
116
117/**
118 *  this sets the flight direction of the projectile
119 * @param directin in which to flight
120
121   this function will calculate a vector out of this to be used in the
122   tick function
123*/
124void Projectile::setFlightDirection(const Quaternion& flightDirection)
125{
126  Vector v(1, 0, 0);
127  this->flightDirection = flightDirection.apply(v);
128  this->flightDirection.normalize();
129}
130
131/**
132 *  sets the velocity vector to a spec speed
133 * @param velocity: vector of the velocity
134*/
135void Projectile::setVelocity(const Vector &velocity)
136{
137  //Vector offsetVel =
138  this->velocity = velocity;
139 // offsetVel.normalize();
140  //this->velocity += (offsetVel * 50.0);
141}
142
143
144
145void Projectile::setTarget(PNode* target)
146{
147  if (this->target == NULL)
148    this->target = new PNode(target, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_ON_PARENTS_REMOVE);
149  else
150    this->target->setParent(target);
151}
152
153
154/**
155 * signal tick, time dependent things will be handled here
156 * @param dt since last tick
157*/
158void Projectile::tick (float dt)
159{
160  Vector v = this->velocity * (dt);
161  this->shiftCoor(v);
162
163  if (this->tickLifeCycle(dt))
164    this->destroy( NULL );
165}
166
167
168/**
169 *  the function gets called, when the projectile is destroyed
170*/
171void Projectile::destroy (WorldEntity* killer)
172{
173  if (this->explosionBuffer != NULL)
174    this->soundSource.play(this->explosionBuffer);
175}
176
Note: See TracBrowser for help on using the repository browser.