-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
282 lines (235 loc) · 8 KB
/
player.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#-*-coding:utf-8-*
import pygame
from pygame.locals import *
import math
import game_values as GAMEVALUES
from proj_models import projectile_models
from fct import *
from projectile import projectile
from visuals import *
import res
class player(pygame.sprite.Sprite):
def __init__(self, pos, exitPos, shield, pGE):
pygame.sprite.Sprite.__init__(self)
self.cursorCircle = res.images["playerAttributes"][0]
self.shootDirection = res.images["playerAttributes"][1]
self.skins = res.images["player"]
self.rect = self.skins[0].get_rect(center=(pos[0], pos[1]))
self.rect = self.rect.inflate(-1, -1)
self.pGE = pGE[0]
self.pGEs = pGE
self.skin = 6
self.cCAngle = 0
self.sDAngle = get_angle(self.rect.center, (683, 384))
self.mouseDistance = 0
self.shootCoolDown = 0
self.shooting = 0
self.speed = 1
self.sDRotate = 0
self.focusObj = None
self.lastHit = None
self.showCursor = False
self.miniCount = 0
self.pulse = 0, 0
self.freeze = False
self.noColl = False
self.shield = False
self.shieldTime = 0
self.outStart = False
self.shield = shield
self.imgShield = rotativeDeco(res.images["playerAttributes"][2])
def update(self, A_G_V):
if not self.outStart:
for obj in A_G_V.gameSprites["objects"]:
if obj.name == "start" and not obj.collide(self.rect) or self.shooting != 0:
self.outStart = True
obj.unFocused()
self.miniCount += 2
if self.miniCount == 20:
self.miniCount = 0
deplaced = 0
self.mouseDistance = int(distancePoint(self.rect.center, A_G_V.mousePos))
maxSpeed = 9*self.speed
if res.get_cheat(2):
maxSpeed = 999
move_vector = (A_G_V.mousePos[0]-(self.rect.centerx))*0.075, (A_G_V.mousePos[1]-(self.rect.centery))*0.075
if math.fabs(move_vector[0]) > maxSpeed:
move_vector = move_vector[0]*(maxSpeed/math.fabs(move_vector[0])), move_vector[1]*(maxSpeed/math.fabs(move_vector[0]))
if math.fabs(move_vector[1]) > maxSpeed:
move_vector = move_vector[0]*(maxSpeed/math.fabs(move_vector[1])), move_vector[1]*(maxSpeed/math.fabs(move_vector[1]))
if self.freeze or distancePoint(self.rect.center, A_G_V.mousePos) < 40:
move_vector = 0, 0
movedPlayer = self.rect.move(move_vector)
self.pGE, self.pGEs = pG_rectLeaving(movedPlayer.inflate(5, 5), A_G_V.partialGrid[1][self.pGE], self.pGE)
if not self.noColl:
hazards = comparePGE(self.pGEs, A_G_V.get_hazards())
if self.shieldTime > 0:
solids = comparePGE(self.pGEs, A_G_V.get_solids())
else:
solids = comparePGE(self.pGEs, A_G_V.get_solids(2))
for obj in A_G_V.gameSprites["objects"]:
if obj.magic:
solids.append(obj)
newRect, death = physic_collision(move_vector, self.rect, solids, hazards)
if death:
A_G_V.loose()
deplaced = distancePoint(self.rect.center, newRect.center)
self.rect = newRect
if res.get_cheat(5):
self.rect = movedPlayer
exitRect = pygame.Rect(0, 0, 40, 40)
exitRect.center = A_G_V.gameSprites["exitPos"]
if collideCircle(self.rect, exitRect) and not self.noColl:
A_G_V.win()
for hazard in comparePGE(self.pGEs, A_G_V.gameSprites["hazardProjectiles"]):
if collideCircle(self.rect, hazard.hitbox) and not self.noColl:
hazard.kill()
A_G_V.loose()
self.cCAngle = get_angle(self.rect.center, A_G_V.mousePos)
res.stats["distanceTraveled"] += deplaced
if deplaced < 5:
self.skin = int(deplaced)
else:
self.skin = 5
A_G_V.gameSprites["particles"].add(1, 10, self.rect.center, (255, 255, 255), 200, 5, 1)
if self.freeze or not self.outStart:
self.skin = 6
if self.focusObj is None:
self.sDAngle = limitangle(self.sDAngle+self.sDRotate)
else:
if self.focusObj.alive():
self.sDAngle = get_angle(self.rect.center, self.focusObj.rect.center)
else:
self.unFocus()
if self.shootCoolDown <= 0 and not self.noColl and self.outStart:
if self.shooting == 1:
res.stats["projShooted"] += 1
res.soundMananger.playSound("shoot1")
if res.get_cheat(4):
for i in range(0,16,2):
A_G_V.addProj(projectile(self.rect.center, self.sDAngle+i-10, projectile_models["whiteArrow"]))
else:
proj = projectile(self.rect.center, self.sDAngle, projectile_models["whiteArrow"])
A_G_V.addProj(proj)
self.shootCoolDown = 20
if res.get_cheat(3):
self.shootCoolDown = 5
elif self.shooting == 2:
res.stats["projShooted"] += 1
res.soundMananger.playSound("shoot2")
randangle = spreadAngle(self.sDAngle, 7)
if res.get_cheat(4):
for i in range(0,16,2):
A_G_V.addProj(projectile(self.rect.center, randangle+i-10, projectile_models["blueFragment"]))
else:
proj = projectile(self.rect.center, randangle, projectile_models["blueFragment"])
proj.pos[0] += proj.motion[0]
proj.pos[1] += proj.motion[1]
A_G_V.addProj(proj)
self.shootCoolDown = 5
if res.get_cheat(3):
self.shootCoolDown = 1
else:
self.shootCoolDown -= 1
if self.shieldTime > 0:
self.shieldTime -= 1
if self.shieldTime == 1:
self.speed = 1
def shoot(self, button):
self.shooting = button
def unShoot(self, button=0):
if button == 0:
self.shooting = 0
elif self.shooting == button:
self.shooting = 0
def focusBlock(self, focusList):
if self.focusObj in focusList:
focusList.remove(self.focusObj)
self.unFocus()
if len(focusList) > 0:
angleList = []
for obj in focusList:
angle = get_angle(self.rect.center, obj.rect.center)
if self.sDAngle > 180 and angle < limitangle(self.sDAngle+180):
angle += 360
elif self.sDAngle <= 180 and angle > limitangle(self.sDAngle+180):
angle -= 360
angle = self.sDAngle-angle
if math.fabs(angle) < 23:
angleList.append([angle, obj])
angleList.sort(key=lambda a: math.fabs(a[0])+distancePoint(a[1].rect.center, self.rect.center)/50-(a[1].rect.width+a[1].rect.height)/20)
if len(angleList) > 0:
self.focusObj = angleList[0][1]
self.focusObj.focused()
def focusBlockDes(self):
if self.lastHit is not None:
self.unFocus()
self.focusObj = self.lastHit
self.focusObj.focused()
def blockHit(self, obj):
if obj.hardness > -1:
self.lastHit = obj
def rotate(self, way):
self.unFocus()
if way == 1:
self.sDRotate = 5
elif way == 2:
self.sDRotate = -5
def unRotate(self, way=0):
if way == 0:
self.sDRotate = 0
elif way == 1 and self.sDRotate > 0:
self.sDRotate = 0
elif way == 2 and self.sDRotate < 0:
self.sDRotate = 0
def unFocus(self):
if self.focusObj is not None:
self.focusObj.unFocused()
self.focusObj = None
def draw(self, window):
if not self.noColl:
if self.shield:
self.imgShield.draw(window, self.rect.center)
rotatedCC = pygame.transform.rotate(self.cursorCircle, self.cCAngle)
if self.focusObj is not None:
draw_dotted_line(window, self.rect.center, self.focusObj.rect.center, self.miniCount)
window.blit(self.skins[self.skin], self.rect.move(-1,-1))
if self.showCursor:
rotatedSD = pygame.transform.rotate(self.shootDirection, self.sDAngle)
window.blit(rotatedSD, rotatedSD.get_rect(center=self.rect.center))
if self.freeze == False:
if self.mouseDistance < 40:
opacity = 0
elif self.mouseDistance < 300:
opacity = self.mouseDistance-40/300*235+20
else:
opacity = self.mouseDistance = 255
blit_alpha(window, rotatedCC, rotatedCC.get_rect(center=self.rect.center), opacity)
else:
pygame.draw.circle(window, (255, 255, 255), self.rect.center, 30, 2)
if self.shieldTime > 0:
if self.shieldTime%3 == 0:
window.blit(res.images["player"][7], self.rect.move(-1, -1))
def hurt(self):
if not self.noColl and self.outStart:
if self.shield or self.shieldTime > 0:
self.shield = False
if self.shieldTime == 0:
self.shieldTime = 35
res.stats["shieldsDestroyed"] += 1
res.soundMananger.playSound("shieldLoss")
self.speed *= 0.4
return 2
return True
return False
return True
def tp(self, x, y):
self.unFocus()
self.rect.center = (x, y)
res.stats["distanceTraveled"] += (x+y)/2
def insens(self):
self.freeze = True
self.noColl = True
def uninsens(self):
self.freeze = False
self.noColl = False