Some Window$ specific edits.
[dbw.git] / src / effects.cpp
blobe4e050ee1b3cbb16062f199cdbc7fca75b53b84d
1 /*
2 Copyright (C) 2004 Parallel Realities
3 Copyright (C) 2007 Kővágó Zoltán
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 "effects.h"
24 void addEffect(float x, float y, float dx, float dy, int flags)
26 Effect *effect = new Effect();
28 effect->create(x, y, dx, dy, flags);
30 map.addEffect(effect);
33 void addColoredEffect(float x, float y, float dx, float dy, int color, int flags)
35 Effect *effect = new Effect();
37 effect->create(x, y, dx, dy, flags);
38 effect->health = Math::rrand(60, 90);
39 effect->color = color;
41 map.addEffect(effect);
44 void addSmokeAndFire(Entity *ent, float dx, float dy, int amount)
46 int x, y;
48 for (int i = 0 ; i < amount ; i++)
50 x = (int)(ent->x + rand() % ent->width);
51 y = (int)(ent->y + rand() % ent->height);
52 if ((rand() % 4) > 0)
54 addEffect(x, y, dx, dy, EFF_TRAILSFIRE);
56 else
58 addEffect(x, y, dx, dy, EFF_SMOKES);
63 void addBlood(Entity *ent, float dx, float dy, int amount)
65 int x, y;
67 if (engine.cheatBlood)
69 amount *= 3;
72 if (game.gore)
74 for (int i = 0 ; i < amount ; i++)
76 x = (int)(ent->x + rand() % ent->width);
77 y = (int)(ent->y + rand() % ent->height);
78 addEffect(x, y, dx, dy, EFF_BLEEDS);
83 void doEffects()
85 Effect *effect = (Effect*)map.effectList.getHead();
86 Effect *previous = effect;
88 Sprite *blood = graphics.getSprite("RedBloodParticle", true);
89 Sprite *explosion = graphics.getSprite("SmallExplosion", true);
90 Sprite *smoke = graphics.getSprite("Smoke", true);
92 int x, y;
94 while (effect->next != NULL)
96 effect = (Effect*)effect->next;
98 effect->update();
100 if (effect->flags & EFF_BLEEDS)
102 map.addParticle(effect->x, effect->y, 0, 1, Math::rrand(5, 30), graphics.red, blood, PAR_COLLIDES);
104 else if (effect->flags & EFF_TRAILSFIRE)
106 map.addParticle(effect->x, effect->y, 0, 1, Math::rrand(5, 30), graphics.red, explosion, PAR_COLLIDES);
108 else if (effect->flags & EFF_SMOKES)
110 map.addParticle(effect->x, effect->y, 0, 1, Math::rrand(5, 30), graphics.red, smoke, PAR_COLLIDES);
112 else if (effect->flags & EFF_COLORED)
114 map.addParticle(effect->x, effect->y, 0, 1, Math::rrand(5, 30), effect->color, NULL, PAR_COLLIDES);
117 x = (int)(effect->x - map.offsetX);
118 y = (int)(effect->y - map.offsetY);
120 if ((x < 0) || (y < 0))
122 effect->health = 0;
124 else
126 x = (int)effect->x >> BRICKSHIFT;
127 y = (int)effect->y >> BRICKSHIFT;
129 if (map.isSolid(x, y))
131 effect->health = 0;
135 if (effect->health > 0)
137 previous = effect;
139 else
141 map.effectList.remove(previous, effect);
142 effect = previous;