2014-01-17 00:20:59 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
2014-04-10 10:02:37 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
------------------------------------------
|
|
|
|
|
|
|
|
WireChem - The new chemistry game
|
|
|
|
|
|
|
|
Programme principal
|
|
|
|
|
|
|
|
(C) Copyright 2013-2014 Nicolas Hordé
|
|
|
|
Licence GPL V3.0
|
|
|
|
|
|
|
|
------------------------------------------
|
|
|
|
'''
|
2014-05-04 11:44:38 +02:00
|
|
|
import datetime
|
|
|
|
import math
|
2014-01-17 00:20:59 +01:00
|
|
|
import pyglet
|
|
|
|
import copy
|
|
|
|
import csv
|
|
|
|
import random
|
|
|
|
import time
|
|
|
|
import operator
|
2014-03-08 20:23:05 +01:00
|
|
|
import shelve
|
|
|
|
import os
|
2014-05-17 11:50:49 +02:00
|
|
|
import sys
|
2014-01-17 00:20:59 +01:00
|
|
|
from pyglet.gl import *
|
|
|
|
from pyglet.window import mouse
|
|
|
|
from pyglet.window import key
|
|
|
|
from pyglet import clock
|
|
|
|
from pyglet import image
|
2014-03-08 20:23:05 +01:00
|
|
|
from os.path import expanduser
|
2014-01-17 00:20:59 +01:00
|
|
|
|
|
|
|
''' *********************************************************************************************** '''
|
2014-06-05 11:22:41 +02:00
|
|
|
''' Fonctions de chargement '''
|
2014-05-22 20:29:26 +02:00
|
|
|
|
2014-06-05 11:22:41 +02:00
|
|
|
#Enregistre les données utilisateurs
|
2014-05-22 20:29:26 +02:00
|
|
|
def sync():
|
|
|
|
global Uworlds,finished
|
|
|
|
write(gethome()+"/dbdata",["Uworlds","finished"])
|
|
|
|
|
2014-06-05 11:22:41 +02:00
|
|
|
#Vérifie l'existence de la base de donnée utilisateur
|
2014-05-22 20:29:26 +02:00
|
|
|
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()
|
2014-06-05 11:22:41 +02:00
|
|
|
|
|
|
|
#Trouve le chemin vers le repertoire utilisateur
|
2014-05-22 20:29:26 +02:00
|
|
|
def gethome():
|
|
|
|
home = expanduser("~")+"/.wirechem"
|
|
|
|
return home
|
|
|
|
|
2014-06-05 11:22:41 +02:00
|
|
|
#Ecrit les variables spécifiés dans la base selectionnée (utilisateur ou système)
|
2014-05-22 20:29:26 +02:00
|
|
|
def write(afile,var):
|
|
|
|
d=shelve.open(afile,writeback=True)
|
|
|
|
for k in var:
|
|
|
|
d[k]=copy.deepcopy(globals()[k])
|
|
|
|
d.sync()
|
|
|
|
d.close()
|
|
|
|
|
2014-06-05 11:22:41 +02:00
|
|
|
#Lit une base de donnée
|
2014-05-22 20:29:26 +02:00
|
|
|
def read(afile):
|
|
|
|
d=shelve.open(afile,writeback=True)
|
|
|
|
for k in d.keys():
|
|
|
|
globals()[k]=copy.deepcopy(d[k])
|
|
|
|
d.close()
|
|
|
|
|
2014-06-05 11:22:41 +02:00
|
|
|
#Charge le dictionnaire sous forme de variables
|
2014-05-22 20:29:26 +02:00
|
|
|
def load(d):
|
|
|
|
for k in d.keys():
|
|
|
|
if k[0]!="_":
|
|
|
|
globals()[k]=copy.deepcopy(d[k])
|
|
|
|
|
2014-06-05 11:22:41 +02:00
|
|
|
#Référence les variables
|
2014-05-22 20:29:26 +02:00
|
|
|
def reference(var,noms):
|
|
|
|
if len(noms)==2:
|
|
|
|
for y in range(len(var)):
|
|
|
|
for x in range(len(var[y])):
|
|
|
|
var[y][x][noms[0]]=y
|
|
|
|
var[y][x][noms[1]]=x
|
|
|
|
else:
|
|
|
|
for x in range(len(var[y])):
|
|
|
|
var[x][y][noms[0]]=x
|
|
|
|
|
2014-06-05 11:22:41 +02:00
|
|
|
#duplique les références
|
2014-05-22 20:29:26 +02:00
|
|
|
def duplicateref(d):
|
|
|
|
for k in d.keys():
|
|
|
|
d[d[k]['nom']]=d[k]
|
2014-06-04 17:02:25 +02:00
|
|
|
|
2014-06-05 11:22:41 +02:00
|
|
|
|
|
|
|
''' *********************************************************************************************** '''
|
|
|
|
''' Sauvegarde/Restauration '''
|
|
|
|
|
|
|
|
def readlevel(w,l,user):
|
|
|
|
global tuto,worlds,cout,selected,sizex,sizey,stat,tech
|
|
|
|
tuto=''
|
|
|
|
if user:
|
|
|
|
if w<len(Uworlds) and l<len(Uworlds[w]) and Uworlds[w][l].has_key("element"):
|
|
|
|
load(Uworlds[w][l])
|
|
|
|
else:
|
|
|
|
load(worlds[w][l])
|
|
|
|
else:
|
|
|
|
load(worlds[w][l])
|
|
|
|
menus[0][18]['icon']=copy.deepcopy(art['null'])
|
|
|
|
sizex=len(world_new)
|
|
|
|
sizey=len(world_new[0])
|
|
|
|
resize();
|
|
|
|
stat=[0,0,0,0,0,0,0,0,0]
|
|
|
|
over=0
|
|
|
|
infos()
|
|
|
|
|
|
|
|
def savelevel(w,l):
|
|
|
|
global tuto,users,worlds,Uworlds,nom,descriptif,video,link,tech,cout,victory,current,cycle,nrj,rayon,temp,maxcycle,maxnrj,maxrayon,maxtemp,world_new,world_art
|
|
|
|
while len(Uworlds)<=w:
|
|
|
|
Uworlds.append(0)
|
|
|
|
Uworlds[w]=[]
|
|
|
|
while len(Uworlds[w])<=l:
|
|
|
|
Uworlds[w].append({})
|
|
|
|
Uworlds[w][l]={'nom':nom,
|
|
|
|
'element':element,
|
|
|
|
'users':users,
|
|
|
|
'tuto':tuto,
|
|
|
|
'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}
|
|
|
|
|
|
|
|
''' *********************************************************************************************** '''
|
|
|
|
''' Fonction d'initialisation '''
|
|
|
|
|
|
|
|
#initialisation du jeu
|
|
|
|
def init():
|
2014-06-05 16:03:33 +02:00
|
|
|
global worlds,debug,level
|
2014-06-05 11:22:41 +02:00
|
|
|
verifyhome()
|
|
|
|
read("dbdata")
|
|
|
|
read(gethome()+"/dbdata")
|
|
|
|
reference(worlds,['world','level'])
|
|
|
|
reference(Uworlds,['world','level'])
|
|
|
|
if len(sys.argv)>1 and sys.argv[1]=='debug':
|
2014-06-06 19:13:44 +02:00
|
|
|
debug=1
|
|
|
|
elif len(sys.argv)>1 and sys.argv[1]=='edit' :
|
|
|
|
debug=2
|
2014-06-05 11:22:41 +02:00
|
|
|
else:
|
2014-06-06 19:13:44 +02:00
|
|
|
debug=0
|
2014-06-05 11:22:41 +02:00
|
|
|
|
|
|
|
''' *********************************************************************************************** '''
|
|
|
|
''' initialisation '''
|
|
|
|
|
2014-06-06 19:13:44 +02:00
|
|
|
debug=0
|
2014-06-05 11:22:41 +02:00
|
|
|
worlds={}
|
2014-06-05 16:03:33 +02:00
|
|
|
world=level=0
|
2014-06-05 11:22:41 +02:00
|
|
|
init()
|
|
|
|
|
|
|
|
''' *********************************************************************************************** '''
|
|
|
|
''' Classes graphiques '''
|
|
|
|
|
|
|
|
#Bouton sensible a plusieurs évènements
|
2014-06-04 17:02:25 +02:00
|
|
|
class abutton(object):
|
2014-06-04 22:26:06 +02:00
|
|
|
def update(self,dt):
|
|
|
|
try:
|
|
|
|
self.vertex_list.delete()
|
|
|
|
except:
|
|
|
|
foo=0
|
|
|
|
try:
|
|
|
|
self.vertex_list2.delete()
|
|
|
|
except:
|
|
|
|
foo=0
|
|
|
|
try:
|
|
|
|
self.vertex_list3.delete()
|
|
|
|
except:
|
|
|
|
foo=0
|
|
|
|
try:
|
|
|
|
self.sprite.delete()
|
|
|
|
except:
|
|
|
|
foo=0
|
|
|
|
if self.isvisible():
|
|
|
|
if self.typeof=='color':
|
2014-06-06 19:13:44 +02:00
|
|
|
if not self.isactive():
|
|
|
|
color=(self.content[0],self.content[1],self.content[2],127)
|
|
|
|
else:
|
|
|
|
color=(self.content[0],self.content[1],self.content[2],255)
|
2014-06-04 22:26:06 +02:00
|
|
|
self.vertex_list = self.window.batch.add(4,pyglet.gl.GL_QUADS, self.window.p1,
|
2014-06-04 17:02:25 +02:00
|
|
|
('v2i', (self.x, self.y, self.x+self.width, self.y, self.x+self.width, self.y+self.height, self.x, self.y+self.height)),
|
2014-06-04 22:26:06 +02:00
|
|
|
('c4B', color * 4))
|
2014-06-04 17:02:25 +02:00
|
|
|
elif self.typeof=='function':
|
|
|
|
self.vertex_list = eval(self.content)
|
2014-06-04 22:26:06 +02:00
|
|
|
else:
|
|
|
|
if self.typeof=='multicon':
|
|
|
|
image = self.content[self.index]
|
|
|
|
else:
|
|
|
|
image = self.content
|
|
|
|
if self.width==0 or self.height==0:
|
|
|
|
self.width=image.width
|
|
|
|
self.height=image.height
|
|
|
|
self.sprite = pyglet.sprite.Sprite(image, x=self.x, y=self.y, batch=self.window.batch, group=self.window.p1)
|
|
|
|
if self.width/float(self.height) < image.width/float(image.height):
|
|
|
|
self.sprite.scale=float(self.width)/image.width
|
|
|
|
else:
|
|
|
|
self.sprite.scale=float(self.height)/image.height
|
2014-06-06 19:13:44 +02:00
|
|
|
if not self.isactive():
|
|
|
|
self.sprite.color=(60,60,60)
|
|
|
|
else:
|
|
|
|
self.sprite.color=(255,255,255)
|
2014-06-05 11:22:41 +02:00
|
|
|
if type(self.selected) is tuple:
|
|
|
|
color=(self.selected[0],self.selected[1],self.selected[2],255)
|
2014-06-04 22:26:06 +02:00
|
|
|
self.vertex_list2 = self.window.batch.add(4,pyglet.gl.GL_LINE_LOOP, self.window.p2,
|
|
|
|
('v2i', (self.x, self.y, self.x+self.width, self.y, self.x+self.width, self.y+self.height, self.x, self.y+self.height)),
|
|
|
|
('c4B', color * 4))
|
2014-06-06 19:13:44 +02:00
|
|
|
elif type(self.selected) is list and self.isactive():
|
2014-06-05 11:22:41 +02:00
|
|
|
self.sprite.color=(self.selected[0],self.selected[1],self.selected[2])
|
2014-06-04 22:26:06 +02:00
|
|
|
if self.hilite and int(time.time())%2==0:
|
|
|
|
color=(255,0,0,128)
|
|
|
|
self.vertex_list3 = self.window.batch.add(4,pyglet.gl.GL_QUADS, self.window.p2,
|
|
|
|
('v2i', (self.x, self.y, self.x+self.width, self.y, self.x+self.width, self.y+self.height, self.x, self.y+self.height)),
|
|
|
|
('c4B', color * 4))
|
2014-06-04 17:02:25 +02:00
|
|
|
|
2014-06-05 11:22:41 +02:00
|
|
|
def __init__(self, window, name, x, y, width, height , active, hilite, visible, selected, content, hint, typeof, text, text2):
|
2014-06-04 17:02:25 +02:00
|
|
|
self.name=name
|
|
|
|
self.index=0
|
2014-06-05 11:22:41 +02:00
|
|
|
self.enter=0
|
2014-06-04 17:02:25 +02:00
|
|
|
self.x=x
|
|
|
|
self.y=y
|
|
|
|
self.width=width
|
|
|
|
self.height=height
|
|
|
|
self.active=active
|
|
|
|
self.hilite=hilite
|
|
|
|
self.visible=visible
|
|
|
|
self.content=content
|
|
|
|
self.typeof=typeof
|
|
|
|
self.hint=hint
|
2014-06-05 11:22:41 +02:00
|
|
|
self.selected=selected
|
2014-06-04 17:02:25 +02:00
|
|
|
self.window=window
|
|
|
|
self.window.push_handlers(self.on_mouse_press)
|
|
|
|
self.window.push_handlers(self.on_mouse_motion)
|
|
|
|
self.window.push_handlers(self.on_mouse_drag)
|
|
|
|
self.window.push_handlers(self.on_mouse_release)
|
2014-06-04 22:26:06 +02:00
|
|
|
self.window.push_handlers(self.on_mouse_scroll)
|
|
|
|
self.updateclock=clock.schedule_interval(self.update,1)
|
|
|
|
self.update(0)
|
2014-06-04 17:02:25 +02:00
|
|
|
|
|
|
|
def delete(self):
|
|
|
|
self.vertex_list.delete()
|
2014-06-04 22:26:06 +02:00
|
|
|
del self
|
|
|
|
self=None
|
2014-06-04 17:02:25 +02:00
|
|
|
|
2014-06-05 16:03:33 +02:00
|
|
|
|
|
|
|
def launch(self,state):
|
2014-06-06 19:13:44 +02:00
|
|
|
global debug
|
2014-06-05 16:03:33 +02:00
|
|
|
name=self.name.split('_')
|
|
|
|
if len(name)>1 and hasattr(self.window, "on_mouse_"+state['event']+"_"+name[0]) and callable(eval("self.window.on_mouse_"+state['event']+"_"+name[0])):
|
2014-06-06 19:13:44 +02:00
|
|
|
eval("self.window.on_mouse_"+state['event']+"_"+name[0]+"("+str(name[1])+","+str(state)+")")
|
|
|
|
if debug>0: print state
|
2014-06-05 16:03:33 +02:00
|
|
|
if hasattr(self.window, "on_mouse_"+state['event']+"_"+self.name) and callable(eval("self.window.on_mouse_"+state['event']+"_"+self.name)):
|
|
|
|
if self.typeof=='multicon':
|
|
|
|
self.index+=1
|
|
|
|
if self.index>=len(self.content):
|
|
|
|
self.index=0
|
|
|
|
self.update(0)
|
|
|
|
eval("self.window.on_mouse_"+state['event']+"_"+self.name+"("+str(state)+")")
|
2014-06-06 19:13:44 +02:00
|
|
|
if debug>0: print state
|
2014-06-05 16:03:33 +02:00
|
|
|
|
2014-06-04 17:02:25 +02:00
|
|
|
def on_mouse_press(self, x, y, button, modifiers):
|
|
|
|
if x>self.x and y>self.y and x<self.x+self.width and y<self.y+self.height and self.isactive() and self.isvisible():
|
2014-06-05 16:03:33 +02:00
|
|
|
state={'x':x,'y':y, 'dx':0, 'dy':0, 'buttons':button, 'modifiers':modifiers, 'event': 'press'}
|
|
|
|
self.launch(state)
|
2014-06-04 17:02:25 +02:00
|
|
|
|
|
|
|
def on_mouse_release(self, x, y, button, modifiers):
|
|
|
|
if x>self.x and y>self.y and x<self.x+self.width and y<self.y+self.height and self.isactive() and self.isvisible():
|
2014-06-05 16:03:33 +02:00
|
|
|
state={'x':x,'y':y, 'dx':0, 'dy':0, 'buttons':button, 'modifiers':modifiers, 'event': 'release'}
|
|
|
|
self.launch(state)
|
2014-06-04 17:02:25 +02:00
|
|
|
|
|
|
|
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
|
2014-06-05 16:03:33 +02:00
|
|
|
if x>self.x and y>self.y and x<self.x+self.width and y<self.y+self.height and self.isactive() and self.isvisible():
|
|
|
|
state={'x':x,'y':y, 'dx':dx, 'dy':dy, 'buttons':buttons, 'modifiers':modifiers, 'event': 'drag'}
|
|
|
|
self.launch(state)
|
|
|
|
|
2014-06-04 17:02:25 +02:00
|
|
|
def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
|
2014-06-05 16:03:33 +02:00
|
|
|
if x>self.x and y>self.y and x<self.x+self.width and y<self.y+self.height and self.isactive() and self.isvisible():
|
|
|
|
state={'x':x,'y':y, 'dx':scroll_x, 'dy':scroll_y, 'buttons':0, 'modifiers':0, 'event': 'scroll'}
|
|
|
|
self.launch(state)
|
|
|
|
|
2014-06-04 17:02:25 +02:00
|
|
|
def on_mouse_motion(self, x, y, dx, dy):
|
2014-06-05 11:22:41 +02:00
|
|
|
if x>self.x and y>self.y and x<self.x+self.width and y<self.y+self.height:
|
|
|
|
if self.isvisible() and self.isactive():
|
|
|
|
if self.enter==0:
|
|
|
|
self.enter=1
|
2014-06-05 16:03:33 +02:00
|
|
|
state={'x':x,'y':y, 'dx':dx, 'dy':dy, 'buttons':0, 'modifiers':0, 'event': 'enter'}
|
|
|
|
self.launch(state)
|
|
|
|
state={'x':x,'y':y, 'dx':dx, 'dy':dy, 'buttons':0, 'modifiers':0, 'event': 'motion'}
|
|
|
|
self.launch(state)
|
2014-06-05 11:22:41 +02:00
|
|
|
else:
|
|
|
|
if self.enter==1:
|
|
|
|
self.enter=0
|
|
|
|
state={'x':x,'y':y, 'dx':dx, 'dy':dy, 'buttons':0, 'modifiers':0, 'event': 'leave'}
|
2014-06-05 16:03:33 +02:00
|
|
|
self.launch(state)
|
2014-06-05 11:22:41 +02:00
|
|
|
|
|
|
|
def setselected(self,select):
|
|
|
|
self.selected=select
|
|
|
|
self.update(0)
|
2014-06-04 17:02:25 +02:00
|
|
|
|
|
|
|
def isvisible(self):
|
|
|
|
if type(self.visible) is bool:
|
|
|
|
return self.visible
|
|
|
|
else:
|
|
|
|
return eval(self.visible)
|
|
|
|
|
|
|
|
def isactive(self):
|
|
|
|
if type(self.active) is bool:
|
|
|
|
return self.active
|
|
|
|
else:
|
|
|
|
return eval(self.active)
|
|
|
|
|
|
|
|
def ishilite(self):
|
|
|
|
if type(self.hilite) is bool:
|
|
|
|
return self.hilite
|
|
|
|
else:
|
|
|
|
return eval(self.hilite)
|
|
|
|
|
|
|
|
def hide(self):
|
|
|
|
if type(self.visible) is bool:
|
|
|
|
self.visible=False
|
2014-06-04 22:26:06 +02:00
|
|
|
self.update(0)
|
2014-06-04 17:02:25 +02:00
|
|
|
|
|
|
|
def show(self):
|
|
|
|
if type(self.visible) is bool:
|
|
|
|
self.visible=True
|
2014-06-04 22:26:06 +02:00
|
|
|
self.update(0)
|
2014-06-04 17:02:25 +02:00
|
|
|
|
|
|
|
def activate(self):
|
|
|
|
if type(self.active) is bool:
|
|
|
|
self.active=True
|
2014-06-04 22:26:06 +02:00
|
|
|
self.update(0)
|
2014-06-04 17:02:25 +02:00
|
|
|
|
|
|
|
def unactivate(self):
|
|
|
|
if type(self.active) is bool:
|
|
|
|
self.active=False
|
2014-06-04 22:26:06 +02:00
|
|
|
self.update(0)
|
2014-06-04 17:02:25 +02:00
|
|
|
|
2014-06-04 22:26:06 +02:00
|
|
|
def hilitate(self):
|
2014-06-04 17:02:25 +02:00
|
|
|
if type(self.hilite) is bool:
|
|
|
|
self.hilite=True
|
2014-06-04 22:26:06 +02:00
|
|
|
self.update(0)
|
2014-06-04 17:02:25 +02:00
|
|
|
|
2014-06-04 22:26:06 +02:00
|
|
|
def unhilitate(self):
|
2014-06-04 17:02:25 +02:00
|
|
|
if type(self.hilite) is bool:
|
|
|
|
self.hilite=False
|
2014-06-04 22:26:06 +02:00
|
|
|
self.update(0)
|
2014-06-04 17:02:25 +02:00
|
|
|
|
2014-05-22 20:29:26 +02:00
|
|
|
|
|
|
|
''' *********************************************************************************************** '''
|
|
|
|
''' Gestion du plateau de jeu '''
|
|
|
|
|
2014-06-05 11:22:41 +02:00
|
|
|
#Classe du plateau de jeu
|
2014-05-22 20:29:26 +02:00
|
|
|
class game(pyglet.window.Window):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(game, self).__init__(resizable=True, fullscreen=False, visible=True, caption="Wirechem: The new chemistry game")
|
|
|
|
self.batch = pyglet.graphics.Batch()
|
|
|
|
self.clocks=[clock.schedule(self.draw)]
|
|
|
|
self.labels = []
|
|
|
|
|
|
|
|
def draw(self,dt):
|
|
|
|
glClearColor(0,0,0,255)
|
|
|
|
self.clear()
|
|
|
|
|
|
|
|
''' *********************************************************************************************** '''
|
2014-06-04 22:26:06 +02:00
|
|
|
''' Gestion du menu principal '''
|
2014-01-17 00:20:59 +01:00
|
|
|
|
2014-06-05 11:22:41 +02:00
|
|
|
#Classe du menu principal
|
2014-05-22 20:29:26 +02:00
|
|
|
class menu(pyglet.window.Window):
|
|
|
|
def __init__(self, *args, **kwargs):
|
2014-06-05 16:03:33 +02:00
|
|
|
global debug,worlds,world
|
2014-06-04 22:26:06 +02:00
|
|
|
super(menu, self).__init__(width=1024, height=768, resizable=True, fullscreen=False, visible=True, caption="Wirechem: The new chemistry game")
|
2014-05-22 20:29:26 +02:00
|
|
|
self.batch = pyglet.graphics.Batch()
|
2014-06-04 22:26:06 +02:00
|
|
|
self.p0 = pyglet.graphics.OrderedGroup(0)
|
|
|
|
self.p1 = pyglet.graphics.OrderedGroup(1)
|
|
|
|
self.p2 = pyglet.graphics.OrderedGroup(2)
|
|
|
|
self.p3 = pyglet.graphics.OrderedGroup(3)
|
2014-06-06 19:13:44 +02:00
|
|
|
self.p4 = pyglet.graphics.OrderedGroup(4)
|
|
|
|
self.clocks=[clock.schedule(self.draw),clock.schedule_interval(self.movefond,0.03)]
|
2014-06-05 11:22:41 +02:00
|
|
|
self.loc=[0,0,1,1]
|
2014-06-05 16:03:33 +02:00
|
|
|
self.images=[pyglet.image.load('picture/leveler0.png'),pyglet.image.load('picture/leveler1.png'),pyglet.image.load('picture/leveler2.png'),pyglet.image.load('picture/leveler3.png'),pyglet.image.load('picture/leveler4.png')]
|
|
|
|
self.colors=[[0,192,244],[235,118,118],[5,157,60],[215,33,255],[201,209,98]]
|
2014-06-06 19:13:44 +02:00
|
|
|
#self.fond=pyglet.image.TileableTexture.create_for_image(image.load("picture/fond.png"))
|
|
|
|
self.labels=[pyglet.text.Label("",font_name='vademecum',font_size=380,x=0,y=0,bold=False,italic=False,batch=self.batch,group=self.p0,color=(255, 80, 80,230))]
|
|
|
|
self.fond=image.load("picture/fond.png")
|
2014-06-05 16:03:33 +02:00
|
|
|
self.buttons=[
|
|
|
|
abutton(self,'logo',185, self.height-200, 0, 0 , True, False, True, False, pyglet.image.load('picture/logo.png'), 'test', 'icon', '', ''),
|
2014-06-04 22:26:06 +02:00
|
|
|
abutton(self,'logo2',45, self.height-150, 0, 0 , True, False, True, False, pyglet.image.load('picture/logo2.png'), 'test', 'icon', '', ''),
|
2014-06-05 16:03:33 +02:00
|
|
|
abutton(self,'menu_0',840, 150, 0, 0 , True, False, True, False, pyglet.image.load('picture/arrows.png'), 'test', 'icon', '', ''),
|
|
|
|
abutton(self,'menu_1',920, 150, 0, 0 , True, False, True, False, pyglet.image.load('picture/arrows2.png'), 'test', 'icon', '', ''),
|
|
|
|
abutton(self,'menu_2',940, self.height-100, 0, 0 , True, False, True, False, pyglet.image.load('picture/exit2.png'), 'test', 'icon', '', '')
|
|
|
|
]
|
|
|
|
self.levels=[
|
|
|
|
abutton(self,'level_0',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
|
|
|
abutton(self,'level_1',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
|
|
|
abutton(self,'level_2',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
|
|
|
abutton(self,'level_3',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
|
|
|
abutton(self,'level_4',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
|
|
|
abutton(self,'level_5',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
|
|
|
abutton(self,'level_6',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
|
|
|
abutton(self,'level_7',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
|
|
|
abutton(self,'level_8',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
|
|
|
abutton(self,'level_9',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', '')
|
|
|
|
]
|
2014-06-06 19:13:44 +02:00
|
|
|
self.special=pyglet.sprite.Sprite(pyglet.image.load('picture/boss.png'),batch=self.batch, group=self.p4)
|
|
|
|
self.lock=[pyglet.sprite.Sprite(pyglet.image.load('picture/locked.png'),batch=self.batch, group=self.p4) for i in range(9)]
|
|
|
|
self.untitled=[pyglet.text.Label("",font_name='Vademecum',batch=self.batch, group=self.p4, font_size=23,x=0,y=0,bold=False,italic=False,color=(180, 180, 180,255)) for i in range(9)]
|
|
|
|
self.untitled2=[pyglet.text.Label("",font_name='Fluoxetine',batch=self.batch, group=self.p4, font_size=18,x=0,y=0,bold=False,italic=False,color=(255, 255, 255,255)) for i in range(9)]
|
2014-06-05 16:03:33 +02:00
|
|
|
self.update()
|
2014-06-05 11:22:41 +02:00
|
|
|
|
2014-06-06 19:13:44 +02:00
|
|
|
def movefond(self,dt):
|
|
|
|
global loc
|
|
|
|
self.loc[0]+=self.loc[2]
|
|
|
|
self.loc[1]+=self.loc[3]
|
|
|
|
if self.loc[0]>1024:
|
|
|
|
self.loc[2]=-1
|
|
|
|
if self.loc[1]>768:
|
|
|
|
self.loc[3]=-1
|
|
|
|
if self.loc[0]<0:
|
|
|
|
self.loc[2]=1
|
|
|
|
if self.loc[1]<0:
|
|
|
|
self.loc[3]=1
|
|
|
|
|
2014-06-05 16:03:33 +02:00
|
|
|
def update(self):
|
2014-06-06 19:13:44 +02:00
|
|
|
global world,worlds,finished
|
|
|
|
for obj in worlds[world]:
|
|
|
|
if obj.has_key('special'):
|
|
|
|
break
|
|
|
|
self.labels[0].text=obj['element']
|
|
|
|
self.labels[0].color=(self.colors[world][0],self.colors[world][1],self.colors[world][2],100)
|
|
|
|
self.labels[0].x=(1024-self.labels[0].content_width)/2-50
|
|
|
|
self.labels[0].y=75*self.height/768
|
|
|
|
self.labels[0].text=obj['element']
|
2014-06-05 16:03:33 +02:00
|
|
|
for l in range(len(worlds[world])):
|
|
|
|
ele=worlds[world][l]
|
2014-06-06 19:13:44 +02:00
|
|
|
self.levels[l].active=(world,l) in finished
|
2014-06-05 16:03:33 +02:00
|
|
|
self.levels[l].x=ele['_xx']
|
|
|
|
self.levels[l].y=ele['_yy']/768.0*self.height
|
2014-06-06 19:13:44 +02:00
|
|
|
self.levels[l].setselected([255,120+int(ele['_xx']/1024.0*135),155+int(ele['_xx']/1024.0*100)])
|
2014-06-05 16:03:33 +02:00
|
|
|
self.levels[l].content=self.images[world]
|
|
|
|
self.levels[l].update(0)
|
2014-06-06 19:13:44 +02:00
|
|
|
self.untitled[l].text=ele['element']
|
|
|
|
self.untitled[l].x=ele['_xx']+(self.images[world].width-self.untitled[l].content_width)/2
|
|
|
|
self.untitled[l].y=ele['_yy']/768.0*self.height+20
|
|
|
|
self.untitled[l].color=(int(ele['_xx']/1024.0*150), int(ele['_xx']/1024.0*150), int(ele['_xx']/1024.0*150),255)
|
|
|
|
self.untitled2[l].text=ele['nom'].decode('utf-8')
|
|
|
|
self.untitled2[l].x=ele['_xx']-(self.untitled2[l].content_width-self.images[world].width)/2
|
|
|
|
self.untitled2[l].y=ele['_yy']/768.0*self.height-15
|
|
|
|
if (world,l) in finished:
|
|
|
|
self.untitled2[l].color=(255,255,255,255)
|
|
|
|
else:
|
|
|
|
self.untitled2[l].color=(90,90,90,255)
|
|
|
|
self.lock[l].visible=(world,l) not in finished
|
|
|
|
self.lock[l].x=ele['_xx']+10
|
|
|
|
self.lock[l].y=ele['_yy']/768.0*self.height+50
|
|
|
|
if ele['nom']==obj['nom']:
|
|
|
|
self.special.x=ele['_xx']
|
|
|
|
self.special.y=ele['_yy']
|
|
|
|
|
2014-05-22 20:29:26 +02:00
|
|
|
def draw(self,dt):
|
2014-06-06 19:13:44 +02:00
|
|
|
global loc
|
2014-05-22 20:29:26 +02:00
|
|
|
glClearColor(0,0,0,255)
|
|
|
|
self.clear()
|
2014-06-06 19:13:44 +02:00
|
|
|
#self.fond.anchor_x=self.loc[0]
|
|
|
|
#self.fond.anchor_y=self.loc[1]
|
|
|
|
self.fond.blit(self.loc[0],self.loc[1])
|
|
|
|
self.fond.blit(self.loc[0]-1024,self.loc[1])
|
|
|
|
self.fond.blit(self.loc[0]-1024,self.loc[1]-768)
|
|
|
|
self.fond.blit(self.loc[0],self.loc[1]-768)
|
|
|
|
#self.fond.blit_tiled(0, 0, 0, self.width, self.height)
|
2014-05-22 20:29:26 +02:00
|
|
|
self.batch.draw()
|
2014-06-04 17:02:25 +02:00
|
|
|
|
2014-06-05 16:03:33 +02:00
|
|
|
def on_mouse_press_menu_2(self, state):
|
2014-06-04 22:26:06 +02:00
|
|
|
pyglet.app.exit()
|
2014-06-04 17:02:25 +02:00
|
|
|
|
2014-06-06 19:13:44 +02:00
|
|
|
def on_mouse_press_menu_1(self, state):
|
|
|
|
global world
|
|
|
|
if world>0: world-=1
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
def on_mouse_press_menu_0(self, state):
|
|
|
|
global world
|
|
|
|
if world<len(worlds)-1: world+=1
|
|
|
|
self.update()
|
|
|
|
|
2014-06-05 16:03:33 +02:00
|
|
|
def on_mouse_enter_menu(self, n, state):
|
|
|
|
self.buttons[2+n].setselected([255,0,0])
|
2014-06-05 11:22:41 +02:00
|
|
|
|
2014-06-05 16:03:33 +02:00
|
|
|
def on_mouse_leave_menu(self, n, state):
|
|
|
|
self.buttons[2+n].setselected(False)
|
2014-06-05 11:22:41 +02:00
|
|
|
|
2014-06-05 16:03:33 +02:00
|
|
|
def on_mouse_enter_level(self, n, state):
|
|
|
|
global world
|
2014-06-06 19:13:44 +02:00
|
|
|
self.levels[n].setselected([255,0,0])
|
|
|
|
self.untitled2[n].color=(255,0,0,255)
|
2014-06-05 16:03:33 +02:00
|
|
|
|
|
|
|
def on_mouse_leave_level(self, n, state):
|
2014-06-06 19:13:44 +02:00
|
|
|
self.levels[n].setselected([255,120+int(self.levels[n].x/1024.0*135),155+int(self.levels[n].x/1024.0*100)])
|
|
|
|
self.untitled2[n].color=(255,255,255,255)
|
2014-06-05 16:03:33 +02:00
|
|
|
|
|
|
|
def on_mouse_press_level(self, n, state):
|
|
|
|
print "level "+str(n)
|
|
|
|
|
2014-05-22 20:29:26 +02:00
|
|
|
''' *********************************************************************************************** '''
|
2014-06-05 11:22:41 +02:00
|
|
|
''' Lancement du menu principal '''
|
2014-06-06 19:13:44 +02:00
|
|
|
|
|
|
|
pyglet.font.add_file('font/Fluoxetine.ttf')
|
|
|
|
pyglet.font.add_file('font/OpenDyslexicAlta.otf')
|
|
|
|
pyglet.font.add_file('font/Mecanihan.ttf')
|
|
|
|
pyglet.font.add_file('font/Vademecum.ttf')
|
|
|
|
pyglet.font.add_file('font/LiberationMono-Regular.ttf')
|
2014-06-04 22:26:06 +02:00
|
|
|
menu_principal = menu()
|
|
|
|
menu_principal.set_minimum_size(1024, 768)
|
2014-05-22 20:29:26 +02:00
|
|
|
glEnable(GL_BLEND);
|
2014-06-04 22:26:06 +02:00
|
|
|
glEnable(GL_LINE_SMOOTH);
|
|
|
|
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
2014-05-22 20:29:26 +02:00
|
|
|
glEnable(GL_LINE_STIPPLE)
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
pyglet.app.run()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-17 00:20:59 +01:00
|
|
|
|