]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/particles.cpp
Don't link pak tool with SDL.
[quix0rs-blobwars.git] / src / particles.cpp
1 /*
2 Copyright (C) 2004-2011 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 "particles.h"
22
23 void addWindParticles()
24 {
25         int c = graphics.white;
26         float x, y, dx, dy;
27         
28
29         for (int i = 0 ; i < 50 ; i++)
30         {
31                 if (player.x < 320)
32                 {
33                         x = Math::rrand(-100, 700);
34                 }
35                 else
36                 {
37                         x = player.x + Math::rrand(-450, 450);
38                 }
39                         
40                 c = Math::prand() % 4;
41                 switch (c)
42                 {
43                         case 0: c = graphics.white; break;
44                         case 1: c = graphics.lightGrey; break;
45                         case 2: c = graphics.grey; break;
46                         case 3: c = graphics.darkGrey; break;
47                 }
48                 
49                 y = player.y + Math::rrand(-450, 450);
50                 dx = Math::rrand(1, 100) * map.windPower;
51                 dx /= 100;
52                 dy = Math::rrand(1, 10); dy /= 10;
53                 map.addParticle(x, y, dx, dy, 120, c, NULL, PAR_WEIGHTLESS);
54         }
55 }
56
57 void addColorParticles(float x, float y, int amount, int color)
58 {
59         int c = color;
60         float dx, dy;
61
62         for (int i = 0 ; i < amount ; i++)
63         {
64                 if (color == -1)
65                 {
66                         c = Math::prand() % 5;
67                         switch (c)
68                         {
69                                 case 0: c = graphics.white; break;
70                                 case 1: c = graphics.grey; break;
71                                 case 2: c = graphics.blue; break;
72                                 case 3: c = graphics.cyan; break;
73                                 case 4: c = graphics.red; break;
74                         }
75                 }
76
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);
80         }
81 }
82
83 void addFireTrailParticle(float x, float y)
84 {
85         map.addParticle(x, y, 0, 0, 12, graphics.red, graphics.getSprite("SmallExplosion", true), PAR_WEIGHTLESS);
86 }
87
88 void addFireParticles(float x, float y, int amount)
89 {
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);
91 }
92
93 void addBubble(float x, float y)
94 {
95         if ((Math::prand() % 50) == 0)
96         {
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);
98         }
99 }
100
101 void throwStalagParticles(float x, float y)
102 {
103         Sprite *stalagPiece = graphics.getSprite("StalagPiece", true);
104         
105         int amount = Math::rrand(3, 6);
106         
107         for (int i = 0 ; i < amount ; i++)
108         {
109                 map.addParticle(x, y, Math::rrand(-2, 2), Math::rrand(-3, -1), Math::rrand(5, 30), graphics.red, stalagPiece, 0);
110         }
111 }
112
113 void throwBrickParticles(float x, float y)
114 {
115         int amount = Math::rrand(4, 8);
116         
117         Sprite *wallPiece = graphics.getSprite("WallPiece", true);
118         
119         for (int i = 0 ; i < amount ; i++)
120         {
121                 map.addParticle(x, y, Math::rrand(-2, 2), Math::rrand(-4, -1), Math::rrand(5, 30), graphics.red, wallPiece, 0);
122         }
123 }
124
125 void addTeleportParticles(float x, float y, int amount, int soundToPlay)
126 {
127         Sprite *teleportStar = graphics.getSprite("TeleportStar", true);
128         float dx, dy;
129
130         for (int i = 0 ; i < amount ; i++)
131         {
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);
135         }
136
137         if (soundToPlay != -1)
138         {
139                 audio.playSound(soundToPlay, CH_SPAWN);
140         }
141 }
142
143 void doParticles()
144 {
145         Particle *particle = (Particle*)map.particleList.getHead();
146         Particle *previous = particle;
147
148         int x, y;
149
150         while (particle->next != NULL)
151         {
152                 particle = (Particle*)particle->next;
153
154                 x = (int)(particle->x - engine.playerPosX);
155                 y = (int)(particle->y - engine.playerPosY);
156
157                 if (particle->sprite == NULL)
158                 {
159                         graphics.lock(graphics.screen);
160                         
161                         graphics.putPixel(x, y, particle->color, graphics.screen);
162                         
163                         graphics.unlock(graphics.screen);
164                 }
165                 else
166                 {
167                         graphics.blit(particle->getFrame(), x, y, graphics.screen, false);
168                 }
169
170                 particle->health--;
171
172                 particle->move();
173
174                 if (!(particle->flags & PAR_WEIGHTLESS))
175                 {
176                         particle->dy += 0.1;
177                 }
178
179                 x = (int)particle->x >> BRICKSHIFT;
180                 y = (int)particle->y >> BRICKSHIFT;
181
182                 if (particle->flags & PAR_COLLIDES)
183                 {
184                         if (map.isSolid(x, y))
185                         {
186                                 particle->health = 0;
187                         }
188                 }
189
190                 if (particle->health > 0)
191                 {
192                         previous = particle;
193                 }
194                 else
195                 {
196                         map.particleList.remove(previous, particle);
197                         particle = previous;
198                 }
199         }
200 }