2 Copyright (C) 2004-2011 Parallel Realities
3 Copyright (C) 2011-2015 Perpendicular Dimensions
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "explosions.h"
24 void addExplosion(float x, float y, int radius, Entity *owner)
26 audio.playSound(SND_GRENADE, CH_EXPLODE, x);
32 Sprite *explosion = graphics.getSprite("Explosion", true);
34 for (int i = 0 ; i < radius ; i++)
36 dx = Math::rrand(-radius, radius); dx /= 10;
37 dy = Math::rrand(-radius, radius); dy /= 10;
38 map.addParticle(x, y, dx, dy, Math::rrand(5, 30), graphics.white, explosion, PAR_WEIGHTLESS);
41 Entity *enemy = (Entity*)map.enemyList.getHead();
43 while (enemy->next != NULL)
45 enemy = (Entity*)enemy->next;
47 if ((enemy->flags & ENT_IMMUNE) || (enemy->flags & ENT_IMMUNEEXPLODE))
52 if (enemy->dead == DEAD_DYING)
57 distX = (int)fabs(enemy->x + (enemy->width / 2) - x);
58 distY = (int)fabs(enemy->y + (enemy->height / 2) - y);
63 distance = (int)sqrt(distX + distY);
65 if (radius - distance > 0)
67 if (enemy->health > 0)
69 enemy->health -= radius - distance;
71 if (enemy->health <= 0)
73 checkObjectives("Enemy", false);
74 checkObjectives(enemy->name, false);
77 if (!(enemy->flags & ENT_STATIC))
79 if (enemy->flags & ENT_EXPLODES)
81 audio.playSound(SND_ELECDEATH1 + Math::prand() % 3, CH_DEATH, enemy->x);
87 audio.playSound(SND_DEATH1 + Math::prand() % 3, CH_DEATH, enemy->x);
94 addPlayerScore(enemy->value);
98 for (int i = 0 ; i < 4 ; i++)
100 (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);
103 if (!(enemy->flags & ENT_STATIC))
105 enemy->dx = Math::rrand(-5, 5);
106 enemy->dy = Math::rrand(-5, 0);
111 if ((player.immune) || (player.health <= -60) || (owner == &player) || (game.missionOver > 0))
116 distX = (int)fabs(player.x + (player.width / 2) - x);
117 distY = (int)fabs(player.y + (player.height / 2) - y);
122 distance = (int)sqrt(distX + distY);
124 if (radius - distance >= 0)
125 throwAndDamageEntity(&player, 2, -3, 3, -8);