-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExplosion.py
50 lines (39 loc) · 1.42 KB
/
Explosion.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
from PlayerMissile import *
from Collision import Collision
import random
import RunningValues
def create_explosion(canvas, x, y):
for i in range(1, 10):
RunningValues.render_list.append(Explosion(canvas, x, y))
class Explosion(Collision):
ticker = 0
explosion_x = -1
explosion_y = 1
def __init__(self, canvas: Canvas, x, y):
self.height = 10
self.width = 10
self.canvas = canvas
self.x = -100
self.y = -100
self.realx = x
self.realy = y
self.addx = Explosion.explosion_x * random.randrange(1, 3)
self.addy = Explosion.explosion_y * random.randrange(1, 3)
Explosion.explosion_x = Explosion.explosion_x * -1
Explosion.explosion_y = Explosion.explosion_y * -1
colours = ['red', 'orange', 'green']
self.shape = canvas.create_rectangle(x, y, x + self.width, y + self.height,
fill=colours[random.randrange(0, 3)])
def render(self):
self.ticker = self.ticker + 1
if self.ticker % 8 < 5:
return
self.canvas.move(self.shape, self.addx, self.addy)
if self.ticker > 50:
if self in RunningValues.render_list:
RunningValues.render_list.remove(self)
self.canvas.delete(self.shape)
RunningValues.delete_list.append(self)
return
def hit(self, other):
return