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