Removed that logo from this bramch aswell..
[dbw.git] / src / effects.cpp
blob255d04d90ead3a00e4b2498b502d37823f2a7cb6
1 /*
2 Copyright © 2004 Parallel Realities
3 Copyright © 2007-2008 Kővágó Zoltán <DirtY.iCE.hu@gmail.com>
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 "CEffect.h"
23 #include "CEngine.h"
24 #include "CGame.h"
25 #include "CGraphics.h"
26 #include "CMap.h"
27 #include "CMath.h"
29 void addEffect(float x, float y, float dx, float dy, int flags)
31 Effect *effect = new Effect();
33 effect->create(x, y, dx, dy, flags);
35 map.addEffect(effect);
38 void addColoredEffect(float x, float y, float dx, float dy, int color, int flags)
40 Effect *effect = new Effect();
42 effect->create(x, y, dx, dy, flags);
43 effect->health = Math::rrand(60, 90);
44 effect->color = color;
46 map.addEffect(effect);
49 void addSmokeAndFire(Entity *ent, float dx, float dy, int amount)
51 int x, y;
53 for (int i = 0 ; i < amount ; i++)
55 x = (int)(ent->x + rand() % ent->width);
56 y = (int)(ent->y + rand() % ent->height);
57 if ((rand() % 4) > 0)
59 addEffect(x, y, dx, dy, EFF_TRAILSFIRE);
61 else
63 addEffect(x, y, dx, dy, EFF_SMOKES);
68 void addBlood(Entity *ent, float dx, float dy, int amount)
70 int x, y;
72 if (engine.cheatBlood)
74 amount *= 3;
77 if (game.gore)
79 for (int i = 0 ; i < amount ; i++)
81 x = (int)(ent->x + rand() % ent->width);
82 y = (int)(ent->y + rand() % ent->height);
83 addEffect(x, y, dx, dy, EFF_BLEEDS);
88 void doEffects()
90 Effect *effect = (Effect*)map.effectList.getHead();
91 Effect *previous = effect;
93 Sprite *blood = graphics.getSprite("RedBloodParticle", true);
94 Sprite *explosion = graphics.getSprite("SmallExplosion", true);
95 Sprite *smoke = graphics.getSprite("Smoke", true);
97 int x, y;
99 while (effect->next != NULL)
101 effect = (Effect*)effect->next;
103 effect->update();
105 if (effect->flags & EFF_BLEEDS)
107 map.addParticle(effect->x, effect->y, 0, 1, Math::rrand(5, 30), graphics.red, blood, PAR_COLLIDES);
109 else if (effect->flags & EFF_TRAILSFIRE)
111 map.addParticle(effect->x, effect->y, 0, 1, Math::rrand(5, 30), graphics.red, explosion, PAR_COLLIDES);
113 else if (effect->flags & EFF_SMOKES)
115 map.addParticle(effect->x, effect->y, 0, 1, Math::rrand(5, 30), graphics.red, smoke, PAR_COLLIDES);
117 else if (effect->flags & EFF_COLORED)
119 map.addParticle(effect->x, effect->y, 0, 1, Math::rrand(5, 30), effect->color, NULL, PAR_COLLIDES);
122 x = (int)(effect->x - map.offsetX);
123 y = (int)(effect->y - map.offsetY);
125 if ((x < 0) || (y < 0))
127 effect->health = 0;
129 else
131 x = (int)effect->x >> BRICKSHIFT;
132 y = (int)effect->y >> BRICKSHIFT;
134 if (map.isSolid(x, y))
136 effect->health = 0;
140 if (effect->health > 0)
142 previous = effect;
144 else
146 map.effectList.remove(previous, effect);
147 effect = previous;