]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/effects.cpp
Allow the game to run without sounds.
[quix0rs-blobwars.git] / src / effects.cpp
1 /*
2 Copyright (C) 2004 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 "effects.h"
22
23 void addEffect(float x, float y, float dx, float dy, int flags)
24 {
25         Effect *effect = new Effect();
26
27         effect->create(x, y, dx, dy, flags);
28
29         map.addEffect(effect);
30 }
31
32 void addColoredEffect(float x, float y, float dx, float dy, int color, int flags)
33 {
34         Effect *effect = new Effect();
35
36         effect->create(x, y, dx, dy, flags);
37         effect->health = Math::rrand(60, 90);
38         effect->color = color;
39
40         map.addEffect(effect);
41 }
42
43 void addSmokeAndFire(Entity *ent, float dx, float dy, int amount)
44 {
45         int x, y;
46
47         for (int i = 0 ; i < amount ; i++)
48         {
49                 x = (int)(ent->x + Math::prand() % ent->width);
50                 y = (int)(ent->y + Math::prand() % ent->height);
51                 if ((Math::prand() % 4) > 0)
52                 {
53                         addEffect(x, y, dx, dy, EFF_TRAILSFIRE);
54                 }
55                 else
56                 {
57                         addEffect(x, y, dx, dy, EFF_SMOKES);
58                 }
59         }
60 }
61
62 void addBlood(Entity *ent, float dx, float dy, int amount)
63 {
64         int x, y;
65         
66         if (engine.cheatBlood)
67         {
68                 amount *= 3;
69         }
70
71         if (game.gore)
72         {
73                 for (int i = 0 ; i < amount ; i++)
74                 {
75                         x = (int)(ent->x + Math::prand() % ent->width);
76                         y = (int)(ent->y + Math::prand() % ent->height);
77                         addEffect(x, y, dx, dy, EFF_BLEEDS);
78                 }
79         }
80 }
81
82 void doEffects()
83 {
84         Effect *effect = (Effect*)map.effectList.getHead();
85         Effect *previous = effect;
86
87         Sprite *blood = graphics.getSprite("RedBloodParticle", true);
88         Sprite *explosion = graphics.getSprite("SmallExplosion", true);
89         Sprite *smoke = graphics.getSprite("Smoke", true);
90
91         int x, y;
92
93         while (effect->next != NULL)
94         {
95                 effect = (Effect*)effect->next;
96
97                 effect->update();
98
99                 if (effect->flags & EFF_BLEEDS)
100                 {
101                         map.addParticle(effect->x, effect->y, 0, 1, Math::rrand(5, 30), graphics.red, blood, PAR_COLLIDES);
102                 }
103                 else if (effect->flags & EFF_TRAILSFIRE)
104                 {
105                         map.addParticle(effect->x, effect->y, 0, 1, Math::rrand(5, 30), graphics.red, explosion, PAR_COLLIDES);
106                 }
107                 else if (effect->flags & EFF_SMOKES)
108                 {
109                         map.addParticle(effect->x, effect->y, 0, 1, Math::rrand(5, 30), graphics.red, smoke, PAR_COLLIDES);
110                 }
111                 else if (effect->flags & EFF_COLORED)
112                 {
113                         map.addParticle(effect->x, effect->y, 0, 1, Math::rrand(5, 30), effect->color, NULL, PAR_COLLIDES);
114                 }
115
116                 x = (int)(effect->x - engine.playerPosX);
117                 y = (int)(effect->y - engine.playerPosY);
118
119                 if ((x < 0) || (y < 0))
120                 {
121                         effect->health = 0;
122                 }
123                 else
124                 {
125                         x = (int)effect->x >> BRICKSHIFT;
126                         y = (int)effect->y >> BRICKSHIFT;
127
128                         if (map.isSolid(x, y))
129                         {
130                                 effect->health = 0;
131                         }
132                 }
133
134                 if (effect->health > 0)
135                 {
136                         previous = effect;
137                 }
138                 else
139                 {
140                         map.effectList.remove(previous, effect);
141                         effect = previous;
142                 }
143         }
144 }