So I've been trying to create a jigsaw puzzle using pygame in python.The only problem is that I'm having trouble creating the board with multiple images that i can drag along the screen (no need to connect the images like a puzzle what so ever just a simple drag and drop). I'm loading my images from a local folder on my computer. Can someone please help me?
This is what i have tried so far but the images start at the same postion and pygame recognize them all as one image
import socket
import os
import shutil
import pygame
from pygame.locals import*def dragdrop(path):dirs = os.listdir(path)def load_image(name, colorkey=None):fullname=os.path.join("data", name)try:image=pygame.image.load(fullname)except pygame.error, message:print "Impossible de charger l'image:",nameraise SystemExit, messageimage = image.convert()if colorkey is not None:if colorkey is -1:colorkey = image.get_at((0, 0))image.set_colorkey(colorkey, RLEACCEL)return image, image.get_rect()class Ichrom(pygame.sprite.Sprite):def __init__(self,image,initpos):pygame.sprite.Sprite.__init__(self)self.pos = initposself.image, self.rect=imageself.button=(0,0,0)#mouse buttons not pressedself.selected = 0self.mouseover=Falseself.focused=Falseprint "init chrom at ",self.posdef rollover(self):"""Test if the mouse fly over the chromosome self.mouseover==True if mouse flying over the chrom,False if not"""mpos=pygame.mouse.get_pos()#mouseposition#test if mouse roll over the spriteif self.rect.collidepoint(mpos):self.mouseover=Trueelse:self.mouseover=Falsedef update(self):self.button=pygame.mouse.get_pressed()mpos = pygame.mouse.get_pos()self.selected=self.rect.collidepoint(mpos)#the mouse flies over a chromosomeif (self.mouseover):#print "mouse pos:",mposif self.button==(1,0,0): # ) pos = pygame.mouse.get_pos()self.rect.midtop = posdef main():pygame.init()screen = pygame.display.set_mode((1000,1000))pygame.display.set_caption("Karyotyper")pygame.mouse.set_visible(True)background = pygame.Surface(screen.get_size())background = background.convert()background.fill((0, 0, 0))screen.blit(background,(0, 0))pygame.display.flip()"""i1=load_image('C:/Users/Yonatan/Desktop/House.png', -1)i2=load_image('C:/Users/Yonatan/Desktop/US.jpeg', -1)i3=load_image('C:\Users\Yonatan\Desktop\imgres.jpg', -1)fuck= [i1, i2, i3]"""img=[]count=0for i in dirs:spr = Ichrom(load_image(path + "/" +i,-1),(count,count))count = count+30img.append(spr)allsprites = pygame.sprite.RenderPlain((fck))clock = pygame.time.Clock()while 1:clock.tick(60)for event in pygame.event.get():if event.type == QUIT:returnelif event.type == KEYDOWN and event.key == K_ESCAPE:returnif event.type ==pygame.MOUSEBUTTONDOWN:#need to be modified to handle a list of chromosomesfor i in fck:i.rollover()allsprites.update()screen.blit(background,(0,0))allsprites.draw(screen)pygame.display.flip()main()