-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbosses.py
199 lines (184 loc) · 8.03 KB
/
bosses.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
import pygame
import constants as C
import projectile
import random
pygame.init()
'''
make a big plane flying upwards slowly lowers to just most of the upper screen
secioned weekspots and turrets
no onhit for player but has rapit fire turets
drifts back and forth
'''
def closest(me,possible):
end=None
distance=None
for i in possible:
if distance==None:
end=i
distance=((me.rect.center[0]+i.rect.center[0])**2+(me.rect.center[1]+i.rect.center[1])**2)**.5
elif distance > ((me.rect.center[0]+i.rect.center[0])**2+(me.rect.center[1]+i.rect.center[1])**2)**.5:
distance = ((me.rect.center[0]+i.rect.center[0])**2+(me.rect.center[1]+i.rect.center[1])**2)**.5
end=i
return end
class turret(pygame.sprite.Sprite):
def __init__(self,x,y,size):
super().__init__()
self.origimage = pygame.Surface(size)
self.origimage.fill((255,255,255))
self.origimage.set_colorkey((255,255,255))
self.rect=self.origimage.get_rect()
pygame.draw.circle(self.origimage,(0,0,0),[int(self.rect.width/2),int(self.rect.height/2)],int(self.rect.width/4))
self.relative = [int(x),int(y)]
self.turretAngle=0
self.image = self.origimage
self.mode = "basic"
self.firecount = 5
def setloc(self,x,y):
self.rect.x=x+self.relative[0]-self.rect.width/2
self.rect.y=y+self.relative[1]-self.rect.height/2
def setfircount(self,n):
self.firecount=n
def setfiremode(self,mode):
self.mode = mode
def update(self,playerlist,attacklist):
target = closest(self,playerlist)
if target == None:
return None
self.turretAngle = C.vectorToAngle([self.rect.center[0]-target.rect.center[0],self.rect.center[1]-target.rect.center[1]])
self.firecount+=1
if self.mode=="basic"and self.firecount>random.randint(30,50):
anglelinepos=C.angleToVector(self.turretAngle,self.rect.width/2)
self.firecount=0
return("ea",projectile.shot(self.rect.center[0]-anglelinepos[0],self.rect.center[1]-anglelinepos[1],self.turretAngle+3.1415))
elif self.mode=="circle" and self.firecount>10:
self.turretAngle+=.5
self.firecount=0
return("ea",projectile.shot(self.rect.center[0]-anglelinepos[0],self.rect.center[1]-anglelinepos[1],self.turretAngle+3.1415))
anglelinepos=C.angleToVector(self.turretAngle,self.rect.width/2)
self.image=self.origimage.copy()
pygame.draw.line(self.image,(0,0,0),(self.rect.width/2,self.rect.height/2),[self.rect.width/2-anglelinepos[0],self.rect.height/2-anglelinepos[1]],5)
def crash(self):
return "nocolide"
class WeakPoint(pygame.sprite.Sprite):
def __init__(self,image,x,y):
super().__init__()
self.image = image
self.image.set_colorkey(self.image.get_at((0,0)))
self.rect = self.image.get_rect()
self.relative = [int(x),int(y)]
self.setloc(0,0)
self.flicker = True
self.health=5
self.maxHealth = 5
def isdead(self):
if self.health<1:
return True
else:
return False
def setloc(self,x,y):
self.rect.x=x+self.relative[0]
self.rect.y=y+self.relative[1]
def update(self,playerlist,attacklist):
self.rect.y-=C.backgroundScroll
if self.health>0:
hits=pygame.sprite.spritecollide(self, attacklist, False)
for i in hits:
temp=i.hit()
self.health-=temp
if self.health<1:
self.flicker = False
def crash(self):
return "nocolide"
MAXSPEED = 1
accelfactor=3
class bigPlane(pygame.sprite.Sprite):
def gs(self,x,y,dx,dy):
gsimage = pygame.Surface([dx, dy])
gsimage.fill((234,154,45))
gsimage.set_colorkey((234,154,45))
gsimage.blit(self.spritesheet,(0,0),(x,y,dx,dy))
return gsimage
def __init__(self,x,y):#50,38
super().__init__()
self.spritesheet = pygame.image.load("assets/boss.png")
animations = [self.gs(0,38*2,50,38),self.gs(50,38*2,50,38)]
for t in range(4):
for i in range(len(animations)):
animations[i] = pygame.transform.scale2x(animations[i])
self.image=animations[0]
self.rect = self.image.get_rect()
self.rect.center = (x,y)
self.leftWingSpot = self.makeWeakPoints(6*16,11*16,4*17,4*17,50)#6,11
self.rightWingSpot = self.makeWeakPoints(self.rect.width-6*16-4*17,11*16,4*17,4*17,50)#6,11
self.leftcenter = self.makeWeakPoints(12*16,11*16,4*17,4*17,50,adj=True)#6,11
self.rightcenter =self.makeWeakPoints(self.rect.width-12*16-4*17,11*16,4*17,4*17,50,adj=True)#6,11
self.leftcenter2 = self.makeWeakPoints(18*16,11*16,4*17,4*17,50,adj=True)#6,11
self.rightcenter2 =self.makeWeakPoints(self.rect.width-18*16-4*17,11*16,4*17,4*17,50,adj=True)#6,11
self.weakspots = [self.leftWingSpot,self.rightWingSpot,self.leftcenter,self.rightcenter,self.leftcenter2,self.rightcenter2]
self.turret = turret(self.rect.width/2,self.rect.height/2,[32,32])
self.turret1 = turret(self.rect.width/2-40,self.rect.height/2+40,[32,32])
self.turret2 = turret(self.rect.width/2+40,self.rect.height/2+40,[32,32])
self.turrets = [self.turret,self.turret1,self.turret2]
#
if 1==random.randint(0,1):
self.headingPrime=[1,0] #where I want to go
else:
self.headingPrime=[-1,0]
self.heading=[0,0]#current speed
self.first = True
def update(self,playerlist,attacklist):
self.accel()
self.speed()
self.pos()
for i in self.weakspots:
i.setloc(self.rect.x,self.rect.y)
for i in self.turrets:
i.setloc(self.rect.x,self.rect.y)
dead=True
for i in self.weakspots:
if i.isdead() == False:
dead=False
break
if dead==True:
return(["explosion","cheap"])
if self.first==True:
self.first=False
return ("ep",self.leftWingSpot,self.rightWingSpot,self.turret,self.turret1,self.turret2,self.leftcenter,self.rightcenter,self.leftcenter2,self.rightcenter2)
def crash(self):
return "nocolide"
def die(self):
for i in self.weakspots:
i.kill()
for i in self.turrets:
i.kill()
self.kill()
def makeWeakPoints(self,x,y,dx,dy,health,adj=None):#pygame.transform.chop()
if adj==None:
croped = pygame.Surface((dx,dy))
croped.blit(self.image,(0,0),(x,y,dx,dy))
return WeakPoint(croped,x,y)
elif adj==True:
croped = pygame.Surface((dx,dy))
croped.blit(self.image,(0,0),(6*16,11*16,dx,dy))
return WeakPoint(croped,x,y)
def accel(self):
if self.rect.left<-100+random.randint(-50,50):
self.headingPrime[0] = 1
elif self.rect.right>C.screenSize[0]+100+random.randint(-50,50):
self.headingPrime[0] = -1
if self.rect.top<-100+random.randint(-50,50):
self.headingPrime[1] = 1
elif self.rect.bottom>C.screenSize[1]+100+random.randint(-50,50):
self.headingPrime[1] = -1
def speed(self):
if self.headingPrime[0]>0 and self.heading[0] < MAXSPEED:
self.heading[0]+=self.headingPrime[0]/accelfactor
elif self.headingPrime[0]<0 and self.heading[0] > -MAXSPEED:
self.heading[0]+=self.headingPrime[0]/accelfactor
if self.headingPrime[1]>0 and self.heading[1] < MAXSPEED:
self.heading[1]+=self.headingPrime[1]/accelfactor
elif self.headingPrime[1]<0 and self.heading[1] > -MAXSPEED:
self.heading[1]+=self.headingPrime[1]/accelfactor
def pos(self):
self.rect.x+=self.heading[0]
self.rect.y+=self.heading[1]