1 #ifndef INC_INVADERS_H 2 #define INC_INVADERS_H 3 4 #include <vector> 5 #include <SDL/SDL.h> 6 7 #include "gfx.h" 8 #include "coords.h" 9 #include "collision.h" 10 #include "geom.h" 11 #include "ai.h" 12 13 class Node; 14 15 class Invader 16 { 17 protected: 18 virtual void doUpdate(int time) =0; 19 virtual Uint32 colour() const =0; 20 virtual Uint32 innerColour() const; 21 22 public: 23 // setCollTrajectory: Called after doUpdate; should set up a 24 // CollisionObject to be returned by subsequent calls to collObj, 25 // representing a linear approximation to the movement made by the 26 // object. 27 virtual void setCollTrajectory(CartCoord startPos, RelCartCoord 28 velocity) =0; 29 virtual const CollisionObject& collObj() const =0; 30 31 virtual bool dead() const =0; 32 33 // cpos: return current absolute position in the arena 34 virtual CartCoord cpos() const =0; 35 36 virtual int hit(int weight) =0; 37 virtual int die() =0; onDeath()38 virtual void onDeath() const {}; 39 evil()40 virtual bool evil() const { return true; } hitsYou()41 virtual bool hitsYou() const { return true; } hitsShots()42 virtual bool hitsShots() const { return true; } 43 fleeOnWin()44 virtual void fleeOnWin() {}; 45 killScore()46 virtual int killScore() const { return 1; } 47 48 // hitsInvaders: if returns r>0, hits invaders as a circle of radius r hitsInvaders()49 virtual float hitsInvaders() const { return 0; } 50 51 void update(int time); 52 dodge()53 virtual void dodge() {}; 54 55 std::vector<Invader*> spawns; 56 void spawnInvader(Invader* invader); 57 58 AIData aiData; 59 60 virtual void draw(SDL_Surface* surface, const View& view, View* 61 boundView=NULL, bool noAA=false) const =0; 62 Invader()63 Invader() {} ~Invader()64 virtual ~Invader() {}; 65 }; 66 67 class HPInvader : public virtual Invader 68 { 69 public: 70 int hp; 71 int armour; 72 virtual int hit(int weight); 73 bool dead() const; 74 int die(); 75 hp(ihp)76 HPInvader(int ihp=3, int iarmour=0) : hp(ihp), armour(iarmour) {} ~HPInvader()77 virtual ~HPInvader() {}; 78 }; 79 80 class SpirallingInvader : public virtual Invader 81 { 82 protected: 83 void doUpdate(int time); 84 85 virtual void drawSuper(SDL_Surface* surface, const View& view, View* 86 boundView=NULL, bool noAA=false) const; 87 public: 88 RelPolarCoord pos; 89 CartCoord focus; 90 float ds; 91 float dd; 92 93 virtual void dodge(); 94 95 virtual void fleeOnWin(); 96 97 SpirallingInvader(RelPolarCoord ipos, float ids=0, float idd=1, 98 CartCoord ifocus=ARENA_CENTRE) : pos(ipos)99 pos(ipos), focus(ifocus), ds(ids), dd(idd) {} 100 101 CartCoord cpos() const; 102 }; 103 104 class CircularInvader : public virtual Invader 105 { 106 public: 107 float radius; 108 CollisionCircle cc; 109 const CollisionObject& collObj() const; 110 void setCollTrajectory(CartCoord startPos, RelCartCoord velocity); 111 112 void draw(SDL_Surface* surface, const View& view, View* 113 boundView=NULL, bool noAA=false) const; 114 115 CircularInvader(float iradius=5) : radius(iradius)116 radius(iradius), cc(CartCoord(0,0), RelCartCoord(0,0), iradius) {} 117 }; 118 119 class SpirallingPolygonalInvader : public SpirallingInvader 120 { 121 protected: 122 void getAbsPoints(CartCoord* absPoints) const; 123 124 public: 125 int numPoints; 126 RelCartCoord* points; 127 128 CollisionPolygon cp; 129 const CollisionObject& collObj() const; 130 void setCollTrajectory(CartCoord startPos, RelCartCoord velocity); 131 132 virtual void draw(SDL_Surface* surface, const View& view, View* 133 boundView=NULL, bool noAA=false) const; 134 135 SpirallingPolygonalInvader(int inumPoints, RelPolarCoord ipos, float 136 ids=0, float idd=0, CartCoord ifocus=ARENA_CENTRE); 137 138 SpirallingPolygonalInvader( 139 const SpirallingPolygonalInvader& other); 140 141 SpirallingPolygonalInvader& operator=( 142 const SpirallingPolygonalInvader& other); 143 144 virtual ~SpirallingPolygonalInvader(); 145 }; 146 147 class BasicInvader : public HPInvader, public SpirallingInvader, public 148 CircularInvader 149 { 150 protected: 151 Uint32 colour() const; 152 public: 153 bool super; 154 155 virtual void draw(SDL_Surface* surface, const View& view, View* 156 boundView=NULL, bool noAA=false) const; 157 158 BasicInvader(int ihp, RelPolarCoord ipos, float ids=0, float idd=1, HPInvader(ihp)159 float iradius=5, bool isuper=false) : HPInvader(ihp), 160 SpirallingInvader(ipos, ids, idd), CircularInvader(iradius), 161 super(isuper) 162 {} 163 }; 164 165 class EggInvader : public BasicInvader 166 { 167 public: 168 EggInvader(RelPolarCoord ipos, float ids=0, bool super=false); 169 }; 170 class KamikazeInvader : public BasicInvader 171 { 172 protected: 173 void doUpdate(int time); 174 Uint32 colour() const; 175 Uint32 innerColour() const; 176 private: 177 int kamikaze; 178 int timer; 179 180 public: 181 KamikazeInvader(RelPolarCoord ipos, float ids=0, bool super=false); 182 }; 183 class SplittingInvader : public BasicInvader 184 { 185 private: 186 float spawnDist; 187 protected: 188 void doUpdate(int time); 189 public: 190 SplittingInvader(RelPolarCoord ipos, float ids=0, bool super=false); 191 void draw(SDL_Surface* surface, const View& view, View* 192 boundView=NULL, bool noAA=false) const; 193 }; 194 class InfestingInvader : public HPInvader, public CircularInvader, public SpirallingInvader 195 { 196 private: 197 float healRate; 198 float partialHP; 199 float shownHP; 200 bool infesting; 201 bool super; 202 int maxHP; 203 Angle glowPhase; 204 protected: 205 Uint32 colour() const; 206 void doUpdate(int time); 207 public: 208 Node* targetNode; 209 dodge()210 void dodge() {}; 211 212 void fleeOnWin(); 213 214 InfestingInvader(Node* itargetNode, bool super=false); 215 void draw(SDL_Surface* surface, const View& view, View* 216 boundView=NULL, bool noAA=false) const; 217 void onDeath() const; 218 }; 219 220 class CapturePod : public HPInvader, public CircularInvader, public SpirallingInvader 221 { 222 private: 223 Node* targetNode; 224 bool super; 225 protected: 226 Uint32 colour() const; 227 void doUpdate(int time); 228 public: dodge()229 void dodge() {}; 230 231 bool evil() const; 232 bool hitsYou() const; 233 float hitsInvaders() const; 234 235 void fleeOnWin(); 236 237 int killScore() const; 238 239 float primeRate; 240 CapturePod(Node* itargetNode, RelPolarCoord ipos, bool super=false); 241 }; 242 243 class FoulEggLayingInvader : public HPInvader, 244 public SpirallingPolygonalInvader 245 { 246 protected: 247 void doUpdate(int time); 248 void setPoints(int time); 249 float eggRadius; 250 251 static float eggRate; 252 static float layRadius; 253 254 Uint32 colour() const; 255 256 public: 257 int hit(int weight); 258 259 void draw(SDL_Surface* surface, const View& view, View* 260 boundView=NULL, bool noAA=false) const; 261 262 FoulEggLayingInvader(RelPolarCoord ipos, float ids=0, int ihp=5); 263 }; 264 265 #endif /* INC_INVADERS_H */ 266