1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004-2006 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific |
---|
12 | main-programmer: Marc Schaerrer |
---|
13 | co-programmer: Benjamin Grauer, Nicolas Schlumberger |
---|
14 | |
---|
15 | */ |
---|
16 | |
---|
17 | |
---|
18 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
19 | |
---|
20 | #include "plasma_pulse.h" |
---|
21 | |
---|
22 | #include "state.h" |
---|
23 | |
---|
24 | #include <cassert> |
---|
25 | #include "debug.h" |
---|
26 | |
---|
27 | |
---|
28 | ObjectListDefinition(PlasmaPulse); |
---|
29 | CREATE_FAST_FACTORY_STATIC(PlasmaPulse); |
---|
30 | |
---|
31 | /** |
---|
32 | * standard constructor |
---|
33 | */ |
---|
34 | PlasmaPulse::PlasmaPulse () : Projectile() |
---|
35 | { |
---|
36 | this->registerObject(this, PlasmaPulse::_objectList); |
---|
37 | |
---|
38 | |
---|
39 | this->setMinEnergy(1); |
---|
40 | this->setHealthMax(0); |
---|
41 | this->lifeSpan = 2.0; |
---|
42 | |
---|
43 | this->grid = new Billboard(); |
---|
44 | this->grid->setSize(.2, .2); |
---|
45 | this->grid->setPulseMagnitude(.8); |
---|
46 | this->grid->setParent(this); |
---|
47 | this->grid->setVisibility(false); |
---|
48 | this->grid->setPulse(); |
---|
49 | |
---|
50 | this->grid->setTexture( "textures/plasma.png"); |
---|
51 | |
---|
52 | this->grid->toList(OM_ENVIRON); |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | /** |
---|
57 | * standard deconstructor |
---|
58 | * |
---|
59 | */ |
---|
60 | PlasmaPulse::~PlasmaPulse () |
---|
61 | { |
---|
62 | this->grid->toList(OM_DEAD); |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | void PlasmaPulse::activate() |
---|
67 | { |
---|
68 | this->origList = this->getOMListNumber(); |
---|
69 | this->toList(OM_ENVIRON); |
---|
70 | this->grid->setVisibility(true); |
---|
71 | |
---|
72 | this->setPhysDamage(10); |
---|
73 | this->setElecDamage(0); |
---|
74 | this->setHealth(0); |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | void PlasmaPulse::deactivate() |
---|
79 | { |
---|
80 | this->lifeCycle = 0.0; |
---|
81 | |
---|
82 | this->grid->setVisibility(false); |
---|
83 | this->lifeCycle = 0.0; |
---|
84 | this->toList(OM_NULL); |
---|
85 | // this->removeNode(); |
---|
86 | |
---|
87 | PlasmaPulse::fastFactory->kill(this); |
---|
88 | } |
---|
89 | |
---|
90 | /** |
---|
91 | * signal tick, time dependent things will be handled here |
---|
92 | * @param dt time since last tick |
---|
93 | */ |
---|
94 | void PlasmaPulse::tick (float dt) |
---|
95 | { |
---|
96 | Vector v = this->velocity * dt; |
---|
97 | this->shiftCoor(v); |
---|
98 | |
---|
99 | if (this->tickLifeCycle(dt)) |
---|
100 | this->deactivate(); |
---|
101 | |
---|
102 | this->grid->tick(dt); |
---|
103 | |
---|
104 | for( ObjectList<Playable>::const_iterator eIterator = Playable::objectList().begin(); eIterator !=Playable::objectList().end(); eIterator++) |
---|
105 | { |
---|
106 | if( ((*eIterator)->getOMListNumber() != (this->origList -1)) && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 3) |
---|
107 | { |
---|
108 | (*eIterator)->hit (this->getDamage(),this); |
---|
109 | this->deactivate(); |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | * the function gets called, when the projectile is destroyed |
---|
117 | */ |
---|
118 | void PlasmaPulse::destroy (WorldEntity* killer) |
---|
119 | { |
---|
120 | this->deactivate(); |
---|
121 | Projectile::destroy( killer ); |
---|
122 | PRINTF(5)("DESTROY PlasmaPulse\n"); |
---|
123 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | void PlasmaPulse::draw () const |
---|
128 | { |
---|
129 | glPushMatrix(); |
---|
130 | glEnable( GL_ALPHA_TEST); |
---|
131 | glAlphaFunc( GL_GEQUAL, .5); |
---|
132 | this->grid->draw(); |
---|
133 | glPopMatrix(); |
---|
134 | |
---|
135 | } |
---|