import pygame
import bloc

def crea_mur(posini, ample, alt, nomf):
    imur = pygame.image.load(nomf).convert()
    maons = pygame.sprite.RenderPlain()
    ncols = imur.get_width()
    nfils = imur.get_height()
    ampleb, altb = ample/ncols, alt/nfils
    r = pygame.Rect(posini, (ncols*ampleb, nfils*altb))
    r.center = (ample/2+posini[0], alt/2+posini[1])
    px, py = r.topleft
    for y in range(nfils):
        for x in range(ncols):
            color = imur.get_at((x,y))
            if color[:3] != (255,255,255):
                mao = bloc.Bloc( (px+x*ampleb, py+y*altb), (ampleb-1, altb-1),
                                 color )
                maons.add(mao)
    return maons

