#-----------# #Importation# #-----------# from Fonctions import * import pygame from pygame.locals import * import pickle #import class_def #from class_def import Foo # Import Foo into main_module's namespace explicitly #if __name__=='__main__': # with open('test_data.pkl', 'rb') as f: # users = pickle.load(f) #----------# #Repertoire# #----------# rep="/Users/olivierpartensky/Desktop/Programme/GitHub/python_projects/Expanse/" #--------# #Couleurs# #--------# BLACK= ( 0, 0, 0) WHITE= (255,255,255) RED= (255, 0, 0) GREEN= ( 0,255, 0) BLUE= ( 0, 0,255) CYAN= ( 0,255,255) PURPLE= (255, 0,255) YELLOW= (255,255, 0) BROWN= (150, 75, 0) ORANGE= (255,140, 0) CRANDOM=(random.randint(0,255),random.randint(0,255),random.randint(0,255)) #------# #Blocks# #------# """ "Rideau":[[BLACK,WHITE,BLACK,WHITE,BLACK], [BLACK,WHITE,BLACK,WHITE,BLACsBK], [BLACK,WHITE,BLACK,WHITE,BLACK], [BLACK,WHITE,BLACK,WHITE,BLACK], [BLACK,WHITE,BLACK,WHITE,BLACK]] """ def Init(): #COLORS# COLORS=SortirVariable(rep+"COLORS") try: COLORS=COLORS[0] except: COLORS={"BLACK":( 0, 0, 0), "WHITE",( RED,GREEN,BLUE, CYAN,PURPLE,YELLOW, BROWN,ORANGE, CRANDOM] print("COLORS initialisé") #BLOCKS# BLOCKS=SortirVariable(rep+"BLOCKS") try: BLOCKS=BLOCKS[0] except: BLOCKS={"made":0, "1":{}, "2":{}, "3":{}, "4":{}, "5":{}, "6":{}, "7":{}, "8":{}, "9":{}, "10":{}, "11":{}, "12":{}, "13":{}, "14":{}, "15":{}, "16":{}, "17":{}, "18":{}, "19":{}, "20":{} } print("BLOCKS initialisé") #MAPS# MAPS=SortirVariable(rep+"MAPS") try: MAPS=MAPS[0] except: MAPS={"made":0} #------------# #Organisation# #------------# """ Organisation={"Name":None, "Author":"Marc Partensky", "Windows": {"Menu":None, "Maps": {"Name":None, "Square":"Pixels" } "Credits":None } } """ #--------------------# #Classes et Fonctions# #--------------------# class Editing: def __init__(self,ci=0,mx=100,my=50,bx=5,by=5): self.mci=ci self.mx=mx self.my=my self.bci=ci self.bx=bx self.by=by class Map: made = 0 def __init__(self,name,typ=0,value=None,tx=200,ty=100,size=5): self.version=1 self.map=[[Square(typ,value) for x in range(tx)] for y in range(ty)] self.id=Map.made self.tx=tx self.ty=ty self.size=size self.value=value self.name=str(input("Nom: ")) Map.made+=1 def show(self): pygame.init() screen_size=(self.tx*self.size,self.ty*self.size) screen = pygame.display.set_mode(screen_size) pygame.display.set_caption("Showing Mode") s=self.size print(s) for y in range(self.ty): for x in range(self.tx): if self.map[y][x].typ==0: pygame.draw.rect(screen, self.map[y][x].color, (x*s,y*s,s,s), 0) if self.map[y][x].typ==1: for yi in range(self.size): for xi in range(self.size): pygame.draw.rect(screen, BLOCKS[str(s)][self.value].block[yi][xi], (x*s+xi,y*s+yi,1,1), 0) pygame.display.flip() done = False while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True if event.type == KEYDOWN: done = True pygame.quit() def edit(self): pygame.init() screen_size=(self.tx*self.size,self.ty*self.size) screen = pygame.display.set_mode(screen_size) pygame.display.set_caption("Editing Mode") s=self.size for y in range(self.ty): for x in range(self.tx): if self.map[y][x].typ==0: pygame.draw.rect(screen, self.map[y][x].color, (x*s,y*s,s,s), 0) if self.map[y][x].typ==1: for yi in range(self.size): for xi in range(self.size): pygame.draw.rect(screen, BLOCKS[str(s)][self.value].block[yi][xi], (x*s+xi,y*s+yi,1,1), 0) pygame.display.flip() e=Editing() done = False while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done=True if event.type == MOUSEBUTTONDOWN and event.button == 1: e.mx=event.pos[0]//s e.my=event.pos[1]//s if event.type == pygame.K_UP and my0: e.my-=1 if event.type == pygame.K_LEFT and mx>0: e.mx-=1 if event.type == pygame.K_RIGHT and mx0: e.by-=1 if event.key == pygame.K_LEFT and e.bx>0: e.bx-=1 if event.key == pygame.K_RIGHT and e.bx