Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7384 was 7221, checked in by bensch, 19 years ago

orxonox/trunk: merged the std-branche back, it runs on windows and Linux

svn merge https://svn.orxonox.net/orxonox/branches/std . -r7202:HEAD

File size: 3.9 KB
RevLine 
[3573]1
2
[4597]3/*
[3573]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
[4597]15   co-programmer:
[3573]16*/
[5357]17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
[3573]18
19#include "projectile.h"
[3618]20
[3573]21#include "world_entity.h"
[6434]22#include "world_entities/weapons/weapon.h"
[3678]23#include "model.h"
[7193]24#include "util/loading/resource_manager.h"
[3573]25
26using namespace std;
27
28
[3578]29/**
[4836]30 *  standard constructor
[3578]31*/
[4932]32Projectile::Projectile () : WorldEntity()
[3573]33{
[4322]34  this->setClassID(CL_PROJECTILE, "Projectile");
[4597]35
[4890]36  this->lifeCycle = 0.0;
[5063]37  this->lifeSpan = 1.0f; /* sec */
[6078]38  this->target = NULL;
[5769]39  this->removeNode();
[7084]40
41  this->explosionBuffer = NULL;
42  this->engineBuffer = NULL;
[3573]43}
44
45
[3578]46/**
[4836]47 *  standard deconstructor
[3578]48*/
[4597]49Projectile::~Projectile ()
[3573]50{
[7084]51  if (this->explosionBuffer != NULL)
52    ResourceManager::getInstance()->unload(this->explosionBuffer);
53  if (this->engineBuffer != NULL)
54    ResourceManager::getInstance()->unload(this->engineBuffer);
[4597]55  /*
56     do not delete the test projectModel, since it is pnode
57     and will be cleaned out by world
[3629]58  */
59  //delete this->projectileModel;
[3573]60}
61
[3578]62
[7221]63void Projectile::loadExplosionSound(const std::string& explosionSound)
[7084]64{
65  if (this->explosionBuffer != NULL)
66    ResourceManager::getInstance()->unload(this->explosionBuffer);
67
[7221]68  else if (!explosionSound.empty())
[7084]69  {
70    this->explosionBuffer = (SoundBuffer*)ResourceManager::getInstance()->load(explosionSound, WAV);
71    if (this->explosionBuffer != NULL)
72    {
[7221]73      PRINTF(4)("Loaded sound %s to Pickup: %s.\n", explosionSound.c_str(), this->getName());
[7084]74    }
75    else
76    {
[7221]77      PRINTF(2)("Failed to load sound %s to explosion %s.\n.", explosionSound.c_str(), this->getName());
[7084]78    }
79  }
80  else
81    this->explosionBuffer = NULL;
82}
83
84
[7221]85void Projectile::loadEngineSound(const std::string& engineSound)
[7084]86{
87  if (this->engineBuffer != NULL)
88    ResourceManager::getInstance()->unload(this->engineBuffer);
89
[7221]90  else if (!engineSound.empty())
[7084]91  {
92    this->engineBuffer = (SoundBuffer*)ResourceManager::getInstance()->load(engineSound, WAV);
93    if (this->engineBuffer != NULL)
94    {
[7221]95      PRINTF(4)("Loaded sound %s to Pickup: %s.\n", engineSound.c_str(), this->getName());
[7084]96    }
97    else
98    {
[7221]99      PRINTF(2)("Failed to load sound %s to engine %s.\n.", engineSound.c_str(), this->getName());
[7084]100    }
101  }
102  else
103    this->engineBuffer = NULL;
104}
105
106
[6431]107void Projectile::setMinEnergy(float energyMin)
[4948]108{
109  this->energyMin = energyMin;
110}
111
112
[3578]113/**
[4836]114 *  this sets the flight direction of the projectile
115 * @param directin in which to flight
[3632]116
117   this function will calculate a vector out of this to be used in the
118   tick function
119*/
[4927]120void Projectile::setFlightDirection(const Quaternion& flightDirection)
[3632]121{
122  Vector v(1, 0, 0);
[4890]123  this->flightDirection = flightDirection.apply(v);
124  this->flightDirection.normalize();
[3632]125}
126
127/**
[4836]128 *  sets the velocity vector to a spec speed
129 * @param velocity: vector of the velocity
[4464]130*/
131void Projectile::setVelocity(const Vector &velocity)
132{
[4955]133  //Vector offsetVel =
134  this->velocity = velocity;
135 // offsetVel.normalize();
136  //this->velocity += (offsetVel * 50.0);
[4464]137}
138
[5766]139
140
141void Projectile::setTarget(PNode* target)
142{
[6078]143  if (this->target == NULL)
144    this->target = new PNode(target, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_ON_PARENTS_REMOVE);
145  else
146    this->target->setParent(target);
[5766]147}
148
149
[4464]150/**
[4927]151 * signal tick, time dependent things will be handled here
[6056]152 * @param dt since last tick
[3578]153*/
[6056]154void Projectile::tick (float dt)
[3632]155{
[6056]156  Vector v = this->velocity * (dt);
[3686]157  this->shiftCoor(v);
[3683]158
[6056]159  if (this->tickLifeCycle(dt))
160    this->destroy();
[3632]161}
[3573]162
163
[3578]164/**
[4836]165 *  the function gets called, when the projectile is destroyed
[3578]166*/
[4597]167void Projectile::destroy ()
[7084]168{
169  if (this->explosionBuffer != NULL)
170    this->soundSource.play(this->explosionBuffer);
171}
[3573]172
Note: See TracBrowser for help on using the repository browser.