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 | // #include "effects/wobblegrid.h" |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | ObjectListDefinition(PlasmaPulse); |
---|
32 | CREATE_FAST_FACTORY_STATIC(PlasmaPulse); |
---|
33 | |
---|
34 | /** |
---|
35 | * standard constructor |
---|
36 | */ |
---|
37 | PlasmaPulse::PlasmaPulse () : Projectile() |
---|
38 | { |
---|
39 | this->registerObject(this, PlasmaPulse::_objectList); |
---|
40 | |
---|
41 | // srand(time(0)); //initialize Random Nomber Generator |
---|
42 | |
---|
43 | //this->loadModel("models/projectiles/laser.obj"); |
---|
44 | |
---|
45 | this->setMinEnergy(1); |
---|
46 | this->setHealthMax(0); |
---|
47 | this->lifeSpan = 3.0; |
---|
48 | // this->angle = 0; |
---|
49 | |
---|
50 | this->grid = new Billboard(); |
---|
51 | this->grid->setSize(.2, .2); |
---|
52 | this->grid->setPulseMagnitude(.8); |
---|
53 | this->grid->setParent(this); |
---|
54 | this->grid->setVisibility(false); |
---|
55 | this->grid->setPulse(); |
---|
56 | |
---|
57 | this->grid->setTexture( "textures/plasma.png"); |
---|
58 | |
---|
59 | this->grid->toList(OM_ENVIRON); |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | /** |
---|
64 | * standard deconstructor |
---|
65 | * |
---|
66 | */ |
---|
67 | PlasmaPulse::~PlasmaPulse () |
---|
68 | { |
---|
69 | this->grid->toList(OM_DEAD); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | void PlasmaPulse::activate() |
---|
74 | { |
---|
75 | this->origList = this->getOMListNumber(); |
---|
76 | this->toList(OM_ENVIRON); |
---|
77 | this->grid->setVisibility(true); |
---|
78 | |
---|
79 | this->setPhysDamage(10); |
---|
80 | this->setElecDamage(0); |
---|
81 | this->setHealth(0); |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | void PlasmaPulse::deactivate() |
---|
86 | { |
---|
87 | this->lifeCycle = 0.0; |
---|
88 | |
---|
89 | // this->hide(); |
---|
90 | this->grid->setVisibility(false); |
---|
91 | this->lifeCycle = 0.0; |
---|
92 | this->toList(OM_NULL); |
---|
93 | //this->toList(OM_DEAD); |
---|
94 | this->removeNode(); |
---|
95 | |
---|
96 | PlasmaPulse::fastFactory->kill(this); |
---|
97 | } |
---|
98 | |
---|
99 | /** |
---|
100 | * signal tick, time dependent things will be handled here |
---|
101 | * @param dt time since last tick |
---|
102 | */ |
---|
103 | void PlasmaPulse::tick (float dt) |
---|
104 | { |
---|
105 | Vector v = this->velocity * dt; |
---|
106 | this->shiftCoor(v); |
---|
107 | |
---|
108 | if (this->tickLifeCycle(dt)) |
---|
109 | this->deactivate(); |
---|
110 | |
---|
111 | this->grid->tick(dt); |
---|
112 | |
---|
113 | for( ObjectList<Playable>::const_iterator eIterator = Playable::objectList().begin(); eIterator !=Playable::objectList().end(); eIterator++) |
---|
114 | { |
---|
115 | if( ((*eIterator)->getOMListNumber() != (this->origList -1)) && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 3) |
---|
116 | { |
---|
117 | (*eIterator)->hit (this->getDamage(),this); |
---|
118 | this->deactivate(); |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | } |
---|
123 | |
---|
124 | /** |
---|
125 | * the function gets called, when the projectile is destroyed |
---|
126 | */ |
---|
127 | void PlasmaPulse::destroy (WorldEntity* killer) |
---|
128 | { |
---|
129 | this->deactivate(); |
---|
130 | Projectile::destroy( killer ); |
---|
131 | PRINTF(5)("DESTROY PlasmaPulse\n"); |
---|
132 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | void PlasmaPulse::draw () const |
---|
137 | { |
---|
138 | this->grid->draw(); |
---|
139 | } |
---|