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 #include "Avatar.h"
24
25 Spore::Spores Spore::spores;
26
Spore(const Vector & position)27 Spore::Spore (const Vector &position) : CollideEntity()
28 {
29 spores.push_back(this);
30 scale = Vector(0.1, 0.1);
31 alpha = 0;
32
33 this->position = position;
34 alpha.interpolateTo(1, 0.5);
35 scale.interpolateTo(Vector(1, 1), 4);
36
37 setTexture("Spore");
38
39 setAllDamageTargets(false);
40 setEntityType(ET_ENEMY);
41 setDamageTarget(DT_AVATAR_ENERGYBLAST, true);
42 setDamageTarget(DT_AVATAR_SHOCK, true);
43 setDamageTarget(DT_AVATAR_ENERGYROLL, true);
44
45 health = maxHealth = 1;
46 }
47
isPositionClear(const Vector & position)48 bool Spore::isPositionClear(const Vector &position)
49 {
50 if (dsq->game->isObstructed(TileVector(position)))
51 return false;
52 for (Spores::iterator i = spores.begin(); i != spores.end(); i++)
53 {
54 Spore *s = *i;
55 if (s->position == position)
56 {
57 return false;
58 }
59 }
60 return true;
61 }
62
destroy()63 void Spore::destroy()
64 {
65 spores.remove(this);
66 CollideEntity::destroy();
67 }
68
onEndOfLife()69 void Spore::onEndOfLife()
70 {
71 //::onEndLife();
72 spores.remove(this);
73 }
74
onEnterState(int state)75 void Spore::onEnterState(int state)
76 {
77 CollideEntity::onEnterState(state);
78 if (state == STATE_DEAD)
79 {
80 setLife(1);
81 setDecayRate(4);
82 fadeAlphaWithLife = true;
83 }
84 }
85
killAllSpores()86 void Spore::killAllSpores()
87 {
88 std::queue<Spore*>sporeDeleteQueue;
89 for (Spores::iterator i = spores.begin(); i != spores.end(); i++)
90 {
91 sporeDeleteQueue.push(*i);
92 }
93 Spore *s = 0;
94 while (!sporeDeleteQueue.empty())
95 {
96 s = sporeDeleteQueue.front();
97 if (s)
98 {
99 s->safeKill();
100 }
101 sporeDeleteQueue.pop();
102 }
103 spores.clear();
104 }
105
onUpdate(float dt)106 void Spore::onUpdate(float dt)
107 {
108
109 CollideEntity::onUpdate(dt);
110
111 if (life < 1) return;
112 if (!(dsq->game->avatar->position - position).isLength2DIn(1024))
113 {
114 safeKill();
115 }
116 else
117 {
118 int sporeCr = 48;
119
120 collideRadius = scale.x * sporeCr;
121
122 if (touchAvatarDamage(collideRadius, 1, Vector(-1,-1,-1), 500))
123 {
124 // YAY!
125 }
126
127 dsq->game->handleShotCollisions(this);
128 }
129 }
130