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