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.
24 #include "CGraphics.h"
27 #include "CParticle.h"
29 void addWindParticles()
31 int c
= graphics
.white
;
36 x
= Math::rrand(-100, 700);
40 x
= player
.x
+ Math::rrand(-450, 450);
43 for (int i
= 0 ; i
< 50 ; i
++)
49 case 0: c
= graphics
.white
; break;
50 case 1: c
= graphics
.lightGrey
; break;
51 case 2: c
= graphics
.grey
; break;
52 case 3: c
= graphics
.darkGrey
; break;
55 y
= player
.y
+ Math::rrand(-450, 450);
56 dx
= Math::rrand(1, 100) * map
.windPower
;
58 dy
= Math::rrand(1, 10); dy
/= 10;
59 map
.addParticle(x
, y
, dx
, dy
, 120, c
, NULL
, PAR_WEIGHTLESS
);
63 void addColorParticles(float x
, float y
, int amount
, int color
)
68 for (int i
= 0 ; i
< amount
; i
++)
75 case 0: c
= graphics
.white
; break;
76 case 1: c
= graphics
.grey
; break;
77 case 2: c
= graphics
.blue
; break;
78 case 3: c
= graphics
.cyan
; break;
79 case 4: c
= graphics
.red
; break;
83 dx
= Math::rrand(-30, 30); dx
/= 30;
84 dy
= Math::rrand(-30, 30); dy
/= 30;
85 map
.addParticle(x
, y
, dx
, dy
, Math::rrand(5, 30), c
, NULL
, 0);
89 void addFireTrailParticle(float x
, float y
)
91 map
.addParticle(x
, y
, 0, 0, 12, graphics
.red
, graphics
.getSprite("SmallExplosion", true), PAR_WEIGHTLESS
);
94 void addFireParticles(float x
, float y
, int amount
)
96 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
);
99 void addBubble(float x
, float y
)
101 if ((rand() % 50) == 0)
103 map
.addParticle(x
+ rand() % BRICKSIZE
, y
+ 19, 0, Math::rrand(-3, -1), Math::rrand(30, 90), graphics
.red
, graphics
.getSprite("Bubble", true), PAR_COLLIDES
+ PAR_WEIGHTLESS
);
107 void throwStalagParticles(float x
, float y
)
109 Sprite
*stalagPiece
= graphics
.getSprite("StalagPiece", true);
111 int amount
= Math::rrand(3, 6);
113 for (int i
= 0 ; i
< amount
; i
++)
115 map
.addParticle(x
, y
, Math::rrand(-2, 2), Math::rrand(-3, -1), Math::rrand(5, 30), graphics
.red
, stalagPiece
, 0);
119 void throwBrickParticles(float x
, float y
)
121 int amount
= Math::rrand(4, 8);
123 Sprite
*wallPiece
= graphics
.getSprite("WallPiece", true);
125 for (int i
= 0 ; i
< amount
; i
++)
127 map
.addParticle(x
, y
, Math::rrand(-2, 2), Math::rrand(-4, -1), Math::rrand(5, 30), graphics
.red
, wallPiece
, 0);
131 void addTeleportParticles(float x
, float y
, int amount
, int soundToPlay
)
133 Sprite
*teleportStar
= graphics
.getSprite("TeleportStar", true);
136 for (int i
= 0 ; i
< amount
; i
++)
138 dx
= Math::rrand(-30, 30); dx
/= 20;
139 dy
= Math::rrand(-30, 30); dy
/= 20;
140 map
.addParticle(x
, y
, dx
, dy
, Math::rrand(30, 60), graphics
.red
, teleportStar
, PAR_WEIGHTLESS
);
143 if (soundToPlay
!= -1)
145 audio
.playSound(soundToPlay
, CH_SPAWN
);
151 Particle
*particle
= (Particle
*)map
.particleList
.getHead();
152 Particle
*previous
= particle
;
156 while (particle
->next
!= NULL
)
158 particle
= (Particle
*)particle
->next
;
160 x
= (int)(particle
->x
- map
.offsetX
);
161 y
= (int)(particle
->y
- map
.offsetY
);
163 if (particle
->sprite
== NULL
)
165 graphics
.lock(graphics
.screen
);
167 graphics
.putPixel(x
, y
, particle
->color
, graphics
.screen
);
169 graphics
.unlock(graphics
.screen
);
173 graphics
.blit(particle
->getFrame(), x
, y
, graphics
.screen
, false);
180 if (!(particle
->flags
& PAR_WEIGHTLESS
))
185 x
= (int)particle
->x
>> BRICKSHIFT
;
186 y
= (int)particle
->y
>> BRICKSHIFT
;
188 if (particle
->flags
& PAR_COLLIDES
)
190 if (map
.isSolid(x
, y
))
192 particle
->health
= 0;
196 if (particle
->health
> 0)
202 map
.particleList
.remove(previous
, particle
);