6 class qweSprite(pygame
.sprite
.Sprite
):
11 FRICTION_AIR
=(0.2,0.2)
18 def __init__(self
, stage
):
19 pygame
.sprite
.Sprite
.__init
__(self
)
25 self
.rect
=self
.x
,self
.y
,self
.w
,self
.h
27 def selectImage(self
):
30 def draw(self
,screen
):
31 screen
.blit(self
.selectImage(), self
.rect
)
33 def tickms(self
, ms
, stage
):
34 rect1
=pygame
.Rect(self
.rect
)
36 self
.checkpos(stage
,ms
)
37 self
.move(self
.dx
*ms
/1000.0,self
.dy
*ms
/1000.0)
38 self
.dx
/=1+self
.FRICTION_AIR
[0]*ms
/1000.0
39 self
.dy
/=1+self
.FRICTION_AIR
[1]*ms
/1000.0
43 return [rect1
.union(rect2
)]
46 def checkcell(self
,stage
,px
,py
):
49 Pantalla
=stage
.StageData
62 if y0
<0 and x0
>=0 and x0
<len(Pantalla
[0]): return ' '
63 if y0
>=0 and y0
<len(Pantalla
):
64 if x0
>=0 and x0
<len(Pantalla
[y0
]):
65 return Pantalla
[y0
][x0
]
69 def checkpos(self
,stage
,ms
):
71 if ( (self
.checkcell(stage
,-6,0)!=' ' and self
.dx
>=0) or
72 (self
.checkcell(stage
,-9,12)!=' ' and self
.dx
>=0) or
73 (self
.checkcell(stage
,-9,-12)!=' ' and self
.dx
>=0) ) :
74 self
.move(-self
.dx
*ms
/1000.0-.1,0)
75 if (self
.BOUNCE
>0): self
.dx
*=-self
.BOUNCE
76 else: self
.dx
/=1-self
.BOUNCE
78 if ( (self
.checkcell(stage
,+6,0)!=' ' and self
.dx
<=0) or
79 (self
.checkcell(stage
,+9,12)!=' ' and self
.dx
<=0) or
80 (self
.checkcell(stage
,+9,-12)!=' ' and self
.dx
<=0) ) :
81 self
.move(-self
.dx
*ms
/1000.0+.1,0)
82 if (self
.BOUNCE
>0): self
.dx
*=-self
.BOUNCE
83 else: self
.dx
/=1-self
.BOUNCE
85 #if ( (self.checkcell(stage,-4,0)!=' ' and self.dx>0) or
86 # (self.checkcell(stage,+4,0)!=' ' and self.dx<0) ) :
87 # self.dx/=1+5*ms/1000.0
90 # Control de hundimiento
92 if (self
.checkcell(stage
,+12,-3)!=' '
93 or self
.checkcell(stage
,-12,-3)!=' '):
97 elif self
.checkcell(stage
,0,+1)!=' ' and self
.dy
<0:
98 self
.move(0,-self
.dy
*ms
/1000.0)
99 if (self
.BOUNCE
>0): self
.dy
*=-self
.BOUNCE
100 else: self
.dy
/=1-self
.BOUNCE
101 self
.dx
/=1+self
.FRICTION_CEIL
[0]*ms
/1000.0
102 self
.dy
/=1+self
.FRICTION_CEIL
[1]*ms
/1000.0
103 if self
.checkcell(stage
,0,+2)!=' ' and self
.dy
<0:
104 self
.dx
/=1+self
.FRICTION_CEIL
[0]*ms
/1000.0
105 self
.dy
/=1+self
.FRICTION_CEIL
[1]*ms
/1000.0
106 if self
.checkcell(stage
,0,+3)!=' ' and self
.dy
<0:
112 if (self
.checkcell(stage
,+10,-1)==' '
113 and self
.checkcell(stage
,-10,-1)==' '):
114 self
.dy
+=self
.GRAVITY
118 if (self
.checkcell(stage
,+10,-2)!=' '
119 or self
.checkcell(stage
,-10,-2)!=' '):
120 self
.dx
/=1+self
.FRICTION_FLOOR
[0]*ms
/1000.0
122 if (self
.BOUNCE
>0): self
.dy
*=-self
.BOUNCE
123 else: self
.dy
/=1-self
.BOUNCE
124 self
.dy
/=1+self
.FRICTION_FLOOR
[1]*ms
/1000.0
125 self
.move(0,-self
.dy
*ms
/1000.0)
133 class Tajundra(qweSprite
):
138 def __init__(self
, stage
):
140 qweSprite
.__init
__(self
,stage
)
141 self
.image_right
= pygame
.image
.load('tajuA1.png')
142 self
.image_left
=pygame
.transform
.flip(self
.image_right
,True,False)
144 self
.imageb_right
= pygame
.image
.load('tajuA2.png')
145 self
.imageb_left
=pygame
.transform
.flip(self
.imageb_right
,True,False)
148 self
.image
=self
.image_right
149 self
.rect
= self
.image
.get_rect()
150 pos
=stage
.simbolos
['@'][0]
151 del stage
.simbolos
['@'][0]
152 self
.rect
.bottomright
= pos
153 self
.rect
=self
.rect
.move(stage
.BlockSize
)
154 self
.x
,self
.y
,self
.w
,self
.h
=self
.rect
156 def selectImage(self
):
160 self
.image
=self
.image_left
162 self
.image
=self
.image_right
165 self
.image
=self
.imageb_left
167 self
.image
=self
.imageb_right
169 if self
.estado_ms
>20:
181 class Dragon(qweSprite
):
186 def __init__(self
, stage
):
188 qweSprite
.__init
__(self
,stage
)
189 self
.image_left
= pygame
.image
.load('dragonN1.png')
190 self
.image_right
=pygame
.transform
.flip(self
.image_left
,True,False)
192 self
.imageb_left
= pygame
.image
.load('dragonN2.png')
193 self
.imageb_right
=pygame
.transform
.flip(self
.imageb_left
,True,False)
196 self
.image
=self
.image_right
197 self
.rect
= self
.image
.get_rect()
198 pos
=stage
.simbolos
['$'][0]
199 del stage
.simbolos
['$'][0]
201 self
.rect
.bottomright
= pos
202 self
.rect
=self
.rect
.move(stage
.BlockSize
)
203 self
.x
,self
.y
,self
.w
,self
.h
=self
.rect
205 def selectImage(self
):
209 self
.image
=self
.image_left
211 self
.image
=self
.image_right
214 self
.image
=self
.imageb_left
216 self
.image
=self
.imageb_right
218 if self
.estado_ms
>20:
228 class qweShoot(qweSprite
):
231 FRICTION_AIR
=(1.0,0.0)
232 FRICTION_FLOOR
=(0.0,0.0)
233 FRICTION_CEIL
=(0.0,0.0)
239 def __init__(self
, stage
, pos
,dx
,dy
):
241 qweSprite
.__init
__(self
,stage
)
242 self
.image
= pygame
.image
.load('hacha1.png')
243 if dx
<0: self
.image
=pygame
.transform
.flip(self
.image
, True, False)
245 self
.rect
= self
.image
.get_rect()
247 self
.rect
.topleft
= pos
250 self
.x
,self
.y
,self
.w
,self
.h
=self
.rect
252 def tickms(self
, ms
, stage
):
254 if (self
.Life
<0): self
.alive
=False
255 else: self
.Life
-=ms
/1000.0
256 return qweSprite
.tickms(self
, ms
, stage
)
258 def draw(self
,screen
):
260 if self
.fcount
>10/(self
.Life
+1):
262 screen
.blit(self
.selectImage(), self
.rect
)
265 class Hacha(qweShoot
):
266 FRICTION_AIR
=(1.0,0.0)
272 def __init__(self
, stage
, pos
,dx
,dy
):
274 qweSprite
.__init
__(self
,stage
)
275 self
.image1
= pygame
.image
.load('hacha1.png')
276 self
.image
= self
.image1
.copy()
277 self
.rect
= self
.image
.get_rect()
279 self
.rect
.topleft
= pos
282 self
.x
,self
.y
,self
.w
,self
.h
=self
.rect
284 def draw(self
,screen
):
286 if self
.fcountrot
>5/self
.Life
:
287 self
.image
=pygame
.transform
.rotate(self
.image1
, self
.angle
)
290 qweShoot
.draw(self
,screen
)