Mejoras a la gestiĆ³n de los objetos de pantalla
[tajundrathegame.git] / qwesprites.py
blobb3faec83f22008fd6762aaaaea4b472dd285205b
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 return []
113 rect1=pygame.Rect(self.rect)
114 d=math.sqrt(self.dx*self.dx+self.dy*self.dy)
115 self.accum_ms+=ms
116 #self.accum_dist+=d*self.accum_ms
117 if self.ShowLife>self.Life:
118 self.accum_dist+=(self.ShowLife-self.Life)
120 if self.Life<1:
121 self.accum_dist+=10/(self.Life+0.1)
123 if self.accum_ms>self.MAX_ACCUMMS or \
124 self.accum_dist+d*self.accum_ms>self.MAX_ACCUMDIST:
125 ms=self.accum_ms
126 self.accum_ms=0
127 self.accum_dist=0
129 if (self.ItemTime>0):
130 self.ItemTime-=ms
131 else:
132 self.ItemTime=0
134 if (self.Life<0):
135 self.alive=False
136 self.die(stage)
137 else:
138 if (self.REGEN<0 or self.Life<self.MaxLife):
139 self.Life+=self.REGEN*ms/1000.0
141 if self.ShowLife>self.Life:
142 self.ShowLife-=ms/100.0
143 if self.ShowLife<self.Life:
144 self.ShowLife=self.Life
145 factor=1
146 if d*self.accum_ms>1000: factor=d*self.accum_ms/1000.0
147 while(ms>0):
148 iter_ms=ms
149 if (iter_ms>self.MAX_ITERMS/factor): iter_ms=self.MAX_ITERMS/factor
151 self.checkpos(stage,iter_ms)
152 self.move(self.dx*iter_ms/1000.0,self.dy*iter_ms/1000.0)
153 self.dx/=1+self.FRICTION_AIR[0]*iter_ms/1000.0
154 self.dy/=1+self.FRICTION_AIR[1]*iter_ms/1000.0
155 ms-=iter_ms
157 rect2=self.rect
158 self.psx,self.psy=self.getpspoint(stage,0,0);
160 return [rect1.union(rect2)]
161 else:
162 return []
165 def getpspoint(self,stage,px,py):
166 sx,sy=stage.BlockSize
167 x,y,w,h=self.rect
169 if px>0: x0=x+px
170 elif px<0: x0=x+w+px
171 else: x0=x+w/2
173 if py>0: y0=y+py
174 elif py<0: y0=y+h+py
175 else: y0=y+h/2
177 x0=int(x0)/sx
178 y0=int(y0)/sy
180 return (x0,y0)
182 def collision(self,stage,x,y,char):
183 if self.ItemTime==0:
184 Pantalla=stage.StageData
186 if char=='P':
187 self.alive=False
188 self.LevelFinished=True
190 if not self.Item:
191 if char=='z':
192 self.Item=char
193 self.ItemTime=1000
194 stage.setCh(x,y,' ')
195 stage.checkPortal()
196 else:
197 if char=='Z' and self.Item=='z' and stage.getCh(x,y-1)==' ':
198 testrect=pygame.Rect(x*32+8,(y-1)*32+8,16,16)
200 put_in_place=True
201 for sprite in stage.sprites:
202 if sprite.FSOLID and sprite.rect.colliderect(testrect):
203 put_in_place=False
205 if put_in_place:
206 stage.setCh(x,y-1,'z')
207 stage.checkPortal()
208 self.ItemTime=1000
209 self.Item=''
212 def checkcell(self,stage,px,py):
213 Pantalla=stage.StageData
215 x0,y0=self.getpspoint(stage,px,py);
217 if y0<0 and x0>=0 and x0<len(Pantalla[0]): return ' '
218 if y0>=0 and y0<len(Pantalla):
219 if x0>=0 and x0<len(Pantalla[y0]):
220 ch=Pantalla[y0][x0]
221 self.collision(stage,x0,y0,ch)
223 return ch
225 return 't'
227 def checkpos(self,stage,ms):
228 self.in_ground=False
230 if self.Life<1:
231 MAX_ACCUMMS=1
232 self.REGEN=-1
233 if self.Life>0.5:
234 for sprite in stage.sprites:
235 if sprite!=self and sprite.RADIUS>0 and sprite.Life>0.5:
236 if ( math.fabs(sprite.psx-self.psx)<=1
237 and math.fabs(sprite.psy-self.psy)<=1):
238 x,y,w,h=self.rect
239 sx,sy,sw,sh=sprite.rect
241 min_d=self.RADIUS+sprite.RADIUS
243 ax=x-sx;ay=y-sy;
244 d1=math.sqrt(ax*ax+ay*ay)
245 if d1<min_d:
246 x+=self.dx/1000.0
247 y+=self.dy/1000.0
248 sx+=sprite.dx/1000.0
249 sy+=sprite.dy/1000.0
251 ax=x-sx;ay=y-sy;
252 d2=math.sqrt(ax*ax+ay*ay)
253 if d2<=d1:
254 sdx=sprite.dx
255 sdy=sprite.dy
256 if sprite.SOLID and self.FSOLID:
257 sprite.dx=self.dx
258 sprite.dy=self.dy
260 if self.SOLID and sprite.FSOLID:
261 self.dx=sdx
262 self.dy=sdy
264 if self.Life<900:
265 self.Life-=sprite.LifeCollisionSpriteCost
266 if self.Life<0.5: self.Life=0.5
267 if self.ShowLife>0:
268 self.ShowLife=self.Life+10
270 if sprite.Life<900:
271 sprite.Life-=self.LifeCollisionSpriteCost
272 if sprite.Life<0.5:
273 sprite.Life=0.5
274 if sprite.ShowLife>0:
275 sprite.ShowLife=sprite.Life+10
278 if d2<=d1+0.1:
279 self.in_ground=True
280 x,y,w,h=self.rect
281 ax=x-sx;ay=y-sy;
282 d1=math.sqrt(ax*ax+ay*ay)+1
283 if self.SOLID and sprite.FSOLID:
284 self.dx+=20*ax/d1
285 self.dy+=20*ay/d1
287 if sprite.SOLID and self.FSOLID:
288 sprite.dx-=20*ax/d1
289 sprite.dy-=20*ay/d1
293 # ColisiĆ³n Horizontal
294 if ( (self.checkcell(stage,self.MARGIN_RIGHT,0)!=' ' and self.dx>=0) or
295 (self.checkcell(stage,self.MARGIN_RIGHT,12)!=' ' and self.dx>=0) or
296 (self.checkcell(stage,self.MARGIN_RIGHT,-12)!=' ' and self.dx>=0) ) :
297 if self.Life<900: self.Life-=self.LifeCollisionCost
298 self.move(-self.dx*ms/1000.0-.1,0)
299 if (self.BOUNCE>0): self.dx*=-self.BOUNCE
300 else: self.dx/=1-self.BOUNCE
302 if ( (self.checkcell(stage,self.MARGIN_LEFT,0)!=' ' and self.dx<=0) or
303 (self.checkcell(stage,self.MARGIN_LEFT,12)!=' ' and self.dx<=0) or
304 (self.checkcell(stage,self.MARGIN_LEFT,-12)!=' ' and self.dx<=0) ) :
305 if self.Life<900: self.Life-=self.LifeCollisionCost
306 self.move(-self.dx*ms/1000.0+.1,0)
307 if (self.BOUNCE>0): self.dx*=-self.BOUNCE
308 else: self.dx/=1-self.BOUNCE
310 if ( (self.checkcell(stage,self.MARGIN_RIGHT-3,0)!=' ') and
311 (self.checkcell(stage,self.MARGIN_RIGHT-3,12)!=' ') and
312 (self.checkcell(stage,self.MARGIN_RIGHT-3,-12)!=' ') ) :
313 self.move(-3,0)
315 if ( (self.checkcell(stage,self.MARGIN_LEFT+3,0)!=' ') and
316 (self.checkcell(stage,self.MARGIN_LEFT+3,12)!=' ') and
317 (self.checkcell(stage,self.MARGIN_LEFT+3,-12)!=' ') ) :
318 self.move(+3,0)
321 # Control de hundimiento
322 if self.dy>=0:
323 if (self.checkcell(stage,self.MARGIN_LEFT+4,self.MARGIN_BOTTOM-1)!=' '
324 or self.checkcell(stage,self.MARGIN_RIGHT-4,self.MARGIN_BOTTOM-1)!=' ') and \
325 (self.checkcell(stage,self.MARGIN_LEFT+4,self.MARGIN_TOP+1)==' '
326 and self.checkcell(stage,self.MARGIN_RIGHT-4,self.MARGIN_TOP+1)==' '):
327 self.move(0,-1)
328 self.dy=0
330 if (self.checkcell(stage,0,0)!=' '):
331 self.move(0,-1)
332 self.dy=0
333 # ColisiĆ³n de techo
334 elif self.dy<0:
335 if (self.checkcell(stage,self.MARGIN_LEFT+4,self.MARGIN_TOP)!=' ' or
336 self.checkcell(stage,self.MARGIN_RIGHT-4,self.MARGIN_TOP)!=' ' or
337 self.checkcell(stage,0,self.MARGIN_TOP)!=' '):
339 if self.Life<900: self.Life-=self.LifeCollisionCost
340 self.move(0,-self.dy*ms/1000.0)
341 if (self.BOUNCE>0): self.dy*=-self.BOUNCE
342 else: self.dy/=1-self.BOUNCE
343 self.dx/=1+self.FRICTION_CEIL[0]*ms/1000.0
344 self.dy/=1+self.FRICTION_CEIL[1]*ms/1000.0
345 if self.checkcell(stage,0,+2)!=' ' and self.dy<0:
346 self.dx/=1+self.FRICTION_CEIL[0]*ms/1000.0
347 self.dy/=1+self.FRICTION_CEIL[1]*ms/1000.0
348 if self.checkcell(stage,0,+3)!=' ' and self.dy<0:
349 self.dy=0
353 # ColisiĆ³n suelo
354 if ((self.checkcell(stage,self.MARGIN_LEFT+4,self.MARGIN_BOTTOM)!=' '
355 and self.checkcell(stage,0,self.MARGIN_BOTTOM)!=' ')
356 or (self.checkcell(stage,self.MARGIN_RIGHT-4,self.MARGIN_BOTTOM)!=' '
357 and self.checkcell(stage,0,self.MARGIN_BOTTOM)!=' ')
359 self.dx/=1+self.FRICTION_FLOOR[0]*ms/1000.0
360 if self.dy>0:
361 if self.Life<900: self.Life-=self.LifeCollisionCost
362 if (self.BOUNCE>0): self.dy*=-self.BOUNCE
363 else: self.dy/=1-self.BOUNCE
364 self.dy/=1+self.FRICTION_FLOOR[1]*ms/1000.0
365 self.move(0,-self.dy*ms/1000.0)
367 elif self.dy<0:
368 pass
370 self.in_ground=True
371 else:
372 # Gravedad
373 self.dy+=self.GRAVITY
375 if self.Life>self.MaxLife*1.5: self.Life=self.MaxLife*1.5
377 class qweText(qweSprite):
378 FONT=None
379 GRAVITY=0
380 SOLID=False
381 FSOLID=False
382 Life=1000
383 LifeCollisionSpriteCost=0
384 ShowLife=0
385 RADIUS=0
386 MAX_ACCUMMS=0
387 MAX_ACCUMDIST=0
389 def __init__(self, stage,x,y,txt,font,color):
391 qweSprite.__init__(self,stage)
392 self.FONT=font
394 self.image=font.render(txt, True, color)
396 self.rect = self.image.get_rect()
398 self.x,self.y,self.w,self.h=self.rect
399 self.x=x
400 self.y=y
402 def collision(self,stage,x,y,char):
403 return
405 def checkcell(self,stage,px,py):
406 return ' '
408 def checkpos(self,stage,ms):
409 return
412 global qweTextBasic_font
413 qweTextBasic_font=None
414 global qweTextBIG_font
415 qweTextBIG_font=None
417 class qweTextBasic(qweText):
418 def __init__(self, stage,x,y,txt):
419 global qweTextBasic_font
420 if not qweTextBasic_font:
421 qweTextBasic_font=pygame.font.Font(None,15)
423 color=(0,255,0)
424 self.Layer=2
425 qweText.__init__(self,stage,x,y,txt,qweTextBasic_font,color)
427 class qweTextBIG(qweText):
428 def __init__(self, stage,x,y,txt):
429 qweSprite.__init__(self,stage)
430 global qweTextBIG_font
431 if not qweTextBIG_font:
432 qweTextBIG_font=pygame.font.Font(None,64)
434 self.FONT=qweTextBIG_font
436 self.image1=qweTextBIG_font.render(txt, True, (0,0,0))
437 self.image2=qweTextBIG_font.render(txt, True, (255,255,255))
438 w,h = self.image1.get_size()
439 w+=5
440 h+=5
441 self.image=pygame.Surface((w,h),pygame.SRCALPHA).convert_alpha()
442 self.image.fill((0,0,0,0))
443 self.image.blit(self.image1,(5,5))
444 self.image.blit(self.image2,(0,0))
447 self.rect = self.image.get_rect()
449 self.x,self.y,self.w,self.h=self.rect
450 self.x=x-w/2
451 self.y=y-h/2
454 class Tajundra(qweSprite):
455 image_flip=None
456 estado=0
457 estado_ms=0
458 MARGIN_LEFT=+8
459 MARGIN_RIGHT=-8
460 MARGIN_TOP=+1
461 MARGIN_BOTTOM=-1
462 RADIUS=10
463 BOUNCE=0
464 Item=None
465 DIE_IMG='platano.png'
466 MAX_ACCUMMS=50
467 MAX_ACCUMDIST=250
468 REGEN=-1
470 def __init__(self, stage):
472 qweSprite.__init__(self,stage)
473 self.image_right = pygame.image.load('tajuA1.png')
474 self.image_left=pygame.transform.flip(self.image_right,True,False)
476 self.imageb_right = pygame.image.load('tajuA2.png')
477 self.imageb_left=pygame.transform.flip(self.imageb_right,True,False)
480 self.image=self.image_right
481 self.rect = self.image.get_rect()
482 pos=stage.simbolos['@'][0]
483 del stage.simbolos['@'][0]
484 self.rect.bottomright = pos
485 self.rect=self.rect.move(stage.BlockSize)
486 self.x,self.y,self.w,self.h=self.rect
488 def selectImage(self):
489 dx=self.dx
490 if self.estado==0:
491 if dx<0:
492 self.image=self.image_left
493 else:
494 self.image=self.image_right
495 else:
496 if dx<0:
497 self.image=self.imageb_left
498 else:
499 self.image=self.imageb_right
500 self.estado_ms+=1
501 if self.estado_ms>20:
502 self.estado_ms=0
503 if self.estado==0:
504 self.estado=1
505 else:
506 self.estado=0
507 return self.image
513 class Dragon(qweSprite):
514 image_flip=None
515 estado=0
516 estado_ms=0
517 MAX_ACCUMMS=500
518 MAX_ACCUMDIST=100
519 BOUNCE=-.1
521 def __init__(self, stage):
523 qweSprite.__init__(self,stage)
524 self.image_left = pygame.image.load('dragonN1.png')
525 self.image_right=pygame.transform.flip(self.image_left,True,False)
527 self.imageb_left = pygame.image.load('dragonN2.png')
528 self.imageb_right=pygame.transform.flip(self.imageb_left,True,False)
531 self.image=self.image_right
532 self.rect = self.image.get_rect()
533 pos=stage.simbolos['$'][0]
534 del stage.simbolos['$'][0]
536 self.rect.bottomright = pos
537 self.rect=self.rect.move(stage.BlockSize)
538 self.x,self.y,self.w,self.h=self.rect
540 def selectImage(self):
541 dx=self.dx
542 if self.estado==0:
543 if dx<0:
544 self.image=self.image_left
545 else:
546 self.image=self.image_right
547 else:
548 if dx<0:
549 self.image=self.imageb_left
550 else:
551 self.image=self.imageb_right
552 self.estado_ms+=1
553 if self.estado_ms>20:
554 self.estado_ms=0
555 if self.estado==0:
556 self.estado=1
557 else:
558 self.estado=0
559 return self.image
563 class LanzaBolas(qweSprite):
564 image_flip=None
565 MAX_ACCUMMS=500
566 MAX_ACCUMDIST=100
567 BOUNCE=.2
569 estado=0
570 estado_ms=0
571 BOUNCE=0
572 DIE_IMG='safanoria.png'
573 def __init__(self, stage):
575 qweSprite.__init__(self,stage)
576 self.image = pygame.image.load('lanzabolas1.png')
578 self.rect = self.image.get_rect()
579 pos=stage.simbolos['|'][0]
580 del stage.simbolos['|'][0]
582 self.rect.bottomright = pos
583 self.rect=self.rect.move(stage.BlockSize)
584 self.x,self.y,self.w,self.h=self.rect
585 self.estado_ms=random.randint(6000,12000)
587 def selectImage(self):
588 return self.image
590 def tickms(self, ms, stage):
592 v=qweSprite.tickms(self, ms, stage)
593 self.estado_ms+=ms
594 if self.estado_ms>10000 and self.Life>10:
595 random.seed()
596 self.estado_ms=random.randint(0,1000)
597 r=random.randint(-1000,1000)/3.0
598 disparo=Bola(stage,(int(self.x),int(self.y)),r,-200)
599 disparo.move(0,-10)
600 disparo.GRAVITY=1
602 return v
606 class qweShoot(qweSprite):
607 estado=0
608 estado_ms=0
609 FRICTION_AIR=(0.0,0.0)
610 FRICTION_FLOOR=(0.0,0.0)
611 FRICTION_CEIL=(0.0,0.0)
612 GRAVITY=0
613 BOUNCE=.5
614 MaxLife=Life=2.0
615 ShowLife=0
616 LifeCollisionCost=1
617 LifeCollisionSpriteCost=10
618 REGEN=-1
620 fcount=0
621 accum_ms=0
623 MARGIN_LEFT=+10
624 MARGIN_RIGHT=-10
625 MARGIN_TOP=+10
626 MARGIN_BOTTOM=-10
628 def __init__(self, stage, pos,dx,dy):
630 qweSprite.__init__(self,stage)
631 self.image = pygame.image.load('bola1.png')
633 self.rect = self.image.get_rect()
635 self.rect.topleft = pos
636 self.dx=dx
637 self.dy=dy
638 self.x,self.y,self.w,self.h=self.rect
639 d=math.sqrt(dx*dx+dy*dy)+5
640 self.tickms(1000/d,stage);
642 def collision(self,stage,x,y,char):
643 qweSprite.collision(self,stage,x,y,char)
644 if self.ItemTime==0:
645 nchar=char
647 if char=='M': nchar='N'
648 if char=='N': nchar='m'
649 if char=='m': nchar='n'
650 if char=='n': nchar=' '
652 if char!=nchar:
653 stage.setCh(x,y,nchar)
654 self.Life-=1
655 self.ItemTime=1000
659 def die(self,screen):
660 pass
662 class Bola(qweShoot):
663 GRAVITY=20
664 BOUNCE=.5
665 MaxLife=Life=12.0
666 LifeCollisionCost=1
667 RADIUS=5
668 MAX_ACCUMMS=5000
669 MAX_ACCUMDIST=1000
671 class Hacha(qweShoot):
672 FRICTION_AIR=(0.5,0.0)
673 BOUNCE=.8
674 MaxLife=60
675 Life=2
676 LifeCollisionCost=0.1
677 LifeCollisionSpriteCost=10
678 fcountrot=0
679 angle=0
680 GRAVITY=5
681 RADIUS=10
683 MARGIN_LEFT=+12
684 MARGIN_RIGHT=-12
685 MARGIN_TOP=+7
686 MARGIN_BOTTOM=-7
688 time_elapsed=0
690 def __init__(self, stage, pos,dx,dy):
692 qweSprite.__init__(self,stage)
693 self.image1 = pygame.image.load('hacha1.png')
694 if dx<0: self.image1=pygame.transform.flip(self.image1, True, False)
695 self.image = self.image1.copy()
696 self.rect = self.image.get_rect()
698 self.rect.topleft = pos
699 self.dx=dx
700 self.dy=dy
701 self.x,self.y,self.w,self.h=self.rect
704 def draw(self,screen,lr=None):
705 self.fcountrot+=1
706 if self.Life>0 and self.fcountrot>5/self.Life:
707 self.image=pygame.transform.rotate(self.image1, self.angle)
708 if self.dx>0:
709 self.angle-=90
710 else:
711 self.angle+=90
712 self.fcountrot=0
713 if self.Life>2 or self.Life<.5:
714 self.SOLID=False
715 else:
716 self.SOLID=False
718 qweShoot.draw(self,screen,lr)
720 def tickms(self, ms, stage):
721 if self.Life>2:
722 self.dx*=1.01
723 self.dy*=1.01
724 self.time_elapsed+=ms
725 if self.time_elapsed<50:
726 self.FSOLID=False
727 else:
728 self.FSOLID=True
730 v=qweSprite.tickms(self, ms, stage)
731 return v
733 def collision(self,stage,x,y,char):
734 if self.ItemTime>0: return
735 qweShoot.collision(self,stage,x,y,char)
737 if char=='B' and x>self.psx and self.dx>0 \
738 and stage.getCh(x+1,y)==' ': # and stage.getCh(x+1,y+1)!=' ':
739 self.Life-=1
740 self.ItemTime=1000
742 testrect=pygame.Rect((x+1)*32,(y)*32,32,32)
743 put_in_place=True
744 for sprite in stage.sprites:
745 if sprite.FSOLID and sprite.rect.colliderect(testrect):
746 put_in_place=False
748 if put_in_place:
749 stage.setCh(x,y,' ')
750 stage.setCh(x+1,y,'B')
752 if char=='B' and x<self.psx and self.dx<0 \
753 and stage.getCh(x-1,y)==' ': # and stage.getCh(x-1,y+1)!=' ':
754 self.Life-=1
755 self.ItemTime=1000
757 testrect=pygame.Rect((x-1)*32,(y)*32,32,32)
758 put_in_place=True
759 for sprite in stage.sprites:
760 if sprite.FSOLID and sprite.rect.colliderect(testrect):
761 put_in_place=False
763 if put_in_place:
764 stage.setCh(x,y,' ')
765 stage.setCh(x-1,y,'B')
768 class Life(qweShoot):
769 FRICTION_AIR=(10.0,10.0)
770 BOUNCE=-.8
771 ShowLife=MaxLife=Life=10
772 LifeCollisionCost=0
773 LifeCollisionSpriteCost=-10
775 GRAVITY=1
776 SOLID=False
777 FSOLID=False
779 RADIUS=0
781 MARGIN_LEFT=+4
782 MARGIN_RIGHT=-4
783 MARGIN_TOP=+4
784 MARGIN_BOTTOM=-4
786 def __init__(self, stage, pos,imgfile, life):
788 qweSprite.__init__(self,stage)
790 self.image1 = pygame.image.load(imgfile)
791 self.image = self.image1.copy()
792 self.rect = self.image.get_rect()
793 self.ShowLife=self.MaxLife=self.Life=life
795 self.rect.topleft = pos
796 self.dx=0
797 self.dy=-20
798 self.x,self.y,self.w,self.h=self.rect
799 self.tickms(5,stage);
801 def tickms(self, ms, stage):
802 if self.RADIUS<16:
803 self.RADIUS+=ms/5000.0
805 v=qweSprite.tickms(self, ms, stage)
806 if self.psx<0: self.move(8,0)
807 if self.psx>=20: self.move(-8,0)
809 if self.psy<0: self.move(0,8)
810 if self.psy>=15: self.move(0,-8)
811 return v