Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9957 was 9957, checked in by nicolasc, 17 years ago

updated damage() to use tick
added collidesWith() to Projectile

File size: 3.5 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"
[9869]24#include "sound/resource_sound_buffer.h"
[3573]25
[8362]26#include "debug.h"
[3573]27
[9869]28ObjectListDefinition(Projectile);
[3573]29
[3578]30/**
[4836]31 *  standard constructor
[3578]32*/
[4932]33Projectile::Projectile () : WorldEntity()
[3573]34{
[9869]35  this->registerObject(this, Projectile::_objectList);
[4597]36
[4890]37  this->lifeCycle = 0.0;
[5063]38  this->lifeSpan = 1.0f; /* sec */
[6078]39  this->target = NULL;
[5769]40  this->removeNode();
[7084]41
[8190]42  /* character attributes */
43  this->setHealth(1.0f);
[9235]44  this->setDamage(1.0f); // default damage of a projectile set to 100.0 damage points
[8190]45
[9656]46  //this->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
[3573]47}
48
49
[3578]50/**
[4836]51 *  standard deconstructor
[3578]52*/
[4597]53Projectile::~Projectile ()
[3573]54{
[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{
[9869]65  if (!explosionSound.empty())
66    this->explosionBuffer = OrxSound::ResourceSoundBuffer(explosionSound);
[7084]67  else
[9869]68    this->explosionBuffer = OrxSound::SoundBuffer();
[7084]69}
70
71
[7221]72void Projectile::loadEngineSound(const std::string& engineSound)
[7084]73{
[9869]74  if (!engineSound.empty())
75    this->engineBuffer = OrxSound::ResourceSoundBuffer(engineSound);
[7084]76  else
[9869]77    this->engineBuffer = OrxSound::SoundBuffer();
[7084]78}
79
80
[6431]81void Projectile::setMinEnergy(float energyMin)
[4948]82{
83  this->energyMin = energyMin;
84}
85
86
[3578]87/**
[4836]88 *  this sets the flight direction of the projectile
89 * @param directin in which to flight
[3632]90
91   this function will calculate a vector out of this to be used in the
92   tick function
93*/
[4927]94void Projectile::setFlightDirection(const Quaternion& flightDirection)
[3632]95{
96  Vector v(1, 0, 0);
[4890]97  this->flightDirection = flightDirection.apply(v);
98  this->flightDirection.normalize();
[3632]99}
100
101/**
[4836]102 *  sets the velocity vector to a spec speed
103 * @param velocity: vector of the velocity
[4464]104*/
105void Projectile::setVelocity(const Vector &velocity)
106{
[4955]107  //Vector offsetVel =
108  this->velocity = velocity;
[9869]109  // offsetVel.normalize();
[4955]110  //this->velocity += (offsetVel * 50.0);
[4464]111}
112
[5766]113
114
115void Projectile::setTarget(PNode* target)
116{
[6078]117  if (this->target == NULL)
[9869]118    this->target = new PNode(target, PNODE_REPARENT_ON_PARENTS_REMOVE | PNODE_REPARENT_TO_NULL | PNODE_PROHIBIT_DELETE_WITH_PARENT);
[6078]119  else
120    this->target->setParent(target);
[5766]121}
122
123
[9957]124
125void Projectile::collidesWith (WorldEntity* entity, const Vector& location)
126{
127  //if (entity->isA(CL_SPACE_SHIP)) /* FIXME make sure that entity is a spaceship*/
128  //  entity->damage(this->physDamage, this->elecDamage); /* and do some damage*/
129  this->destroy(entity);
130}
131
[4464]132/**
[4927]133 * signal tick, time dependent things will be handled here
[6056]134 * @param dt since last tick
[3578]135*/
[6056]136void Projectile::tick (float dt)
[3632]137{
[6056]138  Vector v = this->velocity * (dt);
[3686]139  this->shiftCoor(v);
[3683]140
[6056]141  if (this->tickLifeCycle(dt))
[9235]142    this->destroy( NULL );
[3632]143}
[3573]144
145
[3578]146/**
[4836]147 *  the function gets called, when the projectile is destroyed
[3578]148*/
[9235]149void Projectile::destroy (WorldEntity* killer)
[7084]150{
[9869]151  if (this->explosionBuffer.loaded())
[7084]152    this->soundSource.play(this->explosionBuffer);
153}
[3573]154
[9953]155int Projectile::getPhysDamage () { return this->physDamage; }
156
157int Projectile::getElecDamage () { return this->elecDamage; }
Note: See TracBrowser for help on using the repository browser.