Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/world_entities/projectiles/projectile.cc @ 9623

Last change on this file since 9623 was 9615, checked in by bensch, 18 years ago

AimingTurret is better suited for network, as the projectiles are not connected to anything.
also it makes the game a little bit easier, and more fun as the turrets move around :)

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(1.0f); // default damage of a projectile set to 100.0 damage points
44
45  this->explosionBuffer = NULL;
46  this->engineBuffer = NULL;
47
48  //this->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
49}
50
51
52/**
53 *  standard deconstructor
54*/
55Projectile::~Projectile ()
56{
57  if (this->explosionBuffer != NULL)
58    ResourceManager::getInstance()->unload(this->explosionBuffer);
59  if (this->engineBuffer != NULL)
60    ResourceManager::getInstance()->unload(this->engineBuffer);
61  /*
62     do not delete the test projectModel, since it is pnode
63     and will be cleaned out by world
64  */
65  //delete this->projectileModel;
66}
67
68
69void Projectile::loadExplosionSound(const std::string& explosionSound)
70{
71  if (this->explosionBuffer != NULL)
72    ResourceManager::getInstance()->unload(this->explosionBuffer);
73
74  else if (!explosionSound.empty())
75  {
76    this->explosionBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load(explosionSound, WAV);
77    if (this->explosionBuffer != NULL)
78    {
79      PRINTF(4)("Loaded sound %s to Pickup: %s.\n", explosionSound.c_str(), this->getCName());
80    }
81    else
82    {
83      PRINTF(2)("Failed to load sound %s to explosion %s.\n.", explosionSound.c_str(), this->getCName());
84    }
85  }
86  else
87    this->explosionBuffer = NULL;
88}
89
90
91void Projectile::loadEngineSound(const std::string& engineSound)
92{
93  if (this->engineBuffer != NULL)
94    ResourceManager::getInstance()->unload(this->engineBuffer);
95
96  else if (!engineSound.empty())
97  {
98    this->engineBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load(engineSound, WAV);
99    if (this->engineBuffer != NULL)
100    {
101      PRINTF(4)("Loaded sound %s to Pickup: %s.\n", engineSound.c_str(), this->getCName());
102    }
103    else
104    {
105      PRINTF(2)("Failed to load sound %s to engine %s.\n.", engineSound.c_str(), this->getCName());
106    }
107  }
108  else
109    this->engineBuffer = NULL;
110}
111
112
113void Projectile::setMinEnergy(float energyMin)
114{
115  this->energyMin = energyMin;
116}
117
118
119/**
120 *  this sets the flight direction of the projectile
121 * @param directin in which to flight
122
123   this function will calculate a vector out of this to be used in the
124   tick function
125*/
126void Projectile::setFlightDirection(const Quaternion& flightDirection)
127{
128  Vector v(1, 0, 0);
129  this->flightDirection = flightDirection.apply(v);
130  this->flightDirection.normalize();
131}
132
133/**
134 *  sets the velocity vector to a spec speed
135 * @param velocity: vector of the velocity
136*/
137void Projectile::setVelocity(const Vector &velocity)
138{
139  //Vector offsetVel =
140  this->velocity = velocity;
141 // offsetVel.normalize();
142  //this->velocity += (offsetVel * 50.0);
143}
144
145
146
147void Projectile::setTarget(PNode* target)
148{
149  if (this->target == NULL)
150    this->target = new PNode(target, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_ON_PARENTS_REMOVE);
151  else
152    this->target->setParent(target);
153}
154
155
156/**
157 * signal tick, time dependent things will be handled here
158 * @param dt since last tick
159*/
160void Projectile::tick (float dt)
161{
162  Vector v = this->velocity * (dt);
163  this->shiftCoor(v);
164
165  if (this->tickLifeCycle(dt))
166    this->destroy( NULL );
167}
168
169
170/**
171 *  the function gets called, when the projectile is destroyed
172*/
173void Projectile::destroy (WorldEntity* killer)
174{
175  if (this->explosionBuffer != NULL)
176    this->soundSource.play(this->explosionBuffer);
177}
178
Note: See TracBrowser for help on using the repository browser.