-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticles.py
277 lines (239 loc) · 11.3 KB
/
Particles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
import pygame
import random
from Settings import *
class Particles():
def __init__(self, pos, angle, TTL, Color, angle_bool):
super().__init__()
self.pos = list(pos)
self.angle = angle
if angle_bool:
if self.angle >= 0 and self.angle < 45:
self.Vel = [random.randint(0, 10) / 10, random.randint(-10, 10) / 10]
elif self.angle >= 45 and self.angle < 135:
self.Vel = [random.randint(-10, 10) / 10, random.randint(-10, 0) / 10]
elif self.angle >= 135 and self.angle < 225:
self.Vel = [random.randint(-10, 0) / 10, random.randint(-10, 10) / 10]
elif self.angle >= 225 and self.angle < 315:
self.Vel = [random.randint(-10, 10) / 10, random.randint(0, 10) / 10]
elif self.angle >= 315 and self.angle < 360:
self.Vel = [random.randint(0, 10) / 10, random.randint(-10, 10) / 10]
else:
self.Vel = [random.randint(-10, 10) / 10, random.randint(-10, 10) / 10]
self.TTL = TTL
self.Color = Color
self.offx = random.randint(-5, 5)
self.offy = random.randint(-5, 5)
# if Color == "grey":
# self.Color = random.choice( [(169,169,169), (190,190,190), (192,192,192) ] )
# elif Color == "white":
# self.Color = random.choice( [(232,232,232), (240,240,240), (245,245,245) ] )
#FIX THE COLLSION FOLLOW THE CIRCLE
class Smoke():
def __init__(self, pos, angle, Angle_bool):
self.screen = pygame.display.get_surface()
self.Speed = 2
self.pos = pos
self.angle = angle
self.Particles = []
self.Limit = 10
self.count = 0
self.offsetx = 0
self.offsety = 0
self.Kill = False
self.Angle_bool = Angle_bool
def Draw(self, size):
# self.count = max(self.count, len(self.Particles) )
if self.count <= self.Limit:
if not self.Kill:
# Color = random.choice( [(232,232,232), (240,240,240), (245,245,245), (169,169,169), (190,190,190), (192,192,192) ] )
Color = "white"
self.Particles.append( Particles( self.pos, self.angle, random.randint(15,20), Color, self.Angle_bool) )
self.count += 1
else:
self.Kill = True
for i in self.Particles:
self.Collision(i, "Hoz", size)
self.Collision(i, "Ver", size)
i.pos[0] -= self.offsetx
i.pos[1] -= self.offsety
i.pos[0] += i.Vel[0] * self.Speed
i.pos[1] += i.Vel[1] * self.Speed
i.TTL -= 0.1
if i.TTL <= 14:
i.Color = (190,190,190)
if i.TTL <= 10:
i.Color = (169,169,169)
if i.TTL <= 3:
i.Color = (109, 93, 110)
pygame.draw.circle(self.screen, i.Color, i.pos, i.TTL)
if i.TTL < 0:
self.Particles.remove(i)
def Collision(self, sprite, check, size):
if check == "Hoz":
str_loccTL = str(int(sprite.pos[0] / size)) + ';' + str(int(sprite.pos[1] / size))
str_loccBR = str(int( (sprite.pos[0] + sprite.TTL + sprite.offx ) / size)) + ';' + str(int( (sprite.pos[1] + sprite.TTL + sprite.offy ) / size))
if str_loccTL in Tiles_Map or str_loccBR in Tiles_Map :
sprite.Vel[0] = -1 * sprite.Vel[0]
else:
str_loccTL = str(int(sprite.pos[0] / size)) + ';' + str(int(sprite.pos[1] / size))
str_loccBR = str(int( (sprite.pos[0] + sprite.TTL + sprite.offx ) / size)) + ';' + str(int( (sprite.pos[1] + sprite.TTL + sprite.offy ) / size))
if str_loccTL in Tiles_Map or str_loccBR in Tiles_Map :
sprite.Vel[1] = -1 * sprite.Vel[1]
class Fire():
def __init__(self, pos, angle, Angle_bool):
self.screen = pygame.display.get_surface()
self.Speed = 2
self.pos = pos
self.angle = angle
self.Particles = []
self.Limit = 10
self.count = 0
self.offsetx = 0
self.offsety = 0
self.Kill = False
self.Angle_bool = Angle_bool
def Draw(self, size):
# self.count = max(self.count, len(self.Particles) )
if self.count <= self.Limit:
if not self.Kill:
# Color = random.choice( [(232,232,232), (240,240,240), (245,245,245), (169,169,169), (190,190,190), (192,192,192) ] )
Color = "white"
self.Particles.append( Particles( self.pos, self.angle, random.randint(15,20), Color, self.Angle_bool) )
self.count += 1
else:
self.Kill = True
for i in self.Particles:
self.Collision(i, "Hoz", size)
self.Collision(i, "Ver", size)
i.pos[0] -= self.offsetx
i.pos[1] -= self.offsety
i.pos[0] += i.Vel[0] * self.Speed
i.pos[1] += i.Vel[1] * self.Speed
i.TTL -= 0.1
if i.TTL <= 14:
i.Color = "yellow"
if i.TTL <= 10:
i.Color = "orange"
if i.TTL <= 3:
i.Color = "red"
pygame.draw.circle(self.screen, i.Color, i.pos, i.TTL)
if i.TTL < 0:
self.Particles.remove(i)
def Collision(self, sprite, check, size):
if check == "Hoz":
str_loccTL = str(int(sprite.pos[0] / size)) + ';' + str(int(sprite.pos[1] / size))
str_loccBR = str(int( (sprite.pos[0] + sprite.TTL + sprite.offx ) / size)) + ';' + str(int( (sprite.pos[1] + sprite.TTL + sprite.offy ) / size))
if str_loccTL in Tiles_Map or str_loccBR in Tiles_Map :
sprite.Vel[0] = -1 * sprite.Vel[0]
else:
str_loccTL = str(int(sprite.pos[0] / size)) + ';' + str(int(sprite.pos[1] / size))
str_loccBR = str(int( (sprite.pos[0] + sprite.TTL + sprite.offx ) / size)) + ';' + str(int( (sprite.pos[1] + sprite.TTL + sprite.offy ) / size))
if str_loccTL in Tiles_Map or str_loccBR in Tiles_Map :
sprite.Vel[1] = -1 * sprite.Vel[1]
class Water():
def __init__(self, pos, angle, Angle_bool):
self.screen = pygame.display.get_surface()
self.Speed = 2
self.pos = pos
self.angle = angle
self.Particles = []
self.Limit = 10
self.count = 0
self.offsetx = 0
self.offsety = 0
self.Kill = False
self.Angle_bool = Angle_bool
def Draw(self, size):
# self.count = max(self.count, len(self.Particles) )
if self.count <= self.Limit:
if not self.Kill:
# Color = random.choice( [(37, 53, 211), (51, 230, 253), (187, 224, 251), (255, 251, 255) ] )
Color = (37, 53, 211)
self.Particles.append( Particles( self.pos, self.angle, random.randint(18,20), Color, self.Angle_bool) )
self.count += 1
else:
self.Kill = True
for i in self.Particles:
self.Collision(i, "Hoz", size)
self.Collision(i, "Ver", size)
i.pos[0] -= self.offsetx
i.pos[1] -= self.offsety
i.pos[0] += i.Vel[0] * self.Speed
i.pos[1] += i.Vel[1] * self.Speed
i.TTL -= 0.1
if i.TTL <= 17:
i.Color = (24, 128, 255)
if i.TTL <= 14:
i.Color = (39, 168, 252)
if i.TTL <= 10:
i.Color = random.choice( [ (187, 224, 251), (255, 251, 255) ] )
pygame.draw.circle(self.screen, i.Color, i.pos, i.TTL)
if i.TTL < 0:
self.Particles.remove(i)
def Collision(self, sprite, check, size):
if check == "Hoz":
str_loccTL = str(int(sprite.pos[0] / size)) + ';' + str(int(sprite.pos[1] / size))
str_loccBR = str(int( (sprite.pos[0] + sprite.TTL + sprite.offx ) / size)) + ';' + str(int( (sprite.pos[1] + sprite.TTL + sprite.offy ) / size))
if str_loccTL in Tiles_Map or str_loccBR in Tiles_Map :
sprite.Vel[0] = -1 * sprite.Vel[0]
else:
str_loccTL = str(int(sprite.pos[0] / size)) + ';' + str(int(sprite.pos[1] / size))
str_loccBR = str(int( (sprite.pos[0] + sprite.TTL + sprite.offx ) / size)) + ';' + str(int( (sprite.pos[1] + sprite.TTL + sprite.offy ) / size))
if str_loccTL in Tiles_Map or str_loccBR in Tiles_Map :
sprite.Vel[1] = -1 * sprite.Vel[1]
#THE COLLSION CORRECT FOR THE ELLIPSE
class Leaf():
def __init__(self, pos, angle, Angle_bool):
self.screen = pygame.display.get_surface()
self.Speed = 2
self.pos = pos
self.angle = angle
self.Particles = []
self.Limit = 10
self.count = 0
self.offsetx = 0
self.offsety = 0
self.Kill = False
self.Angle_bool = Angle_bool
def Draw(self, size):
# self.count = max(self.count, len(self.Particles) )
if self.count <= self.Limit:
if not self.Kill:
# Color = random.choice( [(37, 53, 211), (51, 230, 253), (187, 224, 251), (255, 251, 255) ] )
Color = (19, 99, 56)
self.Particles.append( Particles( self.pos, self.angle, random.randint(18,20), Color, self.Angle_bool) )
self.count += 1
else:
self.Kill = True
for i in self.Particles:
self.Collision(i, "Hoz", size)
self.Collision(i, "Ver", size)
i.pos[0] -= self.offsetx
i.pos[1] -= self.offsety
i.pos[0] += i.Vel[0] * self.Speed
i.pos[1] += i.Vel[1] * self.Speed
i.TTL -= 0.1
if int(i.TTL) == 17:
i.Color = random.choice( [(50, 130, 85), (19, 99, 56)])
if int(i.TTL) == 14:
if i.Color == (50, 130, 85):
i.Color = random.choice( [(50, 130, 85), (81, 157, 122)])
if int(i.TTL) == 10:
# if i.Color == (81, 157, 122):
# i.Color = random.choice( [ (81, 157, 122),(81, 157, 122),(81, 157, 122), (81, 157, 122), (115, 195, 152), (147, 236, 178) ] )
if i.Color == (81, 157, 122):
i.Color = random.choice( [(115, 195, 152), (81, 157, 122)])
pygame.draw.ellipse(self.screen, i.Color, (i.pos[0], i.pos[1], i.TTL + i.offx, i.TTL + i.offy))
if i.TTL < 0:
self.Particles.remove(i)
def Collision(self, sprite, check, size):
if check == "Hoz":
str_loccTL = str(int(sprite.pos[0] / size)) + ';' + str(int(sprite.pos[1] / size))
str_loccBR = str(int( (sprite.pos[0] + sprite.TTL + sprite.offx ) / size)) + ';' + str(int( (sprite.pos[1] + sprite.TTL + sprite.offy ) / size))
if str_loccTL in Tiles_Map or str_loccBR in Tiles_Map :
sprite.Vel[0] = -1 * sprite.Vel[0]
else:
str_loccTL = str(int(sprite.pos[0] / size)) + ';' + str(int(sprite.pos[1] / size))
str_loccBR = str(int( (sprite.pos[0] + sprite.TTL + sprite.offx ) / size)) + ';' + str(int( (sprite.pos[1] + sprite.TTL + sprite.offy ) / size))
if str_loccTL in Tiles_Map or str_loccBR in Tiles_Map :
sprite.Vel[1] = -1 * sprite.Vel[1]