11 return "(char:%s, filename:%s, texture:%s)" % (self
.char
, self
.filename
,repr(self
.texture
))
20 listasimbolos
="!·$%&/()=|@#~"
32 def __init__(self
,fichero
):
33 self
.BlockSize
=(32,32)
39 self
.listasimbolos
="!·$%&/()=|@#~"
43 self
.Tajundra_life
=120
45 self
.background_sprites
=[]
52 if len(self
.StageData
)<=y
: return 't'
53 if y
>=0 and len(self
.StageData
[y
])<=x
: return 't'
55 return self
.StageData
[y
][x
]
56 def setCh(self
,x
,y
,ch
):
58 if len(self
.StageData
)<=y
: return
60 if len(self
.StageData
[y
])<=x
: return
61 if self
.StageData
[y
][x
]==ch
: return
62 self
.StageData
[y
][x
]=ch
64 x
*self
.BlockSize
[0],y
*self
.BlockSize
[1],
65 self
.BlockSize
[0],self
.BlockSize
[1]))
66 self
.rect_changed
+=[rect
]
69 def checkPortal(self
):
73 for line
in self
.StageData
:
76 if (ch
=='p' or ch
=='P'):
82 if (self
.StageData
[y
-1][x
]!='z'):
89 def checkMovingBlocks(self
):
93 for line
in self
.StageData
:
102 if self
.getCh(x
,y
+1)==' ':
103 testrect
=pygame
.Rect((x
)*32,(y
+1)*32,32,32)
105 for sprite
in self
.sprites
:
106 if sprite
.FSOLID
and sprite
.rect
.colliderect(testrect
):
108 sprite
.ShowLife
=sprite
.Life
113 self
.setCh(x
,y
+1,'B')
115 def do_stageChecks(self
):
117 self
.checkMovingBlocks()
120 def fulldraw(self
,screen
,msec
):
122 self
.check_stage_ms
+=msec
123 if self
.check_stage_ms
>200:
124 self
.check_stage_ms
=0
125 self
.do_stageChecks()
126 for rect
in self
.rect_changed
:
127 self
.draw(screen
,rect
,True)
129 v_rect
=self
.rect_changed
133 for sprite
in self
.sprites
:
134 v_rect
+=sprite
.tickms(msec
,self
)
140 for index
,rect
in enumerate(v_rect
):
141 if index
in delete_list
:
143 l
=rect
.collidelistall(v_rect
)
156 delete_list
=list(delete_list
)
159 for index
in reversed(delete_list
):
160 if index
<len(v_rect
):
164 self
.draw(screen
,rect
)
167 lensp
=len(self
.sprites
)-1
168 for key
,sprite
in enumerate(reversed(self
.sprites
)):
170 sprite
.draw(screen
,v_rect
)
172 del self
.sprites
[lensp
-key
]
175 pygame
.display
.update(rect
)
180 def draw(self
,screen
,rect
=None,redraw
=False):
183 self
.Surface
=screen
.copy()
188 rect
=self
.Surface
.get_rect()
191 if not self
.background
:
192 self
.background
= pygame
.image
.load("fondo1.png")
193 #self.Surface.fill((60,16,16))
194 #self.Surface.blit(self.background,(0,0))
197 for sprite
in self
.background_sprites
:
198 rect_seq
+=sprite
.tickms(10,self
)
200 for rect_1
in rect_seq
:
201 self
.Surface
.fill((60,16,16),rect_1
)
202 self
.Surface
.blit(self
.background
,rect_1
,rect_1
)
207 for line
in self
.StageData
:
210 rect_1
=pygame
.Rect(self
.Scroll
[0]+x
*self
.BlockSize
[0],
211 self
.Scroll
[1]+y
*self
.BlockSize
[1]
212 ,self
.BlockSize
[0],self
.BlockSize
[1])
213 if rect_1
.colliderect(rect
):
214 if ((ord(ch
)>=ord('A') and ord(ch
)<=ord('Z')) or
215 (ord(ch
)>=ord('a') and ord(ch
)<=ord('z'))):
216 tex
=self
.Texture
[ch
].texture
218 self
.Surface
.blit(tex
,rect_1
)
220 self
.Surface
.fill((60,16,16),rect_1
)
221 self
.Surface
.blit(self
.background
,rect_1
,rect_1
)
223 #screen.blit(self.Surface,rect_1,rect_1)
227 for sprite
in self
.background_sprites
:
228 sprite
.draw(self
.Surface
,[rect
])
230 screen
.blit(self
.Surface
,rect
,rect
)
233 screen
.blit(self
.Surface
,rect
,rect
)
236 def load(self
,fichero
):
237 print "Cargando pantalla %s ...." % fichero
238 self
.NextStage
=fichero
243 for s
in self
.listasimbolos
:
246 whitespace
=Stage_Texture();
248 self
.Texture
[' ']=whitespace
255 ex
=re
.search("%([\w]{4,64}) ([\S ]*)",line
)
260 self
.exec_stcommand(comando
,argumentos
,datos
)
266 argumentos
=ex1
[1].split(" ")
268 elif line
[0]=='[' and line
[-1]==']':
269 datos
+=[list(line
[1:-1])]
271 print "Error: Linea %d no se reconoce la secuencia '%s'" % (nlinea
,line
)
274 self
.exec_stcommand(comando
,argumentos
,datos
)
276 ################# VER POSICION SPRITES ##########
278 for line
in self
.StageData
:
281 if ((ord(ch
)>=ord('A') and ord(ch
)<=ord('Z')) or
282 (ord(ch
)>=ord('a') and ord(ch
)<=ord('z'))):
284 elif ord(ch
)>=ord('0') and ord(ch
)<=ord('9'):
286 elif ch
in self
.listasimbolos
:
287 self
.simbolos
[ch
] += [(x
*self
.BlockSize
[0],y
*self
.BlockSize
[1])]
288 self
.StageData
[y
][x
]=' '
292 qwesprites
.qweTextBasic(self
,2,2,self
.StageTitle
)
293 self
.Tajundra
=qwesprites
.Tajundra(self
)
294 self
.Tajundra
.MaxLife
=self
.Tajundra
.Life
=self
.Tajundra
.ShowLife
=self
.Tajundra_life
296 for c
in self
.Texture
:
300 tex
.texture
= pygame
.image
.load(tex
.filename
)
304 def exec_stcommand(self
,cmd
,arg
,data
):
306 self
.BlockSize
=(int(arg
[0]),int(arg
[1]))
311 self
.Texture
[arg
[0]]=tex
313 elif cmd
=='StageTitle':
314 self
.StageTitle
=" ".join(arg
)
315 elif cmd
=='StageData':
316 if len(data
)!=int(arg
[1]):
317 print "Error: No coincide el tamaño de datos Y (%d -> %d) en StageData" % (len(data
),int(arg
[1]))
320 if len(line
)!=int(arg
[0]):
321 print "Error: No coincide el tamaño de datos X (%d -> %d) en StageData" % (len(line
),int(arg
[0]))
325 elif cmd
=='PlaceText':
330 qwesprites
.qweTextBasic(self
,x
,y
,"".join(line
))
332 elif cmd
=='CreateTajundraWithLife':
333 self
.Tajundra_life
=int(arg
[0])
334 elif cmd
=='NextStage':
335 self
.NextStage
=arg
[0]
338 print "Error: Comando '%s' desconocido." % cmd