1 /*
2 Copyright (C) 2007, 2010 - Bit-Blot
3 
4 This file is part of Aquaria.
5 
6 Aquaria is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 
15 See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21 #include "Shot.h"
22 #include "Game.h"
23 
24 const float pSpawnRate = 1.0;
GasCloud(Entity * source,const Vector & position,const std::string & particles,const Vector & color,int radius,float life,float damage,bool isMoney,float poisonTime)25 GasCloud::GasCloud(Entity *source, const Vector &position, const std::string &particles, const Vector &color, int radius, float life, float damage, bool isMoney, float poisonTime) : Entity()
26 {
27 	sourceEntity = source;
28 
29 	this->poisonTime = poisonTime;
30 
31 	this->particles = particles;
32 	//this->gfx = gfx;
33 	//this->isMoney = isMoney;
34 	this->position = position;
35 	this->damage = damage;
36 	this->radius = radius;
37 	pTimer = 0;
38 	setLife(life);
39 	setDecayRate(1);
40 	renderQuad = false;
41 	this->color = color;
42 	pTimer = pSpawnRate*10;
43 	vel = Vector(0,-100);
44 
45 	emitter = new ParticleEffect;
46 	emitter->load(particles);
47 	emitter->start();
48 	emitter->setDie(true);
49 	//emitter->parentManagedStatic = true;
50 	//addChild(&emitter);
51 	dsq->game->addRenderObject(emitter, LR_PARTICLES);
52 	//setDamageTarget(DT_ENEMY_GAS, false)
53 	setEntityType(ET_NEUTRAL);
54 
55 	deathSound = "";
56 }
57 
onUpdate(float dt)58 void GasCloud::onUpdate(float dt)
59 {
60 	Entity::onUpdate(dt);
61 	if (emitter)
62 		emitter->position = this->position;
63 	if (life > 0.1f)
64 	{
65 		if (damage > 0)
66 		{
67 			FOR_ENTITIES(i)
68 			{
69 				Entity *e = (*i);
70 				if (e != this && (e->getEntityType() == ET_ENEMY || e->getEntityType() == ET_AVATAR) && e->isDamageTarget(DT_ENEMY_GAS) && (e->position - position).isLength2DIn(radius + e->collideRadius))
71 				{
72 					bool doit = (sourceEntity != e);
73 					if (doit && sourceEntity)
74 					{
75 						if (sourceEntity->getEntityType() == ET_AVATAR)
76 							doit = ((e->getEntityType() == ET_ENEMY) && doit);
77 					}
78 
79 					if (doit)
80 					{
81 						DamageData d;
82 						d.attacker = 0;
83 						d.damageType = DT_ENEMY_GAS;
84 						d.damage = this->damage;
85 						e->damage(d);
86 
87 						if (poisonTime > 0)
88 						{
89 							if (e->isDamageTarget(DT_ENEMY_POISON))
90 							{
91 								e->setPoison(1, poisonTime);
92 							}
93 						}
94 					}
95 				}
96 			}
97 
98 		}
99 		/*
100 		pTimer += dt;
101 		while (pTimer > pSpawnRate)
102 		{
103 			int a = rand()%360;
104 			int r = rand()%radius;
105 			Vector pos = position;
106 			pos += Vector(sinf(a)*r, cosf(a)*r);
107 			Quad *quad = new Quad;
108 			{
109 				quad->rotation.z = rand()%360;
110 				quad->position = pos;
111 				quad->color = color;
112 				quad->setTexture(gfx);
113 				quad->alpha.path.addPathNode(0, 0);
114 				quad->alpha.path.addPathNode(0.5, 0.2);
115 				quad->alpha.path.addPathNode(0.5, 0.8);
116 				quad->alpha.path.addPathNode(0, 1);
117 				quad->alpha.startPath(3);
118 				quad->scale = Vector(0.5, 0.5);
119 				quad->scale.interpolateTo(Vector(2,2),4);
120 			}
121 			dsq->getTopStateData()->addRenderObject(quad, LR_PARTICLES);
122 			pTimer -= pSpawnRate;
123 		}
124 		*/
125 	}
126 	else
127 	{
128 		if (emitter && emitter->isRunning())
129 		{
130 			emitter->stop();
131 			emitter = 0;
132 		}
133 	}
134 }
135