-
Notifications
You must be signed in to change notification settings - Fork 2
/
sprites.py.bak
254 lines (215 loc) · 7.29 KB
/
sprites.py.bak
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
import pygame
import random
from math import *
from pygame.locals import *
import ai
class Sprite(pygame.sprite.Sprite):
def __init__(self, centerPoint, image):
pygame.sprite.Sprite.__init__(self)
self.image = image
self.rect = image.get_rect()
self.rect.center = centerPoint
class Object(Sprite):
def __init__(self, centerPoint, image):
Sprite.__init__(self, centerPoint, image)
def update(self, xMove=0, yMove=0):
self.rect.move_ip(xMove,yMove)
class Bullet(Sprite):
def __init__(self, centerPoint, image, angle, data):
Sprite.__init__(self, centerPoint, image)
self.dam, self.speed, angleFactor, self.speedFactor, self.charge, self.homing, self.spin = data
self.stored_rotation = 0
if angleFactor != 0:
factorA,factorB = angleFactor
factor = random.randint(factorA,factorB)
else:
factor = 0
float(factor)
self.angleFactor = factor
self.angle = angle
rotation = self.angle * (pi / 180)
self.xMove = cos(rotation) * self.speed
self.yMove = sin(rotation) * self.speed
self.image_base = self.image
def update(self, target):
if self.homing == 0:
self.angle += self.angleFactor
else:
if target != None:
m = target
x,y,w,h = self.rect
x += w / 2
y += h / 2
mx,my,mw,mh = m.rect
mx += mw / 2
my += mh / 2
if x < mx and self.angle < -70:
self.angle += self.homing
elif x > mx and self.angle > -110:
self.angle -= self.homing
if self.spin != 0:
self.stored_rotation += self.spin
self.image = pygame.transform.rotate(self.image_base, self.stored_rotation)
else:
imgRotation = ((self.angle * -1) - 90)
self.image = pygame.transform.rotate(self.image_base, imgRotation)
self.speed += self.speedFactor
x,y,w,h = self.rect
if y > 1004 or y < -504 or x > 1004 or x < -504:
self.kill()
if self.speed <= 0:
self.kill()
rotation = self.angle * (pi / 180)
self.xMove = cos(rotation) * self.speed
self.yMove = sin(rotation) * self.speed
self.rect.move_ip(self.xMove,self.yMove)
class monsterBullet(Sprite):
def __init__(self, centerPoint, image, angle, data):
Sprite.__init__(self, centerPoint, image)
self.image_base = image
self.dam, self.speed, self.angleFactor, self.speedFactor, self.dirChangePoint, self.dirChangeFactor, self.dirChangeTime, self.spin = data
self.stored_spin = 0
self.dir_change_point_timer = 0
self.dir_change_timer = 0
self.dir_change = False
self.angle = angle
rotation = self.angle * (pi / 180)
self.xMove = cos(rotation) * self.speed
self.yMove = sin(rotation) * self.speed
def update(self):
self.image = self.image_base
if self.dir_change == True:
self.dir_change_timer += 1
angleFactor = self.angleFactor + self.dirChangeFactor
if self.dir_change_timer == self.dirChangeTime:
self.dir_change = False
self.dir_change_timer = 0
else:
angleFactor = self.angleFactor
self.dir_change_point_timer += 1
if self.dir_change_point_timer == self.dirChangePoint:
self.dir_change = True
self.dir_change_point_timer = 0
if angleFactor != 0 and self.spin == 0:
imgRotation = ((self.angle * -1) + 90)
self.image = pygame.transform.rotate(self.image_base, imgRotation)
elif self.spin != 0:
imgRotation = ((self.stored_spin) + 90)
self.image = pygame.transform.rotate(self.image_base, imgRotation)
self.stored_spin += self.spin
self.spin = self.spin * self.speedFactor
self.angle = self.angle + angleFactor
self.speed = self.speed * self.speedFactor
x,y,w,h = self.rect
if y > 1004 or y < -504 or x > 1004 or x < -504:
self.kill()
if self.speed < 1:
self.kill()
elif self.speed >= h:
self.speed = h
rotation = self.angle * (pi / 180)
self.xMove = cos(rotation) * self.speed
self.yMove = sin(rotation) * self.speed
self.rect.move_ip(self.xMove,self.yMove)
class Monster(ai.BasicAI):
def __init__(self, centerPoint, image, data):
ai.BasicAI.__init__(self, centerPoint, image, data)
self.dying = False
self.giving_charge_points = False
def update(self, bullets):
ai.BasicAI.update(self)
self.rect.move_ip(self.xMove,self.yMove)
for b in pygame.sprite.spritecollide(self, bullets, False):
self.health = self.health - b.dam
if b.charge == False:
self.giving_charge_points = True
b.kill()
if self.health < 1:
self.dying = True
class Shield(Sprite):
def __init__(self, centerPoint, image, data):
Sprite.__init__(self, centerPoint, image)
self.health, self.life_timer_max = data
self.life_timer = 0
def update(self, bullet_group_a, bullet_group_b):
self.life_timer += 1
if self.life_timer == self.life_timer_max:
self.kill()
for b in pygame.sprite.spritecollide(self, bullet_group_a, False):
self.health -= b.dam
b.kill()
for b in pygame.sprite.spritecollide(self, bullet_group_b, False):
self.health -= b.dam
b.kill()
if self.health < 1:
self.kill()
class Hitbox(Sprite):
def __init__(self, centerPoint, image, data):
Sprite.__init__(self, centerPoint, image)
self.xMove, self.yMove = 0,0
self.xPub, self.yPub = self.xMove, self.yMove
self.x_dist, self.y_dist, self.health, self.stamina_gain, self.stamina_loss, self.bullet_data, self.charge_speed, self.charge_bullet_data, self.shield_cost, self.shield_gain, self.shield_data, self.delay_bullets = data
self.facing = 2
self.dam = self.bullet_data[3]
self.stamina_max = 100
self.shield_max = 100
self.charge_max = 100
self.charge = 0
self.stamina = self.stamina_max
self.shield = self.shield_max
self.firing = False
self.stamina_out = False
self.moveable = False
def update(self, vert_walls, hori_walls, bullets):
if self.moveable == True:
self.xPub,self.yPub = self.xMove,self.yMove
self.rect.move_ip(self.xMove,self.yMove)
if pygame.sprite.spritecollideany(self, vert_walls):
self.rect.move_ip(-self.xMove,0)
self.xPub = 0
if pygame.sprite.spritecollideany(self, hori_walls):
self.rect.move_ip(0,-self.yMove)
self.yPub = 0
if self.xMove == 0 and self.yMove == 0:
self.facing = 2
if self.stamina == 0:
self.firing = False
for b in pygame.sprite.spritecollide(self, bullets, False):
self.health = self.health - b.dam
b.kill()
if self.health < 1:
self.kill()
if self.stamina < self.stamina_max:
self.stamina += self.stamina_gain
if self.stamina > self.stamina_max:
self.stamina = self.stamina_max
if self.shield < self.shield_max:
self.shield += self.shield_gain
if self.stamina_out == True and self.stamina == 100:
self.stamina_out = False
def MoveKeyDown(self, key):
if (key == K_RIGHT):
self.xMove += self.x_dist
self.facing = 3
elif (key == K_LEFT):
self.xMove += -self.x_dist
self.facing = 1
elif (key == K_UP):
self.yMove += -self.y_dist
self.facing = 2
elif (key == K_DOWN):
self.yMove += self.y_dist
self.facing = 2
def MoveKeyUp(self, key): # FIX ME! As is, this can cause player drift on respawn, but if those boolean checks are uncommented, it causes stick when changing from right<->left or up<->down
if (key == K_RIGHT):
#if self.xMove < 0 or self.xMove > 0:
self.xMove += -self.x_dist
elif (key == K_LEFT):
#if self.xMove < 0 or self.xMove > 0:
self.xMove += self.x_dist
elif (key == K_UP):
#if self.yMove < 0 or self.yMove > 0:
self.yMove += self.y_dist
elif (key == K_DOWN):
#if self.yMove < 0 or self.yMove > 0:
self.yMove += -self.y_dist