]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/explosions.cpp
Allow playing sounds with stereo effects.
[quix0rs-blobwars.git] / src / explosions.cpp
1 /*
2 Copyright (C) 2004-2011 Parallel Realities
3 Copyright (C) 2011-2015 Perpendicular Dimensions
4
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.
9
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.
13
14 See the GNU General Public License for more details.
15
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.
19
20 */
21
22 #include "explosions.h"
23
24 void addExplosion(float x, float y, int radius, Entity *owner)
25 {
26         audio.playSound(SND_GRENADE, CH_EXPLODE);
27
28         float dx, dy;
29         int distX, distY;
30         int distance;
31
32         Sprite *explosion = graphics.getSprite("Explosion", true);
33
34         for (int i = 0 ; i < radius ; i++)
35         {
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);
39         }
40
41         Entity *enemy = (Entity*)map.enemyList.getHead();
42
43         while (enemy->next != NULL)
44         {
45                 enemy = (Entity*)enemy->next;
46                 
47                 if ((enemy->flags & ENT_IMMUNE) || (enemy->flags & ENT_IMMUNEEXPLODE))
48                 {
49                         continue;
50                 }
51                 
52                 if (enemy->dead == DEAD_DYING)
53                 {
54                         continue;
55                 }
56
57                 distX = (int)fabs(enemy->x + (enemy->width / 2) - x);
58                 distY = (int)fabs(enemy->y + (enemy->height / 2) - y);
59
60                 distX *= distX;
61                 distY *= distY;
62
63                 distance = (int)sqrt(distX + distY);
64
65                 if (radius - distance > 0)
66                 {       
67                         if (enemy->health > 0)
68                         {
69                                 enemy->health -= radius - distance;
70                                 
71                                 if (enemy->health <= 0)
72                                 {       
73                                         checkObjectives("Enemy", false);
74                                         checkObjectives(enemy->name, false);
75                                 }
76                                 
77                                 if (!(enemy->flags & ENT_STATIC))
78                                 {
79                                         if (enemy->flags & ENT_EXPLODES)
80                                         {
81                                                 audio.playSound(SND_ELECDEATH1 + Math::prand() % 3, CH_DEATH);
82                                         }
83                                         else
84                                         {
85                                                 if (game.gore)
86                                                 {
87                                                         audio.playSound(SND_DEATH1 + Math::prand() % 3, CH_DEATH);
88                                                 }
89                                         }
90                                 }
91                                 
92                                 if (owner == &player)
93                                 {
94                                         addPlayerScore(enemy->value);
95                                 }
96                         }
97                         
98                         for (int i = 0 ; i < 4 ; i++)
99                         {
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);
101                         }
102                                 
103                         if (!(enemy->flags & ENT_STATIC))
104                         {
105                                 enemy->dx = Math::rrand(-5, 5);
106                                 enemy->dy = Math::rrand(-5, 0);
107                         }
108                 }
109         }
110
111         if ((player.immune) || (player.health <= -60) || (owner == &player) || (game.missionOver > 0))
112         {
113                 return;
114         }
115
116         distX = (int)fabs(player.x + (player.width / 2) - x);
117         distY = (int)fabs(player.y + (player.height / 2) - y);
118
119         distX *= distX;
120         distY *= distY;
121
122         distance = (int)sqrt(distX + distY);
123
124         if (radius - distance >= 0)
125                 throwAndDamageEntity(&player, 2, -3, 3, -8);
126 }