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 |
---|
14 | |
---|
15 | */ |
---|
16 | |
---|
17 | |
---|
18 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
19 | |
---|
20 | #include "acid_splash.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(AcidSplash); |
---|
32 | CREATE_FAST_FACTORY_STATIC(AcidSplash); |
---|
33 | |
---|
34 | /** |
---|
35 | * standard constructor |
---|
36 | */ |
---|
37 | AcidSplash::AcidSplash () : Projectile() |
---|
38 | { |
---|
39 | this->registerObject(this, AcidSplash::_objectList); |
---|
40 | |
---|
41 | // moved to baseObject |
---|
42 | // srand(time(0)); //initialize Random Nomber Generator |
---|
43 | |
---|
44 | this->setMinEnergy(1); |
---|
45 | this->setHealthMax(0); |
---|
46 | this->lifeSpan = 3.0; |
---|
47 | this->angle = 0; |
---|
48 | |
---|
49 | this->grid = new Wobblegrid( 5); |
---|
50 | this->grid->setParent( this); |
---|
51 | this->grid->setVisibility(false); |
---|
52 | |
---|
53 | |
---|
54 | int rnd = int(rand() % 3); |
---|
55 | |
---|
56 | switch (rnd){ |
---|
57 | case 0: |
---|
58 | this->grid->setTexture( "textures/acid2.png"); |
---|
59 | break; |
---|
60 | case 1: |
---|
61 | this->grid->setTexture( "textures/acid3.png"); |
---|
62 | break; |
---|
63 | case 2: |
---|
64 | this->grid->setTexture( "textures/blub.png"); |
---|
65 | break; |
---|
66 | default: |
---|
67 | this->grid->setTexture( "textures/acid2.png"); |
---|
68 | } |
---|
69 | |
---|
70 | this->grid->toList(OM_ENVIRON); |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | /** |
---|
75 | * standard deconstructor |
---|
76 | * |
---|
77 | */ |
---|
78 | AcidSplash::~AcidSplash () |
---|
79 | { |
---|
80 | this->grid->toList(OM_DEAD); |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | void AcidSplash::activate() |
---|
85 | { |
---|
86 | this->origList = this->getOMListNumber(); |
---|
87 | this->toList(OM_ENVIRON); |
---|
88 | // this->unhide(); |
---|
89 | this->grid->setVisibility(true); |
---|
90 | |
---|
91 | this->setPhysDamage(10); |
---|
92 | this->setElecDamage(0); |
---|
93 | this->setHealth(0); |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | void AcidSplash::deactivate() |
---|
98 | { |
---|
99 | this->lifeCycle = 0.0; |
---|
100 | |
---|
101 | // this->hide(); |
---|
102 | this->grid->setVisibility(false); |
---|
103 | this->lifeCycle = 0.0; |
---|
104 | this->toList(OM_NULL); |
---|
105 | //this->toList(OM_DEAD); |
---|
106 | // this->removeNode(); |
---|
107 | |
---|
108 | AcidSplash::fastFactory->kill(this); |
---|
109 | } |
---|
110 | |
---|
111 | |
---|
112 | /** |
---|
113 | * signal tick, time dependent things will be handled here |
---|
114 | * @param dt time since last tick |
---|
115 | */ |
---|
116 | void AcidSplash::tick (float dt) |
---|
117 | { |
---|
118 | Vector v = this->velocity * dt; |
---|
119 | this->shiftCoor(v); |
---|
120 | |
---|
121 | if (this->tickLifeCycle(dt)) |
---|
122 | this->deactivate(); |
---|
123 | |
---|
124 | this->angle += this->rotationSpeed * dt; |
---|
125 | |
---|
126 | this->grid->tick(dt); |
---|
127 | |
---|
128 | for( ObjectList<Playable>::const_iterator eIterator = Playable::objectList().begin(); eIterator !=Playable::objectList().end(); eIterator++) |
---|
129 | { |
---|
130 | if( ((*eIterator)->getOMListNumber() != (this->origList -1)) && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 8) |
---|
131 | { |
---|
132 | (*eIterator)->hit (this->getDamage(),this); |
---|
133 | this->deactivate(); |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | } |
---|
138 | |
---|
139 | /** |
---|
140 | * the function gets called, when the projectile is destroyed |
---|
141 | */ |
---|
142 | void AcidSplash::destroy (WorldEntity* killer) |
---|
143 | { |
---|
144 | this->deactivate(); |
---|
145 | Projectile::destroy( killer ); |
---|
146 | PRINTF(5)("DESTROY AcidSplash\n"); |
---|
147 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
148 | } |
---|
149 | |
---|
150 | |
---|
151 | void AcidSplash::draw () const |
---|
152 | { |
---|
153 | this->grid->draw(); |
---|
154 | } |
---|