Splash agregado
[tajundrathegame.git] / qwesprites.py
blob34c9f6e8672a1297cd6c7d73f9804441c39c9e92
1 # Quick W Engine
2 # encoding: UTF-8
3 import pygame
4 import math
5 import random
8 class qweSprite(pygame.sprite.Sprite):
9 dx=dy=x=y=0
10 w=h=32
11 alive=True
12 LevelFinished=False
13 in_ground=False
14 FRICTION_AIR=(0.2,0.2)
15 FRICTION_FLOOR=(8,8)
16 FRICTION_CEIL=(0.1,4)
17 GRAVITY=5
18 BOUNCE=-.1
19 RADIUS=16
20 psx=-1
21 psy=-1
22 ShowLife=MaxLife=Life=240
23 DIE_IMG='pernil.png'
24 accum_ms=1000
25 accum_dist=1000
27 REGEN=1
28 #MAX_ACCUMMS=200
29 #MAX_ACCUMDIST=1000
31 MAX_ACCUMMS=100
32 MAX_ACCUMDIST=500
33 MAX_ITERMS=33
35 #MAX_ACCUMMS=50
36 #MAX_ACCUMDIST=250
38 LifeCollisionCost=0
39 LifeCollisionSpriteCost=2
40 MARGIN_LEFT=+2
41 MARGIN_RIGHT=-2
42 MARGIN_TOP=+1
43 MARGIN_BOTTOM=-1
44 fcount=0
45 SOLID=True
46 FSOLID=True
47 Layer=1
48 Item="?"
49 ItemTime=0
51 def __init__(self, stage):
52 pygame.sprite.Sprite.__init__(self)
53 if self.Layer==1: stage.sprites+=[self]
54 if self.Layer==2: stage.background_sprites+=[self]
56 def move(self,x,y):
57 self.x+=x
58 self.y+=y
59 d=math.sqrt(x*x+y*y)
60 self.accum_dist+=d*1000.0
62 self.rect=pygame.Rect(self.x,self.y,self.w,self.h)
64 def selectImage(self):
65 return self.image
67 def die(self,screen):
68 Life(screen,(int(self.x),int(self.y)),self.DIE_IMG,self.MaxLife/10.0)
71 def draw(self,screen,list_rects=None):
72 if self.accum_ms>0:
73 if list_rects:
74 if self.rect.collidelist(list_rects)==.1: return
75 self.fcount+=1
76 if self.fcount>10/(self.Life+1):
77 self.fcount=4
78 screen.blit(self.selectImage(), self.rect)
79 if self.ShowLife>self.Life or (self.Life < 60 and self.ShowLife>0):
80 if self.ShowLife<0: self.ShowLife=0
81 x,y,h,w=self.rect
82 pp=100.0*self.ShowLife/self.MaxLife
83 pp=pp+math.log(1+1.9*self.ShowLife/self.MaxLife)*100.0
84 if pp>200.0:
85 pp=200
86 if pp>100.0:
87 pp1=100
88 pp2=pp-100
89 else:
90 pp1=pp
91 pp2=0
93 w-=8
94 x+=1
95 y+=0
96 p1=x,y
97 p2=x+pp1*w/100.0,y
98 p1a=x,y+1
99 p2a=x+pp2*w/100.0,y+1
101 p=255.0*pp1/100.0
102 if pp2:
103 p=255.0*pp2/100.0
104 pygame.draw.line(screen, (255-p,255,0) , p1a, p2a,1)
105 pygame.draw.line(screen, (255-p,255,0) , p1, p2,1)
106 else:
107 pygame.draw.line(screen, (255,p,0) , p1, p2,1)
109 def tickms(self, ms, stage):
110 if not self.alive:
111 self.MAX_ACCUMMS = -1
114 rect1=pygame.Rect(self.rect)
115 d=math.sqrt(self.dx*self.dx+self.dy*self.dy)
116 self.accum_ms+=ms
117 #self.accum_dist+=d*self.accum_ms
118 if self.ShowLife>self.Life:
119 self.accum_dist+=(self.ShowLife-self.Life)
121 if self.Life<1:
122 self.accum_dist+=10/(self.Life+0.1)
124 if self.accum_ms>self.MAX_ACCUMMS or \
125 self.accum_dist+d*self.accum_ms>self.MAX_ACCUMDIST:
126 ms=self.accum_ms
127 self.accum_ms=0
128 self.accum_dist=0
130 if (self.ItemTime>0):
131 self.ItemTime-=ms
132 else:
133 self.ItemTime=0
135 if (self.Life<0):
136 self.alive=False
137 self.die(stage)
138 else:
139 if (self.REGEN<0 or self.Life<self.MaxLife):
140 self.Life+=self.REGEN*ms/1000.0
142 if self.ShowLife>self.Life:
143 self.ShowLife-=ms/100.0
144 if self.ShowLife<self.Life:
145 self.ShowLife=self.Life
146 factor=1
147 if d*self.accum_ms>1000: factor=d*self.accum_ms/1000.0
148 while(ms>0):
149 iter_ms=ms
150 if (iter_ms>self.MAX_ITERMS/factor): iter_ms=self.MAX_ITERMS/factor
152 self.checkpos(stage,iter_ms)
153 self.move(self.dx*iter_ms/1000.0,self.dy*iter_ms/1000.0)
154 self.dx/=1+self.FRICTION_AIR[0]*iter_ms/1000.0
155 self.dy/=1+self.FRICTION_AIR[1]*iter_ms/1000.0
156 ms-=iter_ms
158 rect2=self.rect
159 self.psx,self.psy=self.getpspoint(stage,0,0);
161 return [rect1.union(rect2)]
162 else:
163 return []
166 def getpspoint(self,stage,px,py):
167 sx,sy=stage.BlockSize
168 x,y,w,h=self.rect
170 if px>0: x0=x+px
171 elif px<0: x0=x+w+px
172 else: x0=x+w/2
174 if py>0: y0=y+py
175 elif py<0: y0=y+h+py
176 else: y0=y+h/2
178 x0=int(x0)/sx
179 y0=int(y0)/sy
181 return (x0,y0)
183 def collision(self,stage,x,y,char):
184 if self.ItemTime==0:
185 Pantalla=stage.StageData
187 if char=='P':
188 self.alive=False
189 self.LevelFinished=True
191 if not self.Item:
192 if char=='z':
193 self.Item=char
194 self.ItemTime=1000
195 stage.setCh(x,y,' ')
196 stage.checkPortal()
197 else:
198 if char=='Z' and self.Item=='z' and stage.getCh(x,y-1)==' ':
199 testrect=pygame.Rect(x*32+8,(y-1)*32+8,16,16)
201 put_in_place=True
202 for sprite in stage.sprites:
203 if sprite.FSOLID and sprite.rect.colliderect(testrect):
204 put_in_place=False
206 if put_in_place:
207 stage.setCh(x,y-1,'z')
208 stage.checkPortal()
209 self.ItemTime=1000
210 self.Item=''
213 def checkcell(self,stage,px,py):
214 Pantalla=stage.StageData
216 x0,y0=self.getpspoint(stage,px,py);
218 if y0<0 and x0>=0 and x0<len(Pantalla[0]): return ' '
219 if y0>=0 and y0<len(Pantalla):
220 if x0>=0 and x0<len(Pantalla[y0]):
221 ch=Pantalla[y0][x0]
222 self.collision(stage,x0,y0,ch)
224 return ch
226 return 't'
228 def checkpos(self,stage,ms):
229 self.in_ground=False
231 if self.Life<1:
232 MAX_ACCUMMS=1
233 self.REGEN=-1
234 if self.Life>0.5:
235 for sprite in stage.sprites:
236 if sprite!=self and sprite.RADIUS>0 and sprite.Life>0.5:
237 if ( math.fabs(sprite.psx-self.psx)<=1
238 and math.fabs(sprite.psy-self.psy)<=1):
239 x,y,w,h=self.rect
240 sx,sy,sw,sh=sprite.rect
242 min_d=self.RADIUS+sprite.RADIUS
244 ax=x-sx;ay=y-sy;
245 d1=math.sqrt(ax*ax+ay*ay)
246 if d1<min_d:
247 x+=self.dx/1000.0
248 y+=self.dy/1000.0
249 sx+=sprite.dx/1000.0
250 sy+=sprite.dy/1000.0
252 ax=x-sx;ay=y-sy;
253 d2=math.sqrt(ax*ax+ay*ay)
254 if d2<=d1:
255 sdx=sprite.dx
256 sdy=sprite.dy
257 if sprite.SOLID and self.FSOLID:
258 sprite.dx=self.dx
259 sprite.dy=self.dy
261 if self.SOLID and sprite.FSOLID:
262 self.dx=sdx
263 self.dy=sdy
265 if self.Life<900:
266 self.Life-=sprite.LifeCollisionSpriteCost
267 if self.Life<0.5: self.Life=0.5
268 if self.ShowLife>0:
269 self.ShowLife=self.Life+10
271 if sprite.Life<900:
272 sprite.Life-=self.LifeCollisionSpriteCost
273 if sprite.Life<0.5:
274 sprite.Life=0.5
275 if sprite.ShowLife>0:
276 sprite.ShowLife=sprite.Life+10
279 if d2<=d1+0.1:
280 self.in_ground=True
281 x,y,w,h=self.rect
282 ax=x-sx;ay=y-sy;
283 d1=math.sqrt(ax*ax+ay*ay)+1
284 if self.SOLID and sprite.FSOLID:
285 self.dx+=20*ax/d1
286 self.dy+=20*ay/d1
288 if sprite.SOLID and self.FSOLID:
289 sprite.dx-=20*ax/d1
290 sprite.dy-=20*ay/d1
294 # Colisión Horizontal
295 if ( (self.checkcell(stage,self.MARGIN_RIGHT,0)!=' ' and self.dx>=0) or
296 (self.checkcell(stage,self.MARGIN_RIGHT,12)!=' ' and self.dx>=0) or
297 (self.checkcell(stage,self.MARGIN_RIGHT,-12)!=' ' and self.dx>=0) ) :
298 if self.Life<900: self.Life-=self.LifeCollisionCost
299 self.move(-self.dx*ms/1000.0-.1,0)
300 if (self.BOUNCE>0): self.dx*=-self.BOUNCE
301 else: self.dx/=1-self.BOUNCE
303 if ( (self.checkcell(stage,self.MARGIN_LEFT,0)!=' ' and self.dx<=0) or
304 (self.checkcell(stage,self.MARGIN_LEFT,12)!=' ' and self.dx<=0) or
305 (self.checkcell(stage,self.MARGIN_LEFT,-12)!=' ' and self.dx<=0) ) :
306 if self.Life<900: self.Life-=self.LifeCollisionCost
307 self.move(-self.dx*ms/1000.0+.1,0)
308 if (self.BOUNCE>0): self.dx*=-self.BOUNCE
309 else: self.dx/=1-self.BOUNCE
311 if ( (self.checkcell(stage,self.MARGIN_RIGHT-3,0)!=' ') and
312 (self.checkcell(stage,self.MARGIN_RIGHT-3,12)!=' ') and
313 (self.checkcell(stage,self.MARGIN_RIGHT-3,-12)!=' ') ) :
314 self.move(-3,0)
316 if ( (self.checkcell(stage,self.MARGIN_LEFT+3,0)!=' ') and
317 (self.checkcell(stage,self.MARGIN_LEFT+3,12)!=' ') and
318 (self.checkcell(stage,self.MARGIN_LEFT+3,-12)!=' ') ) :
319 self.move(+3,0)
322 # Control de hundimiento
323 if self.dy>=0:
324 if (self.checkcell(stage,self.MARGIN_LEFT+4,self.MARGIN_BOTTOM-1)!=' '
325 or self.checkcell(stage,self.MARGIN_RIGHT-4,self.MARGIN_BOTTOM-1)!=' ') and \
326 (self.checkcell(stage,self.MARGIN_LEFT+4,self.MARGIN_TOP+1)==' '
327 and self.checkcell(stage,self.MARGIN_RIGHT-4,self.MARGIN_TOP+1)==' '):
328 self.move(0,-1)
329 self.dy=0
331 if (self.checkcell(stage,0,0)!=' '):
332 self.move(0,-1)
333 self.dy=0
334 # Colisión de techo
335 elif self.dy<0:
336 if (self.checkcell(stage,self.MARGIN_LEFT+4,self.MARGIN_TOP)!=' ' or
337 self.checkcell(stage,self.MARGIN_RIGHT-4,self.MARGIN_TOP)!=' ' or
338 self.checkcell(stage,0,self.MARGIN_TOP)!=' '):
340 if self.Life<900: self.Life-=self.LifeCollisionCost
341 self.move(0,-self.dy*ms/1000.0)
342 if (self.BOUNCE>0): self.dy*=-self.BOUNCE
343 else: self.dy/=1-self.BOUNCE
344 self.dx/=1+self.FRICTION_CEIL[0]*ms/1000.0
345 self.dy/=1+self.FRICTION_CEIL[1]*ms/1000.0
346 if self.checkcell(stage,0,+2)!=' ' and self.dy<0:
347 self.dx/=1+self.FRICTION_CEIL[0]*ms/1000.0
348 self.dy/=1+self.FRICTION_CEIL[1]*ms/1000.0
349 if self.checkcell(stage,0,+3)!=' ' and self.dy<0:
350 self.dy=0
354 # Colisión suelo
355 if ((self.checkcell(stage,self.MARGIN_LEFT+4,self.MARGIN_BOTTOM)!=' '
356 and self.checkcell(stage,0,self.MARGIN_BOTTOM)!=' ')
357 or (self.checkcell(stage,self.MARGIN_RIGHT-4,self.MARGIN_BOTTOM)!=' '
358 and self.checkcell(stage,0,self.MARGIN_BOTTOM)!=' ')
361 self.dx/=1+self.FRICTION_FLOOR[0]*ms/1000.0
362 if self.dy>0:
363 if self.Life<900: self.Life-=self.LifeCollisionCost
364 if (self.BOUNCE>0): self.dy*=-self.BOUNCE
365 else: self.dy/=1-self.BOUNCE
366 self.dy/=1+self.FRICTION_FLOOR[1]*ms/1000.0
367 self.move(0,-self.dy*ms/1000.0)
369 elif self.dy<0:
370 pass
372 self.in_ground=True
373 else:
374 # Gravedad
375 if self.checkcell(stage,self.MARGIN_LEFT+4,self.MARGIN_BOTTOM)!=' ': self.dx+=1
376 if self.checkcell(stage,self.MARGIN_RIGHT-4,self.MARGIN_BOTTOM)!=' ': self.dx-=1
377 self.dy+=self.GRAVITY
379 if self.Life>self.MaxLife*1.5: self.Life=self.MaxLife*1.5
381 class qweText(qweSprite):
382 FONT=None
383 GRAVITY=0
384 SOLID=False
385 FSOLID=False
386 Life=1000
387 LifeCollisionSpriteCost=0
388 ShowLife=0
389 RADIUS=0
390 MAX_ACCUMMS=0
391 MAX_ACCUMDIST=0
393 def __init__(self, stage,x,y,txt,font,color):
395 qweSprite.__init__(self,stage)
396 self.FONT=font
398 self.image=font.render(txt, True, color)
400 self.rect = self.image.get_rect()
402 self.x,self.y,self.w,self.h=self.rect
403 self.x=x
404 self.y=y
406 def collision(self,stage,x,y,char):
407 return
409 def checkcell(self,stage,px,py):
410 return ' '
412 def checkpos(self,stage,ms):
413 return
416 global qweTextBasic_font
417 qweTextBasic_font=None
418 global qweTextBIG_font
419 qweTextBIG_font=None
421 class qweTextBasic(qweText):
422 def __init__(self, stage,x,y,txt):
423 global qweTextBasic_font
424 if not qweTextBasic_font:
425 qweTextBasic_font=pygame.font.Font(None,15)
427 color=(0,255,0)
428 self.Layer=2
429 qweText.__init__(self,stage,x,y,txt,qweTextBasic_font,color)
431 class qweTextBIG(qweText):
432 def __init__(self, stage,x,y,txt):
433 qweSprite.__init__(self,stage)
434 global qweTextBIG_font
435 if not qweTextBIG_font:
436 qweTextBIG_font=pygame.font.Font(None,64)
438 self.FONT=qweTextBIG_font
440 self.image1=qweTextBIG_font.render(txt, True, (0,0,0))
441 self.image2=qweTextBIG_font.render(txt, True, (255,255,255))
442 w,h = self.image1.get_size()
443 w+=5
444 h+=5
445 self.image=pygame.Surface((w,h),pygame.SRCALPHA).convert_alpha()
446 self.image.fill((0,0,0,0))
447 self.image.blit(self.image1,(5,5))
448 self.image.blit(self.image2,(0,0))
451 self.rect = self.image.get_rect()
453 self.x,self.y,self.w,self.h=self.rect
454 self.x=x-w/2
455 self.y=y-h/2
458 class Tajundra(qweSprite):
459 image_flip=None
460 estado=0
461 estado_ms=0
462 MARGIN_LEFT=+8
463 MARGIN_RIGHT=-8
464 MARGIN_TOP=+1
465 MARGIN_BOTTOM=-1
466 RADIUS=10
467 BOUNCE=0
468 Item=None
469 DIE_IMG='platano.png'
470 MAX_ACCUMMS=50
471 MAX_ACCUMDIST=250
472 REGEN=-1
474 def __init__(self, stage):
476 qweSprite.__init__(self,stage)
477 self.image_right = pygame.image.load('tajuA1.png')
478 self.image_left=pygame.transform.flip(self.image_right,True,False)
480 self.imageb_right = pygame.image.load('tajuA2.png')
481 self.imageb_left=pygame.transform.flip(self.imageb_right,True,False)
484 self.image=self.image_right
485 self.rect = self.image.get_rect()
486 pos=stage.simbolos['@'][0]
487 del stage.simbolos['@'][0]
488 self.rect.bottomright = pos
489 self.rect=self.rect.move(stage.BlockSize)
490 self.x,self.y,self.w,self.h=self.rect
492 def selectImage(self):
493 dx=self.dx
494 if self.estado==0:
495 if dx<0:
496 self.image=self.image_left
497 else:
498 self.image=self.image_right
499 else:
500 if dx<0:
501 self.image=self.imageb_left
502 else:
503 self.image=self.imageb_right
504 self.estado_ms+=1
505 if self.estado_ms>20:
506 self.estado_ms=0
507 if self.estado==0:
508 self.estado=1
509 else:
510 self.estado=0
511 return self.image
517 class Dragon(qweSprite):
518 image_flip=None
519 estado=0
520 estado_ms=0
521 MAX_ACCUMMS=200
522 MAX_ACCUMDIST=1000
523 MAX_ITERMS=100
524 BOUNCE=-.1
525 direction=1
527 def __init__(self, stage):
529 qweSprite.__init__(self,stage)
530 self.image_left = pygame.image.load('dragonN1.png')
531 self.image_right=pygame.transform.flip(self.image_left,True,False)
533 self.imageb_left = pygame.image.load('dragonN2.png')
534 self.imageb_right=pygame.transform.flip(self.imageb_left,True,False)
537 self.image=self.image_right
538 self.rect = self.image.get_rect()
539 pos=stage.simbolos['$'][0]
540 del stage.simbolos['$'][0]
542 self.rect.bottomright = pos
543 self.rect=self.rect.move(stage.BlockSize)
544 self.x,self.y,self.w,self.h=self.rect
546 def selectImage(self):
547 dx=self.dx
548 if self.estado==0:
549 if dx<0:
550 self.image=self.image_left
551 else:
552 self.image=self.image_right
553 else:
554 if dx<0:
555 self.image=self.imageb_left
556 else:
557 self.image=self.imageb_right
558 self.estado_ms+=1
559 if self.estado_ms>20:
560 self.estado_ms=0
561 if self.estado==0:
562 self.estado=1
563 else:
564 self.estado=0
565 return self.image
567 def tickms(self, ms, stage):
568 if self.dx<-10: self.direction=-1
569 if self.dx>+10: self.direction=+1
571 if self.checkcell(stage,self.MARGIN_RIGHT,0)!=' ': self.direction=-1
572 if self.checkcell(stage,self.MARGIN_LEFT,0)!=' ': self.direction=+1
574 if self.checkcell(stage,self.MARGIN_RIGHT,self.MARGIN_BOTTOM)==' ': self.direction=-1
575 if self.checkcell(stage,self.MARGIN_LEFT,self.MARGIN_BOTTOM)==' ': self.direction=+1
576 v=qweSprite.tickms(self, ms, stage)
577 self.dx+=self.direction
579 return v
581 class LanzaBolas(qweSprite):
582 image_flip=None
583 MAX_ACCUMMS=200
584 MAX_ACCUMDIST=1000
585 MAX_ITERMS=200
586 BOUNCE=.2
588 estado=0
589 estado_ms=0
590 BOUNCE=0
591 DIE_IMG='safanoria.png'
592 def __init__(self, stage):
594 qweSprite.__init__(self,stage)
595 self.image = pygame.image.load('lanzabolas1.png')
597 self.rect = self.image.get_rect()
598 pos=stage.simbolos['|'][0]
599 del stage.simbolos['|'][0]
601 self.rect.bottomright = pos
602 self.rect=self.rect.move(stage.BlockSize)
603 self.x,self.y,self.w,self.h=self.rect
604 self.estado_ms=random.randint(6000,12000)
606 def selectImage(self):
607 return self.image
609 def tickms(self, ms, stage):
611 v=qweSprite.tickms(self, ms, stage)
612 self.estado_ms+=ms
613 if self.estado_ms>10000 and self.Life>10:
614 random.seed()
615 self.estado_ms=random.randint(0,1000)
616 r=random.randint(-1000,1000)/3.0
617 disparo=Bola(stage,(int(self.x),int(self.y)),r,-200)
618 disparo.move(0,-10)
619 disparo.GRAVITY=1
621 return v
625 class qweShoot(qweSprite):
626 estado=0
627 estado_ms=0
628 FRICTION_AIR=(0.0,0.0)
629 FRICTION_FLOOR=(0.0,0.0)
630 FRICTION_CEIL=(0.0,0.0)
631 GRAVITY=0
632 BOUNCE=.5
633 MaxLife=Life=2.0
634 ShowLife=0
635 LifeCollisionCost=1
636 LifeCollisionSpriteCost=10
637 REGEN=-1
639 fcount=0
640 accum_ms=0
642 MARGIN_LEFT=+10
643 MARGIN_RIGHT=-10
644 MARGIN_TOP=+10
645 MARGIN_BOTTOM=-10
647 def __init__(self, stage, pos,dx,dy):
649 qweSprite.__init__(self,stage)
650 self.image = pygame.image.load('bola1.png')
652 self.rect = self.image.get_rect()
654 self.rect.topleft = pos
655 self.dx=dx
656 self.dy=dy
657 self.x,self.y,self.w,self.h=self.rect
658 d=math.sqrt(dx*dx+dy*dy)+5
659 self.tickms(1000/d,stage);
661 def collision(self,stage,x,y,char):
662 qweSprite.collision(self,stage,x,y,char)
663 if self.ItemTime==0:
664 nchar=char
666 if char=='M': nchar='N'
667 if char=='N': nchar='m'
668 if char=='m': nchar='n'
669 if char=='n': nchar=' '
671 if char!=nchar:
672 stage.setCh(x,y,nchar)
673 self.Life-=1
674 self.ItemTime=1000
678 def die(self,screen):
679 pass
681 class Bola(qweShoot):
682 FRICTION_AIR=(1.0,1.0)
683 GRAVITY=20
684 BOUNCE=.5
685 MaxLife=Life=12.0
686 LifeCollisionCost=1
687 RADIUS=5
688 MAX_ACCUMMS=200
689 MAX_ACCUMDIST=1000
690 MAX_ITERMS=200
692 class Hacha(qweShoot):
693 FRICTION_AIR=(0.5,0.0)
694 BOUNCE=.8
695 MaxLife=60
696 Life=2
697 LifeCollisionCost=0.1
698 LifeCollisionSpriteCost=10
699 fcountrot=0
700 angle=0
701 GRAVITY=5
702 RADIUS=10
704 MARGIN_LEFT=+12
705 MARGIN_RIGHT=-12
706 MARGIN_TOP=+7
707 MARGIN_BOTTOM=-7
709 time_elapsed=0
711 def __init__(self, stage, pos,dx,dy):
713 qweSprite.__init__(self,stage)
714 self.image1 = pygame.image.load('hacha1.png')
715 if dx<0: self.image1=pygame.transform.flip(self.image1, True, False)
716 self.image = self.image1.copy()
717 self.rect = self.image.get_rect()
719 self.rect.topleft = pos
720 self.dx=dx
721 self.dy=dy
722 self.x,self.y,self.w,self.h=self.rect
725 def draw(self,screen,lr=None):
726 self.fcountrot+=1
727 if self.Life>0 and self.fcountrot>5/self.Life:
728 self.image=pygame.transform.rotate(self.image1, self.angle)
729 if self.dx>0:
730 self.angle-=90
731 else:
732 self.angle+=90
733 self.fcountrot=0
734 if self.Life>2 or self.Life<.5:
735 self.SOLID=False
736 else:
737 self.SOLID=False
739 qweShoot.draw(self,screen,lr)
741 def tickms(self, ms, stage):
742 if self.Life>2:
743 self.dx*=1.01
744 self.dy*=1.01
745 self.time_elapsed+=ms
746 if self.time_elapsed<50:
747 self.FSOLID=False
748 else:
749 self.FSOLID=True
751 v=qweSprite.tickms(self, ms, stage)
752 return v
754 def collision(self,stage,x,y,char):
755 if self.ItemTime>0: return
756 qweShoot.collision(self,stage,x,y,char)
758 if char=='B' and x>self.psx and self.dx>0 \
759 and stage.getCh(x+1,y)==' ': # and stage.getCh(x+1,y+1)!=' ':
760 self.Life-=1
761 self.ItemTime=1000
763 testrect=pygame.Rect((x+1)*32,(y)*32,32,32)
764 put_in_place=True
765 for sprite in stage.sprites:
766 if sprite.FSOLID and sprite.rect.colliderect(testrect):
767 put_in_place=False
769 if put_in_place:
770 stage.setCh(x,y,' ')
771 stage.setCh(x+1,y,'B')
773 if char=='B' and x<self.psx and self.dx<0 \
774 and stage.getCh(x-1,y)==' ': # and stage.getCh(x-1,y+1)!=' ':
775 self.Life-=1
776 self.ItemTime=1000
778 testrect=pygame.Rect((x-1)*32,(y)*32,32,32)
779 put_in_place=True
780 for sprite in stage.sprites:
781 if sprite.FSOLID and sprite.rect.colliderect(testrect):
782 put_in_place=False
784 if put_in_place:
785 stage.setCh(x,y,' ')
786 stage.setCh(x-1,y,'B')
789 class Life(qweShoot):
790 FRICTION_AIR=(10.0,10.0)
791 BOUNCE=-.8
792 ShowLife=MaxLife=Life=10
793 LifeCollisionCost=0
794 LifeCollisionSpriteCost=-10
796 GRAVITY=1
797 SOLID=False
798 FSOLID=False
800 RADIUS=0
802 MARGIN_LEFT=+4
803 MARGIN_RIGHT=-4
804 MARGIN_TOP=+4
805 MARGIN_BOTTOM=-4
807 def __init__(self, stage, pos,imgfile, life):
809 qweSprite.__init__(self,stage)
811 self.image1 = pygame.image.load(imgfile)
812 self.image = self.image1.copy()
813 self.rect = self.image.get_rect()
814 self.ShowLife=self.MaxLife=self.Life=life
816 self.rect.topleft = pos
817 self.dx=0
818 self.dy=-20
819 self.x,self.y,self.w,self.h=self.rect
820 self.tickms(5,stage);
822 def tickms(self, ms, stage):
823 if self.RADIUS<16:
824 self.RADIUS+=ms/5000.0
826 v=qweSprite.tickms(self, ms, stage)
827 if self.psx<0: self.move(8,0)
828 if self.psx>=20: self.move(-8,0)
830 if self.psy<0: self.move(0,8)
831 if self.psy>=15: self.move(0,-8)
832 return v