-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeapon.py
150 lines (123 loc) · 4.28 KB
/
Weapon.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
import pygame
from pygame.sprite import Sprite
from pygame.image import load
from Bullet import Bullet
from Grenade import Grenade
from shotgunShell import shotgunShell
import os
class Weapon(Sprite):
def __init__(self, image, direction):
super().__init__()
pygame.mixer.pre_init()
self.name = image
self.image = load(os.getcwd() + '/img/' + image + '.png')
self.rect = self.image.get_rect()
self.direction = direction
self.shootingBullets = set()
self.sound = pygame.mixer.Sound(os.getcwd() + '/music/'+image+'.wav')
@staticmethod
def grenade_launcher(direction):
g_l = grenade_launcher(direction)
return g_l
@staticmethod
def baseballBat(direction):
shortweapon = baseballBat(direction)
return shortweapon
@staticmethod
def machineGun(direction):
gun = machineGun(direction)
return gun
@staticmethod
def shotgun(direction):
sg = shotgun(direction)
return sg
def shoot(self):
self.sound.play()
bullet = Bullet(self.direction)
bullet.rect.x, bullet.rect.y = self.rect.x, self.rect.y
if self.direction > 0:
bullet.rect.left = self.rect.right
else:
bullet.rect.right = self.rect.left
self.shootingBullets.add(bullet)
return bullet
def launch(self):
self.sound.play()
grenade = Grenade(self.direction)
grenade.rect.x, grenade.rect.y = self.rect.x, self.rect.y
if self.direction > 0:
grenade.rect.left = self.rect.right+25
else:
grenade.rect.right = self.rect.left
self.shootingBullets.add(grenade)
return grenade
def shootshot(self): # if you know how to duplicate objects in python you can cut this code back lol
self.sound.play()
bullet = shotgunShell(self.direction)
bullet_up = shotgunShell(self.direction)
bullet_down = shotgunShell(self.direction)
bullet.rect.x, bullet.rect.y = self.rect.x, self.rect.y
bullet_up.rect.x, bullet_up.rect.y = self.rect.x, self.rect.y
bullet_down.rect.x, bullet_down.rect.y = self.rect.x, self.rect.y
if self.direction > 0:
bullet.rect.left = self.rect.right
bullet_up.rect.left = self.rect.right
bullet_down.rect.left = self.rect.right
else:
bullet.rect.right = self.rect.left
bullet_up.rect.right = self.rect.left
bullet_down.rect.right = self.rect.left
bullet_up.y = 1
bullet_down.y = -1
self.shootingBullets.add(bullet)
self.shootingBullets.add(bullet_up)
self.shootingBullets.add( bullet_down)
return (bullet, bullet_up, bullet_down)
class grenade_launcher(Weapon):
def __init__(self, direction):
super().__init__(image = "grenade", direction = direction)
def shoot(self):
if len(self.shootingBullets) < 3:
return super().launch()
def changeDirection(self, direction):
self.direction = direction
def update(self):
self.image = load(os.getcwd() + '/img/grenade.png')
self.sound = pygame.mixer.Sound(os.getcwd() + '/music/grenade.wav')
class machineGun(Weapon):
def __init__(self, direction):
name = 'normalGun-l' if direction == -1 else 'normalGun-r'
super().__init__(image = name, direction = direction)
def shoot(self):
if len(self.shootingBullets) < 5:
return super().shoot()
def changeDirection(self, direction):
name = 'normalGun-l' if direction == -1 else 'normalGun-r'
self.image = load(os.getcwd() + '/img/' + name + '.png')
self.direction = direction
def update(self):
name = 'normalGun-l' if self.direction == -1 else 'normalGun-r'
self.image = load(os.getcwd() + '/img/' + name + '.png')
self.sound = pygame.mixer.Sound(os.getcwd() + '/music/' + name + '.wav')
class shotgun(Weapon):
def __init__(self, direction):
name = 'shotgun-l' if direction == -1 else 'shotgun-r'
super().__init__(image = name, direction = direction)
def shoot(self):
if len(self.shootingBullets) < 3:
return super().shootshot()
def changeDirection(self, direction):
name = 'shotgun-l' if direction == -1 else 'shotgun-r'
self.image = load(os.getcwd() + '/img/' + name + '.png')
self.direction = direction
def update(self):
name = 'shotgun-l' if self.direction == -1 else 'shotgun-r'
self.image = load(os.getcwd() + '/img/' + name + '.png')
self.sound = pygame.mixer.Sound(os.getcwd() + '/music/' + name + '.wav')
class baseballBat(Weapon):
def __init__(self, direction):
super().__init__(image = "baseballBat", direction = direction)
def shoot(self):
# animation
# if collision with player lose HP
return super().shoot()