2 Copyright (C) 2004-2011 Parallel Realities
3 Copyright (C) 2011-2015 Perpendicular Dimensions
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 "particles.h"
24 void addWindParticles()
26 int c = graphics.white;
30 for (int i = 0 ; i < 50 ; i++)
34 x = Math::rrand(-100, 700);
38 x = player.x + Math::rrand(-450, 450);
41 c = Math::prand() % 4;
44 case 0: c = graphics.white; break;
45 case 1: c = graphics.lightGrey; break;
46 case 2: c = graphics.grey; break;
47 case 3: c = graphics.darkGrey; break;
50 y = player.y + Math::rrand(-450, 450);
51 dx = Math::rrand(1, 100) * map.windPower;
53 dy = Math::rrand(1, 10); dy /= 10;
54 map.addParticle(x, y, dx, dy, 120, c, NULL, PAR_WEIGHTLESS);
58 void addColorParticles(float x, float y, int amount, int color)
63 for (int i = 0 ; i < amount ; i++)
66 c = Math::prand() % 5;
70 case 0: c = graphics.white; break;
71 case 1: c = graphics.grey; break;
72 case 2: c = graphics.blue; break;
73 case 3: c = graphics.cyan; break;
74 case 4: c = graphics.red; break;
77 dx = Math::rrand(-30, 30); dx /= 30;
78 dy = Math::rrand(-30, 30); dy /= 30;
79 map.addParticle(x, y, dx, dy, Math::rrand(5, 30), c, NULL, 0);
83 void addFireTrailParticle(float x, float y)
85 map.addParticle(x, y, 0, 0, 12, graphics.red, graphics.getSprite("SmallExplosion", true), PAR_WEIGHTLESS);
88 void addFireParticles(float x, float y, int amount)
90 map.addParticle(x + Math::rrand(-2, 2), y + Math::rrand(-2, 2), 0, 1, Math::rrand(5, 30), graphics.red, graphics.getSprite("Explosion", true), PAR_COLLIDES);
93 void addBubble(float x, float y)
95 if ((Math::prand() % 50) == 0)
97 map.addParticle(x + Math::prand() % BRICKSIZE, y + 19, 0, Math::rrand(-3, -1), Math::rrand(30, 90), graphics.red, graphics.getSprite("Bubble", true), PAR_COLLIDES | PAR_WEIGHTLESS | PAR_LIQUID);
101 void throwStalagParticles(float x, float y)
103 Sprite *stalagPiece = graphics.getSprite("StalagPiece", true);
105 int amount = Math::rrand(3, 6);
107 for (int i = 0 ; i < amount ; i++)
109 map.addParticle(x, y, Math::rrand(-2, 2), Math::rrand(-3, -1), Math::rrand(5, 30), graphics.red, stalagPiece, 0);
113 void throwBrickParticles(float x, float y)
115 int amount = Math::rrand(4, 8);
117 Sprite *wallPiece = graphics.getSprite("WallPiece", true);
119 for (int i = 0 ; i < amount ; i++)
121 map.addParticle(x, y, Math::rrand(-2, 2), Math::rrand(-4, -1), Math::rrand(5, 30), graphics.red, wallPiece, 0);
125 void addTeleportParticles(float x, float y, int amount, int soundToPlay)
127 Sprite *teleportStar = graphics.getSprite("TeleportStar", true);
130 for (int i = 0 ; i < amount ; i++)
132 dx = Math::rrand(-30, 30); dx /= 20;
133 dy = Math::rrand(-30, 30); dy /= 20;
134 map.addParticle(x, y, dx, dy, Math::rrand(30, 60), graphics.red, teleportStar, PAR_WEIGHTLESS);
137 if (soundToPlay != -1)
139 audio.playSound(soundToPlay, CH_SPAWN, x);
145 Particle *particle = (Particle*)map.particleList.getHead();
146 Particle *previous = particle;
150 while (particle->next != NULL)
152 particle = (Particle*)particle->next;
154 x = (int)(particle->x - engine.playerPosX);
155 y = (int)(particle->y - engine.playerPosY);
157 if (particle->sprite == NULL)
159 graphics.lock(graphics.screen);
161 graphics.putPixel(x, y, particle->color, graphics.screen);
163 graphics.unlock(graphics.screen);
167 graphics.blit(particle->getFrame(), x, y, graphics.screen, false);
174 if (!(particle->flags & PAR_WEIGHTLESS))
179 x = (int)particle->x >> BRICKSHIFT;
180 y = (int)particle->y >> BRICKSHIFT;
182 if (particle->flags & PAR_COLLIDES)
184 if (map.isSolid(x, y))
186 particle->health = 0;
190 if (particle->flags & PAR_LIQUID)
192 if (!map.isLiquid(x, y))
194 particle->health = 0;
198 if (particle->health > 0)
204 map.particleList.remove(previous, particle);