-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvillian.py
213 lines (195 loc) · 7.34 KB
/
villian.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
## all enemies and attacks
import pygame
import random
class Enemy(pygame.sprite.Sprite): #basic enemies
def __init__(self):
super().__init__()
self.health = 4
self.object = pygame.image.load("staticFiles/saibamanStanding.png").convert_alpha()
self.object = pygame.transform.scale(self.object, (60, 100))
self.punching = False
self.punch = pygame.image.load("staticFiles/saibamanPunch.png").convert_alpha()
self.punch = pygame.transform.scale(self.punch, (60,100))
self.rect = self.object.get_rect()
self.topLeft = self.rect.topleft
self.bottomRight = self.rect.bottomright
self.centerX, self.centerY = self.rect.center
self.probability = (2, 5) #2/5 chance to dodge
self.moved = False
self.punched = False
self.dx = 5
self.shotDelay = 0
def move(self, user): #moves character
cx, cy = user.rect.center
x, y = self.rect.center
direction = x - cx
if abs(direction) < 225:
self.rect.move_ip(self.dx, 0)
elif abs(direction) < 800:
if direction > 0 and self.dx > 0:
self.dx *= -1
elif direction <0 and self.dx < 0:
self.dx *= -1
self.rect.move_ip(self.dx, 0)
def dodge(self, kiBlasts, movingRight): #detect blast and dodge
for blast in kiBlasts:
if movingRight:
futureRect = blast.rect.move(10, 0)
if self.rect.colliderect(futureRect):
self.rect.move_ip(-40,-150)
self.moved = True
else:
futureRect = blast.rect.move(-10, 0)
if self.rect.colliderect(futureRect):
self.rect.move_ip(40,-150)
self.moved = True
def Punch(self, user, movingRight): #punch if able to
if movingRight:
futureRect = user.rect.move(5,0)
if self.rect.colliderect(futureRect):
self.punching = True
else:
futureRect = user.rect.move(-5,0)
if self.rect.colliderect(futureRect):
self.punching = True
class Attacks(pygame.sprite.Sprite): #ki blasts
def __init__(self, user, movingRight):
super().__init__()
self.user = user
self.movingRight = movingRight
self.cx, self.cy = self.user.rect.center
self.width, self.height = self.user.user.get_size()
self.object = pygame.image.load("staticFiles/kiBlast.gif")
self.object = pygame.transform.scale(self.object, (45,30))
self.rect = self.object.get_rect()
self.rect.move_ip(self.cx+self.width//2, self.cy-self.height//4)
def move(self, d):
self.rect.move_ip(5*d, 0) #directional value
class ComEnemy(Enemy): #more advanced AI
def __init__(self, enemyNum):
super().__init__()
self.health = 7
if enemyNum == 1:
self.object = pygame.image.load("staticFiles/raditzStanding.png").convert_alpha()
self.object = pygame.transform.scale(self.object, (60, 160))
self.punch = pygame.image.load("staticFiles/raditzPunch.png").convert_alpha()
self.punch = pygame.transform.scale(self.punch, (60,160))
elif enemyNum == 2:
self.object = pygame.image.load("staticFiles/nappaStance.png").convert_alpha()
self.object = pygame.transform.scale(self.object, (80, 160))
self.punch = pygame.image.load("staticFiles/nappaPunch.png").convert_alpha()
self.punch = pygame.transform.scale(self.punch, (80,160))
self.shootLeft = True
self.rect = self.object.get_rect()
def Shoot(self, user):
cx, cy = user.rect.center
x, y = self.rect.center
direction = x - cx
if direction > 0: #shoot to the left
self.shootLeft = True
else: #shoot to the right
self.shootLeft = False
class ComAttacks(pygame.sprite.Sprite): #enemy ki blast
def __init__(self, user, speed, left):
super().__init__()
self.user = user
self.speed = speed
self.shootingLeft = left
self.damaged = False
self.cx, self.cy = self.user.rect.center
self.width, self.height = self.user.object.get_size()
self.object = pygame.image.load("staticFiles/raditzBlast.gif")
self.object = pygame.transform.scale(self.object, (45,30))
self.rect = self.object.get_rect()
self.rect.move_ip(self.cx+self.width//2, self.cy-self.height//4)
def move(self, d, cy):
centerY = self.user.rect.centery
difference = cy - centerY
if difference < -40:
d2 = -1
elif difference > 40:
d2 = 1
else:
d2 = 0
self.rect.move_ip(6*d, d2) #directional value
class ComAttacksBoss(pygame.sprite.Sprite): #enemy attack
def __init__(self, user, speed, left):
super().__init__()
self.user = user
self.speed = speed
self.shootingLeft = left
self.damaged = False
self.cx, self.cy = self.user.rect.center
self.width, self.height = self.user.brolly.get_size()
self.object = pygame.image.load("staticFiles/brolly/bKi.png")
self.object = pygame.transform.scale(self.object, (45,30))
self.rect = self.object.get_rect()
self.rect.move_ip(self.cx+self.width//2, self.cy-self.height//4)
def move(self, d, cy):
centerY = self.user.rect.centery
difference = cy - centerY
if difference < -40:
d2 = -1
elif difference > 40:
d2 = 1
else:
d2 = 0
self.rect.move_ip(6*d, d2) #directional value
class SuperMove(Attacks): #super moves generated
def __init__(self, user, movingRight):
super().__init__(user, movingRight)
cx, cy = self.user.rect.center
self.userwidth, self.userheight = self.user.user.get_size()
self.movingRight = movingRight
if user.character == "vegeta":
self.start = pygame.image.load("staticFiles/vSuperp1.png")
self.mid = pygame.image.load("staticFiles/vSupermid.png")
self.last = pygame.image.load("staticFiles/vSuperp3.png")
else:
self.start = pygame.image.load("staticFiles/firstKame.gif")
self.mid = pygame.image.load("staticFiles/midKame.gif")
self.last = pygame.image.load("staticFiles/lastKame.gif")
self.start = pygame.transform.scale(self.start, (45, 30))
self.mid = pygame.transform.scale(self.mid, (10, 30))
self.last = pygame.transform.scale(self.last, (45, 30))
self.rect1 = self.start.get_rect()
self.rect2 = self.mid.get_rect()
self.rect3 = self.last.get_rect()
self.fullKame = [(self.start, self.rect1), (self.mid, self.rect2), (self.last, self.rect3)]
self.y = cy-self.userheight//4
if self.movingRight:
self.rect1.move_ip(cx+self.userwidth//2+30, cy-self.userheight//4)
self.rect2.move_ip(cx+self.userwidth//2+30+40, cy-self.userheight//4)
self.rect3.move_ip(cx+self.userwidth//2+30+50, cy-self.userheight//4)
else:
self.rect1.move_ip(cx-self.userwidth//2-30, cy-self.userheight//4)
self.rect2.move_ip(cx+self.userwidth//2-30-40, cy-self.userheight//4)
self.rect3.move_ip(cx+self.userwidth//2-30-50, cy-self.userheight//4)
def createMid(self, x):
cx, cy = self.user.rect.center
if self.user.character == "goku":
newMid = pygame.image.load("staticFiles/midKame.gif")
else:
newMid = pygame.image.load("staticFiles/vSupermid.png")
newMid = pygame.transform.scale(newMid, (10, 30))
newMidRect = newMid.get_rect()
newMidRect.move_ip(x, cy-self.userheight//4)
self.fullKame.append((newMid, newMidRect))
# self.fullKame.insert(-1, (newMid, newMidRect))
def move(self):
last, rect0, = self.fullKame.pop()
lastMid, rect = self.fullKame[-1]
cx, cy = self.user.rect.center
if self.movingRight:
dx = 10
x0 = rect0.left
x = rect.right
self.createMid(x)
else:
dx = -10
x0 = rect0.right
x = rect.left - 10
self.createMid(x)
newMid, newRect = self.fullKame[-1]
newRect3 = rect0.move(dx, 0)
self.fullKame.append((last, newRect3))