8 class qweSprite(pygame
.sprite
.Sprite
):
13 FRICTION_AIR
=(0.2,0.2)
21 ShowLife
=MaxLife
=Life
=240
25 LifeCollisionSpriteCost
=2
34 def __init__(self
, stage
):
35 pygame
.sprite
.Sprite
.__init
__(self
)
42 self
.rect
=self
.x
,self
.y
,self
.w
,self
.h
44 def selectImage(self
):
48 Life(screen
,(int(self
.x
),int(self
.y
)),self
.DIE_IMG
,self
.MaxLife
)
51 def draw(self
,screen
):
53 if self
.fcount
>10/(self
.Life
+1):
55 screen
.blit(self
.selectImage(), self
.rect
)
56 if self
.ShowLife
>self
.Life
or (self
.Life
< 60 and self
.ShowLife
>0):
59 pp
=100.0*self
.ShowLife
/self
.MaxLife
60 pp
=pp
+math
.log(1+1.9*self
.ShowLife
/self
.MaxLife
)*100.0
81 pygame
.draw
.line(screen
, (255-p
,255,0) , p1a
, p2a
,1)
82 pygame
.draw
.line(screen
, (255-p
,255,0) , p1
, p2
,1)
84 pygame
.draw
.line(screen
, (255,p
,0) , p1
, p2
,1)
86 def tickms(self
, ms
, stage
):
89 rect1
=pygame
.Rect(self
.rect
)
97 if self
.ShowLife
>self
.Life
:
98 self
.ShowLife
-=ms
/100.0
99 if self
.ShowLife
<self
.Life
:
100 self
.ShowLife
=self
.Life
102 self
.checkpos(stage
,ms
)
103 self
.move(self
.dx
*ms
/1000.0,self
.dy
*ms
/1000.0)
104 self
.dx
/=1+self
.FRICTION_AIR
[0]*ms
/1000.0
105 self
.dy
/=1+self
.FRICTION_AIR
[1]*ms
/1000.0
108 self
.psx
,self
.psy
=self
.getpspoint(stage
,0,0);
110 return [rect1
.union(rect2
)]
113 def getpspoint(self
,stage
,px
,py
):
114 sx
,sy
=stage
.BlockSize
130 def checkcell(self
,stage
,px
,py
):
131 Pantalla
=stage
.StageData
133 x0
,y0
=self
.getpspoint(stage
,px
,py
);
135 if y0
<0 and x0
>=0 and x0
<len(Pantalla
[0]): return ' '
136 if y0
>=0 and y0
<len(Pantalla
):
137 if x0
>=0 and x0
<len(Pantalla
[y0
]):
138 return Pantalla
[y0
][x0
]
142 def checkpos(self
,stage
,ms
):
145 if self
.Life
<=0.5: return
146 for sprite
in stage
.sprites
:
147 if sprite
!=self
and sprite
.Life
>0.5:
148 if ( math
.fabs(sprite
.psx
-self
.psx
)<=1
149 and math
.fabs(sprite
.psy
-self
.psy
)<=1):
151 sx
,sy
,sw
,sh
=sprite
.rect
153 min_d
=self
.RADIUS
+sprite
.RADIUS
156 d1
=math
.sqrt(ax
*ax
+ay
*ay
)
164 d2
=math
.sqrt(ax
*ax
+ay
*ay
)
168 if sprite
.SOLID
and self
.FSOLID
:
172 if self
.SOLID
and sprite
.FSOLID
:
177 self
.Life
-=sprite
.LifeCollisionSpriteCost
179 self
.ShowLife
=self
.Life
+10
182 sprite
.Life
-=self
.LifeCollisionSpriteCost
183 if sprite
.ShowLife
>0:
184 sprite
.ShowLife
=sprite
.Life
+10
191 d1
=math
.sqrt(ax
*ax
+ay
*ay
)
192 if self
.SOLID
and sprite
.FSOLID
:
196 if sprite
.SOLID
and self
.FSOLID
:
202 # Colisión Horizontal
203 if ( (self
.checkcell(stage
,self
.MARGIN_RIGHT
,0)!=' ' and self
.dx
>=0) or
204 (self
.checkcell(stage
,self
.MARGIN_RIGHT
,12)!=' ' and self
.dx
>=0) or
205 (self
.checkcell(stage
,self
.MARGIN_RIGHT
,-12)!=' ' and self
.dx
>=0) ) :
206 if self
.Life
<900: self
.Life
-=self
.LifeCollisionCost
207 self
.move(-self
.dx
*ms
/1000.0-.1,0)
208 if (self
.BOUNCE
>0): self
.dx
*=-self
.BOUNCE
209 else: self
.dx
/=1-self
.BOUNCE
211 if ( (self
.checkcell(stage
,self
.MARGIN_LEFT
,0)!=' ' and self
.dx
<=0) or
212 (self
.checkcell(stage
,self
.MARGIN_LEFT
,12)!=' ' and self
.dx
<=0) or
213 (self
.checkcell(stage
,self
.MARGIN_LEFT
,-12)!=' ' and self
.dx
<=0) ) :
214 if self
.Life
<900: self
.Life
-=self
.LifeCollisionCost
215 self
.move(-self
.dx
*ms
/1000.0+.1,0)
216 if (self
.BOUNCE
>0): self
.dx
*=-self
.BOUNCE
217 else: self
.dx
/=1-self
.BOUNCE
219 #if ( (self.checkcell(stage,-4,0)!=' ' and self.dx>0) or
220 # (self.checkcell(stage,+4,0)!=' ' and self.dx<0) ) :
221 # self.dx/=1+5*ms/1000.0
224 # Control de hundimiento
226 if (self
.checkcell(stage
,self
.MARGIN_LEFT
+4,self
.MARGIN_BOTTOM
-1)!=' '
227 or self
.checkcell(stage
,self
.MARGIN_RIGHT
-4,self
.MARGIN_BOTTOM
-1)!=' '):
233 if (self
.checkcell(stage
,self
.MARGIN_LEFT
+4,self
.MARGIN_TOP
)!=' ' or
234 self
.checkcell(stage
,self
.MARGIN_RIGHT
-4,self
.MARGIN_TOP
)!=' ' or
235 self
.checkcell(stage
,0,self
.MARGIN_TOP
)!=' '):
237 if self
.Life
<900: self
.Life
-=self
.LifeCollisionCost
238 self
.move(0,-self
.dy
*ms
/1000.0)
239 if (self
.BOUNCE
>0): self
.dy
*=-self
.BOUNCE
240 else: self
.dy
/=1-self
.BOUNCE
241 self
.dx
/=1+self
.FRICTION_CEIL
[0]*ms
/1000.0
242 self
.dy
/=1+self
.FRICTION_CEIL
[1]*ms
/1000.0
243 if self
.checkcell(stage
,0,+2)!=' ' and self
.dy
<0:
244 self
.dx
/=1+self
.FRICTION_CEIL
[0]*ms
/1000.0
245 self
.dy
/=1+self
.FRICTION_CEIL
[1]*ms
/1000.0
246 if self
.checkcell(stage
,0,+3)!=' ' and self
.dy
<0:
252 if (self
.checkcell(stage
,self
.MARGIN_LEFT
+4,self
.MARGIN_BOTTOM
)!=' '
253 or self
.checkcell(stage
,self
.MARGIN_RIGHT
-4,self
.MARGIN_BOTTOM
)!=' '):
254 self
.dx
/=1+self
.FRICTION_FLOOR
[0]*ms
/1000.0
256 if self
.Life
<900: self
.Life
-=self
.LifeCollisionCost
257 if (self
.BOUNCE
>0): self
.dy
*=-self
.BOUNCE
258 else: self
.dy
/=1-self
.BOUNCE
259 self
.dy
/=1+self
.FRICTION_FLOOR
[1]*ms
/1000.0
260 self
.move(0,-self
.dy
*ms
/1000.0)
268 self
.dy
+=self
.GRAVITY
270 if self
.Life
<0.5: self
.Life
=0.5
271 if self
.Life
>self
.MaxLife
*1.5: self
.Life
=self
.MaxLife
*1.5
273 class Tajundra(qweSprite
):
282 DIE_IMG
='platano.png'
284 def __init__(self
, stage
):
286 qweSprite
.__init
__(self
,stage
)
287 self
.image_right
= pygame
.image
.load('tajuA1.png')
288 self
.image_left
=pygame
.transform
.flip(self
.image_right
,True,False)
290 self
.imageb_right
= pygame
.image
.load('tajuA2.png')
291 self
.imageb_left
=pygame
.transform
.flip(self
.imageb_right
,True,False)
294 self
.image
=self
.image_right
295 self
.rect
= self
.image
.get_rect()
296 pos
=stage
.simbolos
['@'][0]
297 del stage
.simbolos
['@'][0]
298 self
.rect
.bottomright
= pos
299 self
.rect
=self
.rect
.move(stage
.BlockSize
)
300 self
.x
,self
.y
,self
.w
,self
.h
=self
.rect
302 def selectImage(self
):
306 self
.image
=self
.image_left
308 self
.image
=self
.image_right
311 self
.image
=self
.imageb_left
313 self
.image
=self
.imageb_right
315 if self
.estado_ms
>20:
327 class Dragon(qweSprite
):
332 def __init__(self
, stage
):
334 qweSprite
.__init
__(self
,stage
)
335 self
.image_left
= pygame
.image
.load('dragonN1.png')
336 self
.image_right
=pygame
.transform
.flip(self
.image_left
,True,False)
338 self
.imageb_left
= pygame
.image
.load('dragonN2.png')
339 self
.imageb_right
=pygame
.transform
.flip(self
.imageb_left
,True,False)
342 self
.image
=self
.image_right
343 self
.rect
= self
.image
.get_rect()
344 pos
=stage
.simbolos
['$'][0]
345 del stage
.simbolos
['$'][0]
347 self
.rect
.bottomright
= pos
348 self
.rect
=self
.rect
.move(stage
.BlockSize
)
349 self
.x
,self
.y
,self
.w
,self
.h
=self
.rect
351 def selectImage(self
):
355 self
.image
=self
.image_left
357 self
.image
=self
.image_right
360 self
.image
=self
.imageb_left
362 self
.image
=self
.imageb_right
364 if self
.estado_ms
>20:
374 class LanzaBolas(qweSprite
):
379 DIE_IMG
='safanoria.png'
380 def __init__(self
, stage
):
382 qweSprite
.__init
__(self
,stage
)
383 self
.image
= pygame
.image
.load('lanzabolas1.png')
385 self
.rect
= self
.image
.get_rect()
386 pos
=stage
.simbolos
['|'][0]
387 del stage
.simbolos
['|'][0]
389 self
.rect
.bottomright
= pos
390 self
.rect
=self
.rect
.move(stage
.BlockSize
)
391 self
.x
,self
.y
,self
.w
,self
.h
=self
.rect
392 self
.estado_ms
=random
.randint(0,12000)
394 def selectImage(self
):
397 def tickms(self
, ms
, stage
):
398 v
=qweSprite
.tickms(self
, ms
, stage
)
400 if self
.estado_ms
>10000:
402 self
.estado_ms
=random
.randint(0,1000)
403 r
=random
.randint(-1000,1000)/3.0
404 disparo
=Bola(stage
,(int(self
.x
),int(self
.y
)),r
,-200)
412 class qweShoot(qweSprite
):
415 FRICTION_AIR
=(0.0,0.0)
416 FRICTION_FLOOR
=(0.0,0.0)
417 FRICTION_CEIL
=(0.0,0.0)
423 LifeCollisionSpriteCost
=10
433 def __init__(self
, stage
, pos
,dx
,dy
):
435 qweSprite
.__init
__(self
,stage
)
436 self
.image
= pygame
.image
.load('bola1.png')
438 self
.rect
= self
.image
.get_rect()
440 self
.rect
.topleft
= pos
443 self
.x
,self
.y
,self
.w
,self
.h
=self
.rect
444 self
.tickms(5,stage
);
446 def die(self
,screen
):
449 class Bola(qweShoot
):
456 class Hacha(qweShoot
):
457 FRICTION_AIR
=(0.5,0.0)
461 LifeCollisionCost
=0.1
472 def __init__(self
, stage
, pos
,dx
,dy
):
474 qweSprite
.__init
__(self
,stage
)
475 self
.image1
= pygame
.image
.load('hacha1.png')
476 if dx
<0: self
.image1
=pygame
.transform
.flip(self
.image1
, True, False)
477 self
.image
= self
.image1
.copy()
478 self
.rect
= self
.image
.get_rect()
480 self
.rect
.topleft
= pos
483 self
.x
,self
.y
,self
.w
,self
.h
=self
.rect
484 self
.tickms(15,stage
);
486 def draw(self
,screen
):
488 if self
.fcountrot
>5/self
.Life
:
489 self
.image
=pygame
.transform
.rotate(self
.image1
, self
.angle
)
500 qweShoot
.draw(self
,screen
)
502 def tickms(self
, ms
, stage
):
507 v
=qweSprite
.tickms(self
, ms
, stage
)
512 class Life(qweShoot
):
513 FRICTION_AIR
=(10.0,10.0)
515 ShowLife
=MaxLife
=Life
=10
517 LifeCollisionSpriteCost
=-2
530 def __init__(self
, stage
, pos
,imgfile
, life
):
532 qweSprite
.__init
__(self
,stage
)
534 self
.image1
= pygame
.image
.load(imgfile
)
535 self
.image
= self
.image1
.copy()
536 self
.rect
= self
.image
.get_rect()
537 self
.ShowLife
=self
.MaxLife
=self
.Life
=life
539 self
.rect
.topleft
= pos
542 self
.x
,self
.y
,self
.w
,self
.h
=self
.rect
543 self
.tickms(5,stage
);
545 def tickms(self
, ms
, stage
):
546 v
=qweSprite
.tickms(self
, ms
, stage
)
547 if self
.psx
<0: self
.move(8,0)
548 if self
.psx
>20: self
.move(-8,0)
550 if self
.psy
<0: self
.move(0,8)
551 if self
.psy
>15: self
.move(0,-8)