-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshot_manager.py
41 lines (32 loc) · 1.12 KB
/
shot_manager.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
import random
from shot import Shot
from pygame import mixer
class ShotManager:
def __init__(self, speed=10, max_shots=10):
self.shotSpeed = speed
self.shots = []
self.maxShots = max_shots
self.bulledSound = mixer.Sound("assets/laser.wav")
self.bulledSound.set_volume(0.05)
def add_shot(self, for_player):
if len(self.shots) > self.maxShots:
return
shot_left = bool(random.getrandbits(1))
pos_x = for_player.position_x
if shot_left:
pos_x += (for_player.image.get_width() / 2)
pos_y = for_player.position_y
new_shot = Shot(start_pos_x=pos_x, start_pos_y=pos_y)
new_shot.speed_y = -self.shotSpeed
self.shots.append(new_shot)
self.bulledSound.play()
def move(self):
for shot in self.shots:
shot.move()
self.shots = [shot for shot in self.shots if shot.position_y + shot.image.get_height() > 0]
def remove(self, shots):
for shot in shots:
self.shots.remove(shot)
def draw(self):
for shot in self.shots:
shot.draw()