-
Notifications
You must be signed in to change notification settings - Fork 0
/
blast.py
178 lines (159 loc) · 6.02 KB
/
blast.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
import pygame
import pygame.gfxdraw
from enums import Direction
from enums import Color
from settings import ARENAHEIGHT, CHAIN
class Blast(pygame.sprite.Sprite):
def __init__(self, owner):
super().__init__()
self.image = None
self.owner = owner
self.enemy = owner.enemy
self.time = None
self.rect = None
self.speed = 1
self.vector = [0, 0]
self.timetodestroy = 2000
self.damage = 0
def update(self):
if self.time is not None:
if pygame.time.get_ticks() - self.time >= self.timetodestroy:
self.kill()
if self.rect is not None:
arenaheight_q = ARENAHEIGHT - CHAIN - self.image.get_height()
if self.rect.y > arenaheight_q:
self.kill()
self.rect.x += self.vector[0]
self.rect.y += self.vector[1]
def correction(self, direction):
"""Poprawia vector i pozycję strzału w zależności
od podanego kierunku
"""
if direction == Direction.GORA:
self.vector = [0, -self.speed]
self.rect.x += 15
self.rect.y -= 10
elif direction == Direction.PRAWO:
self.vector = [self.speed, 0]
self.rect.y += 20
elif direction == Direction.DOL:
self.vector = [0, self.speed]
self.rect.x -= 20
elif direction == Direction.LEWO:
self.vector = [-self.speed, 0]
self.rect.y -= 20
elif direction == Direction.GORALEWO:
self.vector = [-self.speed, -self.speed]
self.rect.x += 10
self.rect.y -= 10
elif direction == Direction.GORAPRAWO:
self.vector = [self.speed, -self.speed]
self.rect.x += 10
self.rect.y += 10
elif direction == Direction.DOLLEWO:
self.vector = [-self.speed, self.speed]
self.rect.x -= 10
self.rect.y -= 10
elif direction == Direction.DOLPRAWO:
self.vector = [self.speed, self.speed]
self.rect.x -= 10
self.rect.y += 10
def correctionimage(self, direction):
if direction == Direction.PRAWO:
self.image = pygame.transform.rotate(self.image, -90)
elif direction == Direction.LEWO:
self.image = pygame.transform.rotate(self.image, 90)
elif direction == Direction.GORALEWO:
self.image = pygame.transform.rotate(self.image, -45)
elif direction == Direction.GORAPRAWO:
self.image = pygame.transform.rotate(self.image, 45)
elif direction == Direction.DOLLEWO:
self.image = pygame.transform.rotate(self.image, -135)
elif direction == Direction.DOLPRAWO:
self.image = pygame.transform.rotate(self.image, 135)
class KnifeBlast(Blast):
def __init__(self, owner, direction):
super().__init__(owner)
self.image = pygame.Surface([30, 30])
self.image.set_alpha(50)
self.image.fill(Color.SILVER.value)
#self.correctionimage(direction)
self.rect = self.image.get_rect()
self.rect.x = self.owner.rect.center[0]
self.rect.y = self.owner.rect.center[1]
self.speed = 1
self.time = pygame.time.get_ticks()
self.knifecorrection(direction)
self.timetodestroy = 150
self.damage = 120
def knifecorrection(self, direction):
if direction == Direction.GORA:
self.rect.y -= 40
elif direction == Direction.PRAWO:
self.rect.x += 10
elif direction == Direction.DOL:
self.rect.x -= 30
self.rect.y += 10
elif direction == Direction.LEWO:
self.rect.x -= 40
self.rect.y -= 30
elif direction == Direction.GORALEWO:
self.rect.x -= 20
self.rect.y -= 40
elif direction == Direction.GORAPRAWO:
self.rect.x += 10
self.rect.y -= 20
elif direction == Direction.DOLLEWO:
self.rect.x -= 40
self.rect.y -= 10
elif direction == Direction.DOLPRAWO:
self.rect.x -= 10
self.rect.y += 10
class PistolBlast(Blast):
def __init__(self, owner, direction):
super().__init__(owner)
self.image = pygame.Surface([5, 5])
self.image.fill(Color.BLACK.value)
# self.correctionimage(direction)
self.rect = self.image.get_rect()
self.rect.x = self.owner.rect.center[0]
self.rect.y = self.owner.rect.center[1]
if owner.enemy:
self.speed = 10
else:
self.speed = 5
self.time = pygame.time.get_ticks()
self.correction(direction)
if owner.enemy:
self.timetodestroy = 8000
else:
self.timetodestroy = 1000
self.damage = 100
class TompsonBlast(Blast):
def __init__(self, owner, direction):
super().__init__(owner)
self.image = pygame.Surface([5, 5])
self.image.fill(Color.BLACK.value)
# self.correctionimage(direction)
self.rect = self.image.get_rect()
self.rect.x = self.owner.rect.center[0]
self.rect.y = self.owner.rect.center[1]
self.speed = 7
self.time = pygame.time.get_ticks()
self.correction(direction)
self.timetodestroy = 2000
self.damage = 200
class Mp40Blast(Blast):
def __init__(self, owner, direction):
super().__init__(owner)
self.image = pygame.Surface([10, 10])
self.image.fill(Color.BLACK.value)
# self.correctionimage(direction)
self.rect = self.image.get_rect()
self.rect.x = self.owner.rect.center[0]
self.rect.y = self.owner.rect.center[1]
self.speed = 6
self.time = pygame.time.get_ticks()
self.correction(direction)
self.timetodestroy = 3000
self.damage = 300