2 Copyright (C) 2004 Parallel Realities
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "explosions.h"
23 void addExplosion(float x, float y, int radius, Entity *owner)
25 audio.playSound(SND_GRENADE, CH_EXPLODE);
31 Sprite *explosion = graphics.getSprite("Explosion", true);
33 for (int i = 0 ; i < radius ; i++)
35 dx = Math::rrand(-radius, radius); dx /= 10;
36 dy = Math::rrand(-radius, radius); dy /= 10;
37 map.addParticle(x, y, dx, dy, Math::rrand(5, 30), graphics.white, explosion, PAR_WEIGHTLESS);
40 Entity *enemy = (Entity*)map.enemyList.getHead();
42 while (enemy->next != NULL)
44 enemy = (Entity*)enemy->next;
46 if ((enemy->flags & ENT_IMMUNE) || (enemy->flags & ENT_IMMUNEEXPLODE))
51 if (enemy->dead == DEAD_DYING)
56 distX = (int)fabs(enemy->x + (enemy->width / 2) - x);
57 distY = (int)fabs(enemy->y + (enemy->height / 2) - y);
62 distance = (int)sqrt(distX + distY);
64 if (radius - distance > 0)
66 if (enemy->health > 0)
68 enemy->health -= radius - distance;
70 if (enemy->health <= 0)
72 checkObjectives("Enemy", false);
73 checkObjectives(enemy->name, false);
76 if (!(enemy->flags & ENT_STATIC))
78 if (enemy->flags & ENT_EXPLODES)
80 audio.playSound(SND_ELECDEATH1 + Math::prand() % 3, CH_DEATH);
86 audio.playSound(SND_DEATH1 + Math::prand() % 3, CH_DEATH);
93 addPlayerScore(enemy->value);
97 for (int i = 0 ; i < 4 ; i++)
99 (enemy->flags & ENT_EXPLODES) ? addSmokeAndFire(enemy, Math::rrand(-15, 5), Math::rrand(-15, 5), 2) : addBlood(enemy, Math::rrand(-5, 5), Math::rrand(-5, 5), 1);
102 if (!(enemy->flags & ENT_STATIC))
104 enemy->dx = Math::rrand(-5, 5);
105 enemy->dy = Math::rrand(-5, 0);
110 if ((player.immune) || (player.health <= -60) || (owner == &player) || (game.missionOver > 0))
115 distX = (int)fabs(player.x + (player.width / 2) - x);
116 distY = (int)fabs(player.y + (player.height / 2) - y);
121 distance = (int)sqrt(distX + distY);
123 if (radius - distance >= 0)
124 throwAndDamageEntity(&player, 2, -3, 3, -8);