Modification majeure vers le nouveau format de stockage pour tout les mondes
Reste a convertir les elements et les menus
This commit is contained in:
parent
cc862cfa6a
commit
2c0f386ad2
538
WireChem.py
538
WireChem.py
|
@ -6,49 +6,99 @@ import csv
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
import operator
|
import operator
|
||||||
|
import shelve
|
||||||
|
import os
|
||||||
from pyglet.gl import *
|
from pyglet.gl import *
|
||||||
from pyglet.window import mouse
|
from pyglet.window import mouse
|
||||||
from pyglet.window import key
|
from pyglet.window import key
|
||||||
from pyglet import clock
|
from pyglet import clock
|
||||||
from pyglet import image
|
from pyglet import image
|
||||||
|
from os.path import expanduser
|
||||||
|
|
||||||
''' ************************************************************************************************ '''
|
''' ************************************************************************************************ '''
|
||||||
''' Initialisation '''
|
''' Initialisation & Chargement '''
|
||||||
|
|
||||||
|
def sync():
|
||||||
|
global Uworlds,finished
|
||||||
|
write(gethome()+"/dbdata",["Uworlds","finished"])
|
||||||
|
|
||||||
|
def verifyhome():
|
||||||
|
global Uworlds,finished
|
||||||
|
if not os.path.exists(gethome()):
|
||||||
|
os.makedirs(gethome())
|
||||||
|
if not os.path.exists(gethome()+"/dbdata"):
|
||||||
|
Uworlds=[[{0:0}]]
|
||||||
|
finished=[(0,0)]
|
||||||
|
sync()
|
||||||
|
|
||||||
|
def gethome():
|
||||||
|
home = expanduser("~")+"/.wirechem"
|
||||||
|
return home
|
||||||
|
|
||||||
|
def write(afile,var):
|
||||||
|
d=shelve.open(afile,writeback=True)
|
||||||
|
for k in var:
|
||||||
|
d[k]=copy.deepcopy(globals()[k])
|
||||||
|
d.sync()
|
||||||
|
d.close()
|
||||||
|
|
||||||
|
def read(afile):
|
||||||
|
d=shelve.open(afile,writeback=True)
|
||||||
|
for k in d.keys():
|
||||||
|
globals()[k]=copy.deepcopy(d[k])
|
||||||
|
d.close()
|
||||||
|
|
||||||
|
def load(d):
|
||||||
|
for k in d.keys():
|
||||||
|
if k[0]!="_":
|
||||||
|
globals()[k]=copy.deepcopy(d[k])
|
||||||
|
|
||||||
|
def reference(var,noms):
|
||||||
|
sizex=len(var)
|
||||||
|
if len(noms)==2: sizey=len(var[0])
|
||||||
|
for x in range(sizex):
|
||||||
|
for y in range(sizey):
|
||||||
|
var[x][y][noms[0]]=x
|
||||||
|
if len(noms)==2: var[x][y][noms[1]]=y
|
||||||
|
|
||||||
|
'''Ancienne fonctions'''
|
||||||
|
|
||||||
def loaditems(n,file):
|
def loaditems(n,file):
|
||||||
global items
|
global items
|
||||||
with open(file, 'rb') as f:
|
with open(file, 'rb') as f:
|
||||||
liste=list(csv.reader(f,delimiter=';'))
|
liste=list(csv.reader(f,delimiter=';'))
|
||||||
for i in range(1,len(liste)):
|
if len(liste)!=0:
|
||||||
items[liste[i][0]]={}
|
for i in range(1,len(liste)):
|
||||||
for j in range(1,len(liste[i])):
|
items[liste[i][0]]={}
|
||||||
if liste[i][j][:1]=="#":
|
for j in range(1,len(liste[i])):
|
||||||
items[liste[i][0]][liste[0][j]]=int(liste[i][j][1:])
|
if liste[i][j][:1]=="#":
|
||||||
elif liste[i][j][:1]=="[":
|
items[liste[i][0]][liste[0][j]]=int(liste[i][j][1:])
|
||||||
atemp=liste[i][j][1:-1].split(",")
|
elif liste[i][j][:1]=="[":
|
||||||
items[liste[i][0]][liste[0][j]]=[int(atemp[k]) for k in range(len(atemp))]
|
atemp=liste[i][j][1:-1].split(",")
|
||||||
elif liste[i][j][:1]=="{":
|
items[liste[i][0]][liste[0][j]]=[int(atemp[k]) for k in range(len(atemp))]
|
||||||
atemp=items[liste[i][0]][liste[0][j]]=liste[i][j][1:-1].split(",")
|
elif liste[i][j][:1]=="{":
|
||||||
items[liste[i][0]][liste[0][j]]=[atemp[k] for k in range(len(atemp))]
|
atemp=items[liste[i][0]][liste[0][j]]=liste[i][j][1:-1].split(",")
|
||||||
elif liste[i][j][:2]=="0x":
|
items[liste[i][0]][liste[0][j]]=[atemp[k] for k in range(len(atemp))]
|
||||||
items[liste[i][0]][liste[0][j]]=int(liste[i][j][2:],16)
|
elif liste[i][j][:2]=="0x":
|
||||||
elif liste[i][j][:1]=="&":
|
items[liste[i][0]][liste[0][j]]=int(liste[i][j][2:],16)
|
||||||
items[liste[i][0]][liste[0][j]]=float(liste[i][j][1:])
|
elif liste[i][j][:1]=="&":
|
||||||
elif liste[i][j][:1]=="@":
|
items[liste[i][0]][liste[0][j]]=float(liste[i][j][1:])
|
||||||
items[liste[i][0]][liste[0][j]]=items[liste[i][j][1:]]
|
elif liste[i][j][:1]=="@":
|
||||||
elif liste[i][j][:1]=="%":
|
items[liste[i][0]][liste[0][j]]=items[liste[i][j][1:]]
|
||||||
items[liste[i][0]][liste[0][j]]=image.load(liste[i][j][1:])
|
elif liste[i][j][:1]=="%":
|
||||||
else:
|
items[liste[i][0]][liste[0][j]]=image.load(liste[i][j][1:])
|
||||||
items[liste[i][0]][liste[0][j]]=liste[i][j]
|
else:
|
||||||
if n!=0:
|
items[liste[i][0]][liste[0][j]]=liste[i][j]
|
||||||
items[liste[i][0]]['value']=n+i-1
|
if n!=0:
|
||||||
items[items[liste[i][0]]['value']]=liste[i][0]
|
items[liste[i][0]]['value']=n+i-1
|
||||||
|
items[items[liste[i][0]]['value']]=liste[i][0]
|
||||||
f.close()
|
f.close()
|
||||||
return len(liste)-1
|
return len(liste)-1
|
||||||
|
|
||||||
def initgrid(x,y):
|
''' json.dump(globals()[tempi],f,-1)'''
|
||||||
global statedvar,stat_var,seestat,adirection,sizeworld,finished,allcout,selected,world,level,over,mousel,mouser,mousem,sizex,sizey,world_old,world_new,world_art,items,direction,zoom,play,stat,cycle,cout,thecout,rayon,unroll,debug,temp,decx,decy,nrj,tech,victory,current,maxnrj,maxrayon,maxcycle,maxtemp,nom,descriptif,element
|
|
||||||
|
def initgrid():
|
||||||
|
global Uworlds,statedvar,stat_var,seestat,adirection,worlds,finished,allcout,selected,world,level,over,mousel,mouser,mousem,sizex,sizey,world_old,world_new,world_art,items,direction,zoom,play,stat,cycle,cout,thecout,rayon,unroll,debug,temp,decx,decy,nrj,tech,victory,current,maxnrj,maxrayon,maxcycle,maxtemp,nom,descriptif,element
|
||||||
|
|
||||||
''' Directions des electrons en fonction de la position de la queue '''
|
''' Directions des electrons en fonction de la position de la queue '''
|
||||||
direction = {}
|
direction = {}
|
||||||
|
@ -62,86 +112,47 @@ def initgrid(x,y):
|
||||||
direction[(+1,+1)]=[(-1,-1),(-1,+0),(+0,-1),(-1,+1),(+1,-1),(+0,+1),(+1,+0),(+1,+1)]
|
direction[(+1,+1)]=[(-1,-1),(-1,+0),(+0,-1),(-1,+1),(+1,-1),(+0,+1),(+1,+0),(+1,+1)]
|
||||||
adirection=[(-1,-1),(-1,+0),(-1,+1),(+0,-1),(+0,+1),(+1,-1),(+1,+0),(+1,+1)]
|
adirection=[(-1,-1),(-1,+0),(-1,+1),(+0,-1),(+0,+1),(+1,-1),(+1,+0),(+1,+1)]
|
||||||
items = {}
|
items = {}
|
||||||
sizeworld=loaditems(int("0x40000", 16),"data/worlds.dat")
|
|
||||||
|
verifyhome()
|
||||||
loaditems(int("0x30000", 16),"data/elements2.dat")
|
loaditems(int("0x30000", 16),"data/elements2.dat")
|
||||||
loaditems(int("0x10000", 16),"data/menus2.dat")
|
loaditems(int("0x10000", 16),"data/menus2.dat")
|
||||||
loaditems(int("0x20000", 16),"data/menus.dat")
|
loaditems(int("0x20000", 16),"data/menus.dat")
|
||||||
loaditems(0,"data/elements.dat")
|
loaditems(0,"data/elements.dat")
|
||||||
|
read("dbdata")
|
||||||
|
read(gethome()+"/dbdata")
|
||||||
|
reference(worlds,['world','level'])
|
||||||
|
reference(Uworlds,['world','level'])
|
||||||
|
|
||||||
''' Variables globales '''
|
''' Variables globales '''
|
||||||
sizex=x
|
|
||||||
sizey=y
|
|
||||||
zoom=25
|
zoom=25
|
||||||
stat=[0,0,0,0,0,0,0,0,0]
|
stat=[0,0,0,0,0,0,0,0,0]
|
||||||
nom=descriptif=element='H'
|
nom=descriptif=element='H'
|
||||||
victory=[0,0,0,0,0,0,0,0,0,0,0,0,0]
|
victory=[0,0,0,0,0,0,0,0,0,0,0,0,0]
|
||||||
current=[0,0,0,0,0,0,0,0,0,0,0,0,0]
|
current=[0,0,0,0,0,0,0,0,0,0,0,0,0]
|
||||||
stat_var=finished=[]
|
stat_var=[]
|
||||||
mousel=4
|
mousel=4
|
||||||
mouser=0
|
mouser=0
|
||||||
mousem=3
|
mousem=3
|
||||||
maxnrj=maxrayon=maxcycle=maxtemp=99999
|
maxnrj=maxrayon=maxcycle=maxtemp=99999
|
||||||
allcout=[0,0,0]
|
allcout=[0,0,0]
|
||||||
|
sizex=sizey=1
|
||||||
seestat=thecout=world=over=play=cycle=rayon=temp=cout=decx=decy=unroll=nrj=debug=0
|
seestat=thecout=world=over=play=cycle=rayon=temp=cout=decx=decy=unroll=nrj=debug=0
|
||||||
selected=level=-1
|
tech=selected=level=-1
|
||||||
tech=9
|
|
||||||
statedvar=[stat[0],stat[1],stat[2],stat[3],stat[4],stat[5],stat[6],stat[7],stat[8],nrj,temp,rayon,current[7],current[8],current[9],current[10],current[11],current[12]]
|
statedvar=[stat[0],stat[1],stat[2],stat[3],stat[4],stat[5],stat[6],stat[7],stat[8],nrj,temp,rayon,current[7],current[8],current[9],current[10],current[11],current[12]]
|
||||||
if len(stat_var)==0:
|
if len(stat_var)==0:
|
||||||
for i in range(len(statedvar)):
|
for i in range(len(statedvar)):
|
||||||
stat_var.append([0])
|
stat_var.append([0])
|
||||||
world_art = [[items['nothing']['value'] for y in range(sizey)] for x in range(sizex)]
|
world_new = world_art = [[]]
|
||||||
world_new = [[items['nothing']['value'] for y in range(sizey)] for x in range(sizex)]
|
world=0
|
||||||
|
for w in range(len(worlds)):
|
||||||
|
for l in range(len(worlds[w])):
|
||||||
|
if "level"+str(w)+"-"+str(l) in finished and w>world:
|
||||||
|
world=w
|
||||||
|
|
||||||
|
|
||||||
''' *********************************************************************************************** '''
|
''' *********************************************************************************************** '''
|
||||||
''' Sauvegarde/Restauration '''
|
''' Sauvegarde/Restauration '''
|
||||||
|
|
||||||
'''format nom,element,descriptif,debug,zoom,decx,decy,tech,victory '''
|
|
||||||
|
|
||||||
def readpref(file):
|
|
||||||
global finished
|
|
||||||
with open(file, 'a+') as f:
|
|
||||||
try:
|
|
||||||
finished=list(csv.reader(f,delimiter=';'))[0]
|
|
||||||
f.close()
|
|
||||||
except:
|
|
||||||
print "no"
|
|
||||||
|
|
||||||
def writepref(file):
|
|
||||||
global finished
|
|
||||||
with open(file, 'wb+') as f:
|
|
||||||
writer = csv.writer(f, delimiter=';', quotechar='', quoting=csv.QUOTE_NONE)
|
|
||||||
writer.writerow(list(set(finished)))
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def readlittlegrid(file,key):
|
|
||||||
with open(file, 'rb') as f:
|
|
||||||
liste=list(csv.reader(f,delimiter=';'))
|
|
||||||
items[key]['nom']=liste[0][0]
|
|
||||||
items[key]['element']=liste[0][1]
|
|
||||||
items[key]['description']=liste[0][2]
|
|
||||||
items[key]['tech']=int(liste[0][7])
|
|
||||||
items[key]['cout']=int(liste[0][8])
|
|
||||||
victemp=liste[0][9][1:len(liste[0][9])-1].split(",")
|
|
||||||
items[key]['victory']=[int(victemp[k]) for k in range(len(victemp))]
|
|
||||||
items[key]['maxcycle']=int(liste[0][15])
|
|
||||||
items[key]['maxnrj']=int(liste[0][16])
|
|
||||||
items[key]['maxrayon']=int(liste[0][17])
|
|
||||||
items[key]['maxtemp']=int(liste[0][18])
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def readcondgrid(file):
|
|
||||||
global current,cycle,nrj,rayon,temp
|
|
||||||
with open(file, 'rb') as f:
|
|
||||||
liste=list(csv.reader(f,delimiter=';'))
|
|
||||||
curtemp=liste[0][10][1:len(liste[0][10])-1].split(",")
|
|
||||||
current=[int(curtemp[k]) for k in range(len(curtemp))]
|
|
||||||
cycle=int(liste[0][11])
|
|
||||||
nrj=int(liste[0][12])
|
|
||||||
rayon=int(liste[0][13])
|
|
||||||
temp=int(liste[0][14])
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def resize():
|
def resize():
|
||||||
global zoom,decx,decy,seestat
|
global zoom,decx,decy,seestat
|
||||||
if seestat>=1:
|
if seestat>=1:
|
||||||
|
@ -155,67 +166,67 @@ def resize():
|
||||||
decx=-zoom+(allsizex-zoom*(sizex-2))/2
|
decx=-zoom+(allsizex-zoom*(sizex-2))/2
|
||||||
decy=-zoom+(win.height-zoom*(sizey-2))/2
|
decy=-zoom+(win.height-zoom*(sizey-2))/2
|
||||||
|
|
||||||
def readgrid(file):
|
def readlevel(w,l,user):
|
||||||
global unroll,mousel,mousem,mouser,cout,selected,sizex,sizey,world_old,world_new,world_art,items,zoom,play,stat,cycle,nrj,rayon,tech,decx,decy,unroll,stat,victory,current,temp,debug,nom,descriptif,element,maxnrj,maxrayon,maxcycle,maxtemp
|
global worlds,unroll,mousel,mousem,mouser,cout,selected,sizex,sizey,unroll,stat
|
||||||
try:
|
if user:
|
||||||
with open(file, 'rb') as f:
|
if w<len(Uworlds) and l<len(Uworlds[w]) and Uworlds[w][l].has_key("element"):
|
||||||
liste=list(csv.reader(f,delimiter=';'))
|
load(Uworlds[w][l])
|
||||||
sizey=(len(liste)-1)/2
|
else:
|
||||||
sizex=len(liste[1])
|
load(worlds[w][l])
|
||||||
nom=liste[0][0]
|
else:
|
||||||
element=liste[0][1]
|
load(worlds[w][l])
|
||||||
descriptif=liste[0][2]
|
if tech<0:
|
||||||
debug=int(liste[0][3])
|
items[items['setcopper']['value']]='setnothinga'
|
||||||
resize();
|
items[items['setfiber']['value']]='setnothinga'
|
||||||
tech=int(liste[0][7])
|
items[items['setnothing']['value']]='setnothinga'
|
||||||
cout=int(liste[0][8])
|
items[items['others']['value']]='setnothinga'
|
||||||
victemp=liste[0][9][1:len(liste[0][9])-1].split(",")
|
elif tech<2:
|
||||||
victory=[int(victemp[k]) for k in range(len(victemp))]
|
items[items['setcopper']['value']]='setcopper'
|
||||||
curtemp=liste[0][10][1:len(liste[0][10])-1].split(",")
|
items[items['setfiber']['value']]='setnothinga'
|
||||||
current=[int(curtemp[k]) for k in range(len(curtemp))]
|
items[items['setnothing']['value']]='setnothing'
|
||||||
cycle=int(liste[0][11])
|
items[items['others']['value']]='others'
|
||||||
nrj=int(liste[0][12])
|
else:
|
||||||
rayon=int(liste[0][13])
|
items[items['setcopper']['value']]='setcopper'
|
||||||
temp=int(liste[0][14])
|
items[items['setfiber']['value']]='setfiber'
|
||||||
maxcycle=int(liste[0][15])
|
items[items['setnothing']['value']]='setnothing'
|
||||||
maxnrj=int(liste[0][16])
|
items[items['others']['value']]='others'
|
||||||
maxrayon=int(liste[0][17])
|
sizex=len(world_new)
|
||||||
maxtemp=int(liste[0][18])
|
sizey=len(world_new[0])
|
||||||
world_new = [[int(liste[sizey-i][j]) for i in range(sizey)] for j in range(sizex)]
|
resize();
|
||||||
world_art = [[int(liste[-i-1][j]) for i in range(sizey)] for j in range(sizex)]
|
stat=[0,0,0,0,0,0,0,0,0]
|
||||||
stat=[0,0,0,0,0,0,0,0,0]
|
unroll=over=0
|
||||||
unroll=over=0
|
infos()
|
||||||
if tech<0:
|
|
||||||
items[items['setcopper']['value']]='setnothinga'
|
|
||||||
items[items['setfiber']['value']]='setnothinga'
|
|
||||||
items[items['setnothing']['value']]='setnothinga'
|
|
||||||
items[items['others']['value']]='setnothinga'
|
|
||||||
elif tech<2:
|
|
||||||
items[items['setcopper']['value']]='setcopper'
|
|
||||||
items[items['setfiber']['value']]='setnothinga'
|
|
||||||
items[items['setnothing']['value']]='setnothing'
|
|
||||||
items[items['others']['value']]='others'
|
|
||||||
else:
|
|
||||||
items[items['setcopper']['value']]='setcopper'
|
|
||||||
items[items['setfiber']['value']]='setfiber'
|
|
||||||
items[items['setnothing']['value']]='setnothing'
|
|
||||||
items[items['others']['value']]='others'
|
|
||||||
f.close()
|
|
||||||
infos()
|
|
||||||
return True
|
|
||||||
except IOError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def writegrid(file):
|
def savelevel(w,l):
|
||||||
global sizex,sizey,world_old,world_new,world_art,items,play,cycle,nom,element,descriptif,debug,zoom,decx,decy,tech,victory
|
global worlds,Uworlds,nom,descriptif,video,link,tech,cout,victory,current,cycle,nrj,rayon,temp,maxcycle,maxnrj,maxrayon,maxtemp,world_new,world_art
|
||||||
with open(file, 'wb') as f:
|
while len(Uworlds)<=w:
|
||||||
writer = csv.writer(f, delimiter=';', quotechar='', quoting=csv.QUOTE_NONE)
|
Uworlds.append(0)
|
||||||
writer.writerow([nom,element,descriptif,debug,zoom,decx,decy,tech,cout,str(victory),str(current),cycle,nrj,rayon,temp,maxcycle,maxnrj,maxrayon,maxtemp])
|
Uworlds[w]=[]
|
||||||
for j in range(sizey):
|
while len(Uworlds[w])<=l:
|
||||||
writer.writerow([world_new[i][sizey-j-1] for i in range(sizex)])
|
Uworlds[w].append({'level':level,'world':world})
|
||||||
for j in range(sizey):
|
Uworlds[w][l]={'nom':nom,
|
||||||
writer.writerow([wart(i,-j-1) for i in range(sizex)])
|
'element':element,
|
||||||
f.close()
|
'description':descriptif,
|
||||||
|
'_xx':worlds[world][level]['_xx'],
|
||||||
|
'_yy':worlds[world][level]['_yy'],
|
||||||
|
'video':video,
|
||||||
|
'link':link,
|
||||||
|
'level':level,
|
||||||
|
'world':world,
|
||||||
|
'tech':tech,
|
||||||
|
'cout':cout,
|
||||||
|
'victory':victory,
|
||||||
|
'current':worlds[world][level]['current'],
|
||||||
|
'cycle':cycle,
|
||||||
|
'nrj':nrj,
|
||||||
|
'rayon':rayon,
|
||||||
|
'temp':temp,
|
||||||
|
'maxcycle':maxcycle,
|
||||||
|
'maxnrj':maxnrj,
|
||||||
|
'maxrayon':maxrayon,
|
||||||
|
'maxtemp':maxtemp,
|
||||||
|
'world_new':world_new,
|
||||||
|
'world_art':world_art}
|
||||||
|
|
||||||
''' *********************************************************************************************** '''
|
''' *********************************************************************************************** '''
|
||||||
''' Fonctions programmees '''
|
''' Fonctions programmees '''
|
||||||
|
@ -527,76 +538,72 @@ def drawworld():
|
||||||
glColor3ub(255,255,255)
|
glColor3ub(255,255,255)
|
||||||
pic_arrows2.blit(920,150)
|
pic_arrows2.blit(920,150)
|
||||||
glColor3ub(255,255,255)
|
glColor3ub(255,255,255)
|
||||||
for i in range(sizeworld):
|
for l in range(len(worlds[world])):
|
||||||
ele=items[items[int("0x40000",16)+i]]
|
ele=worlds[world][l]
|
||||||
if ele['world']==world:
|
for n in ele['link']:
|
||||||
for n in ele['validate']:
|
if n!="" and n[0]==world:
|
||||||
if n!="" and items[n]['world']==world:
|
if n in finished:
|
||||||
if n in finished:
|
drawLaser(ele['_xx']+50,int(ele['_yy']/768.0*win.height+50),worlds[n[0]][n[1]]['_xx']+50,int(worlds[n[0]][n[1]]['_yy']/768.0*win.height+50),random.randint(0,6),20,[0,100,0],12)
|
||||||
drawLaser(ele['coordx']+50,int(ele['coordy']/768.0*win.height+50),items[n]['coordx']+50,int(items[n]['coordy']/768.0*win.height+50),random.randint(0,6),20,[0,100,0],12)
|
else:
|
||||||
else:
|
drawLaser(ele['_xx']+50,int(ele['_yy']/768.0*win.height+50),worlds[n[0]][n[1]]['_xx']+50,int(worlds[n[0]][n[1]]['_yy']/768.0*win.height+50),2,20,[40,40,40],0)
|
||||||
drawLaser(ele['coordx']+50,int(ele['coordy']/768.0*win.height+50),items[n]['coordx']+50,int(items[n]['coordy']/768.0*win.height+50),2,20,[40,40,40],0)
|
for l in range(len(worlds[world])):
|
||||||
for i in range(sizeworld):
|
ele=worlds[world][l]
|
||||||
ele=items[items[int("0x40000",16)+i]]
|
if (world,l) not in finished:
|
||||||
if ele['world']==world:
|
glColor3ub(60,60,60)
|
||||||
if 'cout' not in ele:
|
acolor=(90,90,90,255)
|
||||||
readlittlegrid(ele['file'],items[int("0x40000",16)+i])
|
elif selected!=ele:
|
||||||
if items[int("0x40000",16)+i] not in finished and not (ele['world']==0 and ele['grid']==0):
|
glColor3ub(255,120+int(ele['_xx']/1024.0*135),155+int(ele['_xx']/1024.0*100))
|
||||||
glColor3ub(60,60,60)
|
acolor=(255,255,255,255)
|
||||||
acolor=(90,90,90,255)
|
else:
|
||||||
elif selected!=ele:
|
acolor=(255,0,0,255)
|
||||||
glColor3ub(255,120+int(ele['coordx']/1024.0*135),155+int(ele['coordx']/1024.0*100))
|
document=pyglet.text.decode_attributed("{font_name 'OpenDyslexicAlta'}{font_size 18}{color (255, 255, 255, 255)}"+ele['description'].decode('utf-8')+"}".encode('utf8'))
|
||||||
acolor=(255,255,255,255)
|
txt_description.document=document
|
||||||
else:
|
txt_description.draw()
|
||||||
acolor=(255,0,0,255)
|
document=None
|
||||||
document=pyglet.text.decode_attributed("{font_name 'OpenDyslexicAlta'}{font_size 18}{color (255, 255, 255, 255)}"+ele['description'].decode('utf-8')+"}".encode('utf8'))
|
|
||||||
txt_description.document=document
|
|
||||||
txt_description.draw()
|
|
||||||
document=None
|
|
||||||
glColor3ub(255,255,255)
|
|
||||||
if ele['cout']>0:
|
|
||||||
items['cout']['icon'].blit(740,110)
|
|
||||||
txt_cout2.text=str(ele['cout'])
|
|
||||||
txt_cout2.draw()
|
|
||||||
if ele['maxcycle']<90000:
|
|
||||||
items['cycle']['icon'].blit(740,65)
|
|
||||||
txt_maxcycle2.text=str(ele['maxcycle'])
|
|
||||||
txt_maxcycle2.draw()
|
|
||||||
if ele['tech']>0:
|
|
||||||
items['tech']['icon'].blit(940,110)
|
|
||||||
txt_tech2.text=str(ele['tech'])
|
|
||||||
txt_tech2.draw()
|
|
||||||
if ele['maxrayon']<90000:
|
|
||||||
items['rayon']['icon'].blit(940,65)
|
|
||||||
txt_maxrayon2.text=str(ele['maxrayon'])
|
|
||||||
txt_maxrayon2.draw()
|
|
||||||
if ele['maxtemp']<90000:
|
|
||||||
items['temp']['icon'].blit(850,110)
|
|
||||||
txt_maxtemp2.text=str(ele['maxtemp'])
|
|
||||||
txt_maxtemp2.draw()
|
|
||||||
if ele['maxnrj']<90000:
|
|
||||||
items['nrj']['icon'].blit(850,65)
|
|
||||||
txt_maxnrj2.text=str(ele['maxnrj'])
|
|
||||||
txt_maxnrj2.draw()
|
|
||||||
victory=ele['victory']
|
|
||||||
drawcondvictory(742,12,1016,50,[40,40,40])
|
|
||||||
glColor3ub(255,0,0)
|
|
||||||
pic_levels2.blit(ele['coordx'],ele['coordy']/768.0*win.height)
|
|
||||||
glColor3ub(255,255,255)
|
glColor3ub(255,255,255)
|
||||||
if items[int("0x40000",16)+i] not in finished and not (ele['world']==0 and ele['grid']==0):
|
if ele['cout']>0:
|
||||||
pic_locked.blit(ele['coordx']+10,ele['coordy']/768.0*win.height+10)
|
items['cout']['icon'].blit(740,110)
|
||||||
txt_element2.text=ele['element']
|
txt_cout2.text=str(ele['cout'])
|
||||||
txt_element2.x=ele['coordx']+50
|
txt_cout2.draw()
|
||||||
txt_element2.y=ele['coordy']/768.0*win.height+67
|
if ele['maxcycle']<90000:
|
||||||
txt_element2.color=(int(ele['coordx']/1024.0*150), int(ele['coordx']/1024.0*150), int(ele['coordx']/1024.0*150),255)
|
items['cycle']['icon'].blit(740,65)
|
||||||
txt_element2.draw()
|
txt_maxcycle2.text=str(ele['maxcycle'])
|
||||||
calc=(len(ele['nom'])*17-52)/2
|
txt_maxcycle2.draw()
|
||||||
drawsquare(ele['coordx']+35-calc,int(ele['coordy']/768.0*win.height+2),ele['coordx']+42-calc+len(ele['nom'])*17,int(ele['coordy']/768.0*win.height-18),1,[40,int(ele['coordx']/1024.0*135),int(ele['coordx']/1024.0*100)])
|
if ele['tech']>0:
|
||||||
txt_nom2.text=ele['nom'].decode('utf-8')
|
items['tech']['icon'].blit(940,110)
|
||||||
txt_nom2.x=ele['coordx']+38-calc
|
txt_tech2.text=str(ele['tech'])
|
||||||
txt_nom2.y=ele['coordy']/768.0*win.height-15
|
txt_tech2.draw()
|
||||||
txt_nom2.color=acolor
|
if ele['maxrayon']<90000:
|
||||||
txt_nom2.draw()
|
items['rayon']['icon'].blit(940,65)
|
||||||
|
txt_maxrayon2.text=str(ele['maxrayon'])
|
||||||
|
txt_maxrayon2.draw()
|
||||||
|
if ele['maxtemp']<90000:
|
||||||
|
items['temp']['icon'].blit(850,110)
|
||||||
|
txt_maxtemp2.text=str(ele['maxtemp'])
|
||||||
|
txt_maxtemp2.draw()
|
||||||
|
if ele['maxnrj']<90000:
|
||||||
|
items['nrj']['icon'].blit(850,65)
|
||||||
|
txt_maxnrj2.text=str(ele['maxnrj'])
|
||||||
|
txt_maxnrj2.draw()
|
||||||
|
victory=ele['victory']
|
||||||
|
drawcondvictory(742,12,1016,50,[40,40,40])
|
||||||
|
glColor3ub(255,0,0)
|
||||||
|
pic_levels2.blit(ele['_xx'],ele['_yy']/768.0*win.height)
|
||||||
|
glColor3ub(255,255,255)
|
||||||
|
if (world,l) not in finished:
|
||||||
|
pic_locked.blit(ele['_xx']+10,ele['_yy']/768.0*win.height+10)
|
||||||
|
txt_element2.text=ele['element']
|
||||||
|
txt_element2.x=ele['_xx']+50
|
||||||
|
txt_element2.y=ele['_yy']/768.0*win.height+67
|
||||||
|
txt_element2.color=(int(ele['_xx']/1024.0*150), int(ele['_xx']/1024.0*150), int(ele['_xx']/1024.0*150),255)
|
||||||
|
txt_element2.draw()
|
||||||
|
calc=(len(ele['nom'])*17-52)/2
|
||||||
|
drawsquare(ele['_xx']+35-calc,int(ele['_yy']/768.0*win.height+2),ele['_xx']+42-calc+len(ele['nom'])*17,int(ele['_yy']/768.0*win.height-18),1,[40,int(ele['_xx']/1024.0*135),int(ele['_xx']/1024.0*100)])
|
||||||
|
txt_nom2.text=ele['nom'].decode('utf-8')
|
||||||
|
txt_nom2.x=ele['_xx']+38-calc
|
||||||
|
txt_nom2.y=ele['_yy']/768.0*win.height-15
|
||||||
|
txt_nom2.color=acolor
|
||||||
|
txt_nom2.draw()
|
||||||
|
|
||||||
def calc_space(nb,nbtot):
|
def calc_space(nb,nbtot):
|
||||||
global unroll
|
global unroll
|
||||||
|
@ -789,9 +796,9 @@ def drawgrid(zoom):
|
||||||
if art['cat']!=cat:
|
if art['cat']!=cat:
|
||||||
drawsquare(7+i*size,55,8+i*size,55+size,0,[90,90,90])
|
drawsquare(7+i*size,55,8+i*size,55+size,0,[90,90,90])
|
||||||
cat=art['cat']
|
cat=art['cat']
|
||||||
drawsquare(win.width-409,win.height-45,win.width-369,win.height-5,1,[240, int(items['level'+str(world)+'-'+str(level)]['coordx']/1024.0*120+100), int(items['level'+str(world)+'-'+str(level)]['coordx']/1024.0*120+100)])
|
drawsquare(win.width-409,win.height-45,win.width-369,win.height-5,1,[240,int(worlds[world][level]['_xx']/1024.0*120+100), int(worlds[world][level]['_xx']/1024.0*120+100)])
|
||||||
txt_element.text=element
|
txt_element.text=element
|
||||||
txt_element.color=(int(items['level'+str(world)+'-'+str(level)]['coordx']/1024.0*150), int(items['level'+str(world)+'-'+str(level)]['coordx']/1024.0*150), int(items['level'+str(world)+'-'+str(level)]['coordx']/1024.0*150),255)
|
txt_element.color=(int(worlds[world][level]['_xx']/1024.0*150),int(worlds[world][level]['_xx']/1024.0*150), int(worlds[world][level]['_xx']/1024.0*150),255)
|
||||||
txt_element.x=win.width-384-len(element)*10
|
txt_element.x=win.width-384-len(element)*10
|
||||||
txt_element.y=win.height-38
|
txt_element.y=win.height-38
|
||||||
txt_element.draw()
|
txt_element.draw()
|
||||||
|
@ -900,19 +907,14 @@ def drawgrid(zoom):
|
||||||
''' Fonctions liees aux menus '''
|
''' Fonctions liees aux menus '''
|
||||||
|
|
||||||
def settings(dummy1,dummy2,dummy3,dummy4):
|
def settings(dummy1,dummy2,dummy3,dummy4):
|
||||||
global level,sizeworld
|
global level,world
|
||||||
reallystop()
|
reallystop()
|
||||||
for i in range(sizeworld):
|
savelevel(world,level)
|
||||||
ele=items[items[int("0x40000",16)+i]]
|
sync()
|
||||||
if ele['world']==world and ele['grid']==level:
|
|
||||||
writegrid("user/"+ele['file'])
|
|
||||||
level=-2
|
level=-2
|
||||||
|
|
||||||
def raz(dummy1,dummy2,dummy3,dummy4):
|
def raz(dummy1,dummy2,dummy3,dummy4):
|
||||||
for i in range(sizeworld):
|
readlevel(world,level,False)
|
||||||
ele=items[items[int("0x40000",16)+i]]
|
|
||||||
if ele['world']==world and ele['grid']==level:
|
|
||||||
readgrid(ele['file'])
|
|
||||||
|
|
||||||
def speed(x,y,dummy1,dummy2):
|
def speed(x,y,dummy1,dummy2):
|
||||||
global play,zoom
|
global play,zoom
|
||||||
|
@ -965,15 +967,16 @@ def setfiber(x,y,dummy1,dummy2):
|
||||||
infos()
|
infos()
|
||||||
|
|
||||||
def levels(dummy1,dummy2,dummy3,dummy4):
|
def levels(dummy1,dummy2,dummy3,dummy4):
|
||||||
global level,sizeworld
|
global level,world
|
||||||
reallystop()
|
reallystop()
|
||||||
for i in range(sizeworld):
|
savelevel(world,level)
|
||||||
ele=items[items[int("0x40000",16)+i]]
|
sync()
|
||||||
if ele['world']==world and ele['grid']==level:
|
|
||||||
writegrid("user/"+ele['file'])
|
|
||||||
level=-1
|
level=-1
|
||||||
|
|
||||||
def exits(dummy1,dummy2,dummy3,dummy4):
|
def exits(dummy1,dummy2,dummy3,dummy4):
|
||||||
|
if level>=0:
|
||||||
|
savelevel(world,level)
|
||||||
|
sync()
|
||||||
pyglet.app.exit()
|
pyglet.app.exit()
|
||||||
|
|
||||||
def stater(dummy1,dummy2,dummy3,dummy4):
|
def stater(dummy1,dummy2,dummy3,dummy4):
|
||||||
|
@ -1027,16 +1030,17 @@ def zoomp(x,y,dummy1,dummy2):
|
||||||
''' Fonctions gestion du monde '''
|
''' Fonctions gestion du monde '''
|
||||||
|
|
||||||
def reallystop():
|
def reallystop():
|
||||||
global play,sizeworld,level,stat,stat_var
|
global play,world,level,stat,stat_var,current,cycle,temp,nrj,rayon
|
||||||
items[items['run']['value']]='stop'
|
items[items['run']['value']]='stop'
|
||||||
play=0
|
play=0
|
||||||
clock.unschedule(calculate)
|
clock.unschedule(calculate)
|
||||||
for i in range(sizeworld):
|
current=worlds[world][level]['current']
|
||||||
ele=items[items[int("0x40000",16)+i]]
|
cycle=worlds[world][level]['cycle']
|
||||||
if ele['world']==world and ele['grid']==level:
|
temp=worlds[world][level]['temp']
|
||||||
readcondgrid(ele['file'])
|
nrj=worlds[world][level]['nrj']
|
||||||
erase()
|
rayon=worlds[world][level]['rayon']
|
||||||
retriern()
|
erase()
|
||||||
|
retriern()
|
||||||
stat=[0,0,0,0,0,0,0,0,0]
|
stat=[0,0,0,0,0,0,0,0,0]
|
||||||
stat_var=[]
|
stat_var=[]
|
||||||
if len(stat_var)==0:
|
if len(stat_var)==0:
|
||||||
|
@ -1044,7 +1048,7 @@ def reallystop():
|
||||||
stat_var.append([0])
|
stat_var.append([0])
|
||||||
|
|
||||||
def reallyrun():
|
def reallyrun():
|
||||||
global play,sizeworld
|
global play
|
||||||
play=0.15625
|
play=0.15625
|
||||||
items[items['run']['value']]='run'
|
items[items['run']['value']]='run'
|
||||||
clock.schedule_interval(calculate,play)
|
clock.schedule_interval(calculate,play)
|
||||||
|
@ -1086,27 +1090,19 @@ def swap():
|
||||||
adirection[7]=bdirection[0]
|
adirection[7]=bdirection[0]
|
||||||
|
|
||||||
def gameover_ok():
|
def gameover_ok():
|
||||||
global over,level,sizeworld
|
global level,world
|
||||||
reallystop()
|
reallystop()
|
||||||
for i in range(sizeworld):
|
savelevel(world,level)
|
||||||
ele=items[items[int("0x40000",16)+i]]
|
sync()
|
||||||
if ele['world']==world and ele['grid']==level:
|
|
||||||
readcondgrid(ele['file'])
|
|
||||||
erase()
|
|
||||||
writegrid("user/"+ele['file'])
|
|
||||||
clock.schedule_once(menu,2,level)
|
clock.schedule_once(menu,2,level)
|
||||||
|
|
||||||
def itsvictory_ok():
|
def itsvictory_ok():
|
||||||
global over,level,finished,sizeworld
|
global world,level,finished
|
||||||
reallystop()
|
reallystop()
|
||||||
for i in range(sizeworld):
|
finished.extend(worlds[world][level]['link'])
|
||||||
ele=items[items[int("0x40000",16)+i]]
|
finished=list(set(finished))
|
||||||
if ele['world']==world and ele['grid']==level:
|
savelevel(world,level)
|
||||||
readcondgrid(ele['file'])
|
sync()
|
||||||
erase()
|
|
||||||
writegrid("user/"+ele['file'])
|
|
||||||
finished.extend(ele['validate'])
|
|
||||||
writepref('user/pref.dat')
|
|
||||||
clock.schedule_once(menu,2,-1)
|
clock.schedule_once(menu,2,-1)
|
||||||
|
|
||||||
def gameover(x):
|
def gameover(x):
|
||||||
|
@ -1427,7 +1423,7 @@ win = pyglet.window.Window(width=1024, height=768,resizable=True, visible=True)
|
||||||
win.set_minimum_size(1024, 768)
|
win.set_minimum_size(1024, 768)
|
||||||
'''win = pyglet.window.Window(fullscreen=True,resizable=True)'''
|
'''win = pyglet.window.Window(fullscreen=True,resizable=True)'''
|
||||||
|
|
||||||
initgrid(30,20)
|
initgrid()
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
'''glEnable(GL_LINE_SMOOTH);
|
'''glEnable(GL_LINE_SMOOTH);
|
||||||
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);'''
|
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);'''
|
||||||
|
@ -1482,11 +1478,7 @@ txt_world=pyglet.text.Label("World",font_name='OpenDyslexicAlta',font_size=30,x=
|
||||||
txt_temp=pyglet.text.Label("",font_name='Mechanihan',font_size=20,x=0,y=0,bold=False,italic=False,color=(180, 180, 180,255))
|
txt_temp=pyglet.text.Label("",font_name='Mechanihan',font_size=20,x=0,y=0,bold=False,italic=False,color=(180, 180, 180,255))
|
||||||
txt_son=pyglet.text.Label("Reglages du son",font_name='Mechanihan',font_size=30,x=0,y=0,bold=False,italic=False,color=(180, 180, 180,255))
|
txt_son=pyglet.text.Label("Reglages du son",font_name='Mechanihan',font_size=30,x=0,y=0,bold=False,italic=False,color=(180, 180, 180,255))
|
||||||
txt_video=pyglet.text.Label("Options Video",font_name='Mechanihan',font_size=30,x=0,y=0,bold=False,italic=False,color=(180, 180, 180,255))
|
txt_video=pyglet.text.Label("Options Video",font_name='Mechanihan',font_size=30,x=0,y=0,bold=False,italic=False,color=(180, 180, 180,255))
|
||||||
readpref('user/pref.dat')
|
|
||||||
world=0
|
|
||||||
for i in range(sizeworld):
|
|
||||||
if items[int("0x40000",16)+i] in finished and items[items[int("0x40000",16)+i]]['world']>world:
|
|
||||||
world=items[items[int("0x40000",16)+i]]['world']
|
|
||||||
|
|
||||||
''' *********************************************************************************************** '''
|
''' *********************************************************************************************** '''
|
||||||
''' Fonctions evenementielles liees a la fenetre '''
|
''' Fonctions evenementielles liees a la fenetre '''
|
||||||
|
@ -1518,7 +1510,7 @@ def on_key_press(symbol, modifiers):
|
||||||
|
|
||||||
@win.event
|
@win.event
|
||||||
def on_mouse_motion(x, y, dx, dy):
|
def on_mouse_motion(x, y, dx, dy):
|
||||||
global world,selected,allcout,over,level,sizeworld,finished
|
global world,selected,allcout,over,level,worlds,finished
|
||||||
if level>=0:
|
if level>=0:
|
||||||
realx=(x-decx)/zoom
|
realx=(x-decx)/zoom
|
||||||
realy=(y-decy)/zoom
|
realy=(y-decy)/zoom
|
||||||
|
@ -1537,11 +1529,10 @@ def on_mouse_motion(x, y, dx, dy):
|
||||||
allcout[2]=items[items[int("0x30000",16)+i]]
|
allcout[2]=items[items[int("0x30000",16)+i]]
|
||||||
return
|
return
|
||||||
selected=-1
|
selected=-1
|
||||||
for i in range(sizeworld):
|
for l in range(len(worlds[world])):
|
||||||
ele=items[items[int("0x40000",16)+i]]
|
ele=worlds[world][l]
|
||||||
if ele['world']==world:
|
if x>ele['_xx']+20 and x<ele['_xx']+100 and y>ele['_yy']/768.0*win.height+0 and y<ele['_yy']/768.0*win.height+110 and ((world,l) in finished):
|
||||||
if x>ele['coordx']+20 and x<ele['coordx']+100 and y>ele['coordy']/768.0*win.height+0 and y<ele['coordy']/768.0*win.height+110 and (items[ele['value']] in finished or items[ele['value']]=="level0-0"):
|
selected=ele
|
||||||
selected=ele
|
|
||||||
if x>940 and y>win.height-100 and x<1024 and y<win.height:
|
if x>940 and y>win.height-100 and x<1024 and y<win.height:
|
||||||
selected=-2
|
selected=-2
|
||||||
if x>840 and y>150 and x<920 and y<240:
|
if x>840 and y>150 and x<920 and y<240:
|
||||||
|
@ -1591,19 +1582,20 @@ def on_mouse_press(x, y, button, modifiers):
|
||||||
if level<0:
|
if level<0:
|
||||||
if selected==-2:
|
if selected==-2:
|
||||||
pyglet.app.exit()
|
pyglet.app.exit()
|
||||||
elif selected==-4 and world>0:
|
elif selected==-4:
|
||||||
world=world-1
|
if world>0: world=world-1
|
||||||
elif selected==-3 and world<2:
|
elif selected==-3:
|
||||||
world=world+1
|
if world<len(worlds)-1: world=world+1
|
||||||
elif selected>-1:
|
elif selected==-1:
|
||||||
level=selected['grid']
|
return
|
||||||
if readgrid("user/"+selected['file'])==False : readgrid(selected['file'])
|
else:
|
||||||
if selected['tuto']!="":
|
readlevel(selected['world'],selected['level'],True)
|
||||||
player.queue(pyglet.resource.media(selected['tuto']))
|
if selected['video']:
|
||||||
|
player.queue(pyglet.resource.media('movie/level'+str(world)+"-"+str(level)+".mp4"))
|
||||||
player.play()
|
player.play()
|
||||||
ambiance.pause()
|
ambiance.pause()
|
||||||
selected=-1
|
selected=-1
|
||||||
return
|
return
|
||||||
realx=(x-decx)/zoom
|
realx=(x-decx)/zoom
|
||||||
realy=(y-decy)/zoom
|
realy=(y-decy)/zoom
|
||||||
for i in range(15):
|
for i in range(15):
|
||||||
|
|
Loading…
Reference in New Issue