-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathObjectBehavior.py
More file actions
38 lines (33 loc) · 1.36 KB
/
ObjectBehavior.py
File metadata and controls
38 lines (33 loc) · 1.36 KB
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
from Sprites2D import *
from CONSTANTS import *
class Pistole(object):
def __init__(self):
self.bullets = 12
self.magazine_size = 12
self.reloading = False
self.reloading_time = 0.1
def fire(self, bulletSpawnPoint, *Groups):
if self.bullets == 0:
print('Reload')
elif not self.reloading:
aim_point = [pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1]]
self.bullets -= 1
bullet = Bullet(bulletSpawnPoint, aim_point, [10, 10], GREEN)
for group in Groups:
group.add(bullet)
def reload(self, inventory, delta):
if inventory['Bullets'] > 0 and self.reloading == True and self.bullets < self.magazine_size:
if self.reloading_time > 0:
self.reloading_time -= delta
elif self.reloading_time <= 0:
reloading_sound = pygame.mixer.Sound('reload.wav')
reloading_sound.play()
self.bullets += 1
inventory['Bullets'] -= 1
self.reloading_time = 0.1
if inventory['Bullets'] == 0 or self.bullets == self.magazine_size:
self.reloading = False
self.reloading_time = 0.1
else:
self.reloading = False
self.reloading_time = 0.1