-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.py
34 lines (28 loc) · 966 Bytes
/
bullet.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
from game_object import *
from enemy import *
from shuttle import *
class Bullet(GameObject):
def __init__(self, sender_class, x, y, v, width, height):
super().__init__(x, y, v, width, height)
self.sender_class = sender_class
self.targets = []
self.set_targets()
def move(self):
# print("moves")
if not self.is_alive:
return
self.y -= self.velocity
def try_hit(self, another_game_object):
for target in self.targets:
if isinstance(another_game_object, target) \
and another_game_object.is_alive \
and self.is_intersected_with(another_game_object):
print("hit")
another_game_object.get_hit()
self.die()
return True
else:
return False
def set_targets(self):
if self.sender_class == Shuttle:
self.targets = [Enemy]