[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pygame] Tile Based games
Peter, Thanks a lot for the code, but it wasn't working so I changed it a
bit and now it is. I haven't seen how many fps I am getting but at least it
work now. I have changed some variables, so if you don't understand this
version send am e-mail to me that I can explain myself. How about comenting
this code and putting it in the code repository?
def drawtiles(self, tela, posx, posy):
telax, telay = tela.get_size()
tilex, tiley = (16,16)
offsetx, offsety = posx % tilex, posy % tiley
startx, starty = posx / tilex , posy / tiley
for y in range(telay / tiley + 2): # sometimes you need one more
tile (ie: 600/16=37.5) and it is screeny/tiley not the other way.
mapy = y + starty
pixely = (y - 1) * tiley - offsety #it is tiley - offsety not +
for x in range(telax / tilex + 2):
mapx = x + startx
pixelx = (x - 1) * tilex - offsetx
if (mapx >= self.mapdata.shape[0])or (mapx < 0) or (mapy >=
self.mapdata.shape[0])or(mapy < 0):
r = Rect(pixelx, pixely, tilex, tiley)
tela.fill((255, 0, 0), r)
else: #inside of the map
tela.blit(self.tiles[self.mapdata[mapx,mapy]],(pixelx,pixely))
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org