Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/camera/src/world_entities/projectiles/projectile.cc @ 10338

Last change on this file since 10338 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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