Link imagen del error: http://es.tinypic.com/r/ouxh68/9
Ese es el error que me sale.
Estoy empezando a hacer juegos con pygame, y para cargar el mapa y demás necesito la librería pytmx.
La descargué, y si pongo un código que no uso en le programa no me salta el error, pero si lo uso sí. Creo que no es del código, si no que algo funciona mal. Agradecería una ayuda.
Aquí dejo el código por si sirve de algo:
import pygame as pg
import sys
import pytmx
from pytmx.util_pygame import load_pygame
WIDTHWINDOW = 700
HEIGHTWINDOW = 500
SPRITEWIDTH = 30
SPRITEHEIGHT = 30
class Background(pg.sprite.Sprite):
def __init__(self, image_file, location):
pg.sprite.Sprite.__init__(self)
self.image = pg.image.load(image_file)
self.rect = self.image.get_rect()
self.rect.left, self.rect.top = location
class Player(pg.sprite.Sprite):
def __init__(self, location):
pg.sprite.Sprite.__init__(self)
#load images
self.imageDown1 = pg.image.load('./player/5.png')
self.imageDown2 = pg.image.load('./player/4.png')
self.imageUp1 = pg.image.load('./player/1.png')
self.imageUp2 = pg.image.load('./player/0.png')
self.imageRight1 = pg.image.load('./player/3.png')
self.imageRight2 = pg.image.load('./player/2.png')
self.imageLeft1 = pg.image.load('./player/6.png')
self.imageLeft2 = pg.image.load('./player/7.png')
#create a list of lists of the images
self.images = [[self.imageDown1,self.imageDown2],[self.imageUp1,self.imageUp2],[self.imageRight1,self.imageRight2],[self.imageLeft1,self.imageLeft2]]
#create orientation
self.orientation = 0
#actual image
self.actual_image = self.images[self.orientation][0]
#get rectangle of the image
self.rect = self.imageDown1.get_rect()
#set position of the image
self.rect.left, self.rect.top = location
def move(self, vx, vy):
self.rect.move_ip(vx,vy)
"""self.rect.left = self.rect.left + vx
self.rect.top = self.rect.top + vy"""
class Map:
def __init__(self, filename):
tm = load_pygame(filename, pixelalpha=True)
self.size = tm.width * tm.tilewidth, tm.height * tm.tileheight
self.tmx_data = tm
def render(self, surface):
tw = self.tmx_data.tilewidth
th = self.tmx_data.tileheight
gt = self.tmx_data.getTileImageByGid
if self.tmx_data.background_color:
surface.fill(self.tmx_data.background_color)
for layer in self.tmx_data.visibleLayers:
if isinstance(layer, pytmx.TiledTileLayer):
for x, y, gid in layer:
tile = gt(gid)
if tile:
surface.blit(tile, (x * tw, y * th))
elif isinstance(layer, pytmx.TiledObjectGroup):
pass
elif isinstance(layer, pytmx.TiledImageLayer):
image = gt(layer.gid)
if image:
surface.blit(image, (0, 0))
def make_map(self):
temp_surface = pg.Surface(self.size)
self.render(temp_surface)
return temp_surface
def main():
pg.init()
FPSClock = pg.time.Clock()
DISPLAYSURFACE = pg.display.set_mode((WIDTHWINDOW,HEIGHTWINDOW))
pg.display.set_caption("Pokemon")
#backGround = Background('./map/5.png', [0,0])
backGround = Map('map/pokemon01.tmx')
t=0
player = Player([int(WIDTHWINDOW/2), 50])
vx = 0
vy = 0
vel=2
rightIsPressed,leftIsPressed,upIsPressed,downIsPressed = False,False,False,False
isMoving = False
while True:
for event in pg.event.get():
if event.type==pg.QUIT:
pg.quit()
sys.exit()
if event.type==pg.KEYDOWN:
if event.key==pg.K_DOWN:
downIsPressed=True
vy=vel
vx=0
player.orientation = 0
if event.key==pg.K_UP:
upIsPressed=True
vy=-vel
vx=0
player.orientation = 1
if event.key==pg.K_LEFT:
leftIsPressed=True
vx=-vel
vy=0
player.orientation = 3
if event.key==pg.K_RIGHT:
rightIsPressed=True
vx=vel
vy=0
player.orientation = 2
if event.type==pg.KEYUP:
if event.key==pg.K_DOWN:
downIsPressed=False
if upIsPressed:
vy=-vel
vx=0
else:
vy=0
if event.key==pg.K_UP:
upIsPressed=False
if downIsPressed:
vy=vel
vx=0
else:
vy=0
if event.key==pg.K_LEFT:
leftIsPressed=False
if rightIsPressed:
vx=vel
vy=0
else:
vx=0
if event.key==pg.K_RIGHT:
rightIsPressed=False
if leftIsPressed:
vx=-vel
vy=0
else:
vx=0
if t>=1:
t=0
else:
t+=1
if rightIsPressed==False and leftIsPressed==False and upIsPressed==False and downIsPressed==False:
isMoving = False
else:
isMoving = True
if isMoving == False:
t=0
player.actual_image=player.images[player.orientation][t]
player.move(vx,vy)
#DISPLAYSURFACE.blit(pg.transform.scale(backGround.image, (WIDTHWINDOW, HEIGHTWINDOW)), backGround.rect)
DISPLAYSURFACE.blit(pg.transform.scale(backGround.make_map(), (WIDTHWINDOW, HEIGHTWINDOW)), backGround.make_map().get_rect())
DISPLAYSURFACE.blit(pg.transform.scale(player.actual_image, (SPRITEWIDTH, SPRITEHEIGHT)), player.rect)
"""
for x in range(0, WIDTHWINDOW, TILESIZE):
pg.draw.line(DISPLAYSURFACE, (0,0,0), (x, 0), (x, HEIGHTWINDOW))
for y in range(0, HEIGHTWINDOW, TILESIZE):
pg.draw.line(DISPLAYSURFACE, (0,0,0), (0, y), (WIDTHWINDOW, y))
"""
FPSClock.tick(30)
pg.display.update()
if __name__ == '__main__':
main()
El error: http://es.tinypic.com/r/ouxh68/9