-Réindentation du code avec pycharm
-Gestion de l'enregistrement des modification faites dans les champs de texte des niveaux en mode edition.
This commit is contained in:
parent
e082379433
commit
eee0cd6aab
191
WireChem.py
191
WireChem.py
|
@ -15,7 +15,6 @@
|
||||||
'''
|
'''
|
||||||
import datetime
|
import datetime
|
||||||
import math
|
import math
|
||||||
import pyglet
|
|
||||||
import copy
|
import copy
|
||||||
import csv
|
import csv
|
||||||
import random
|
import random
|
||||||
|
@ -24,12 +23,15 @@ import operator
|
||||||
import shelve
|
import shelve
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from os.path import expanduser
|
||||||
|
|
||||||
|
import pyglet
|
||||||
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
|
|
||||||
|
|
||||||
''' *********************************************************************************************** '''
|
''' *********************************************************************************************** '''
|
||||||
''' Fonctions de chargement '''
|
''' Fonctions de chargement '''
|
||||||
|
@ -39,6 +41,7 @@ def sync():
|
||||||
global Uworlds, finished
|
global Uworlds, finished
|
||||||
write(gethome() + "/dbdata", ["Uworlds", "finished"])
|
write(gethome() + "/dbdata", ["Uworlds", "finished"])
|
||||||
|
|
||||||
|
|
||||||
#Vérifie l'existence de la base de donnée utilisateur
|
#Vérifie l'existence de la base de donnée utilisateur
|
||||||
def verifyhome():
|
def verifyhome():
|
||||||
global Uworlds, finished
|
global Uworlds, finished
|
||||||
|
@ -49,11 +52,13 @@ def verifyhome():
|
||||||
finished = [(0, 0)]
|
finished = [(0, 0)]
|
||||||
sync()
|
sync()
|
||||||
|
|
||||||
|
|
||||||
#Trouve le chemin vers le repertoire utilisateur
|
#Trouve le chemin vers le repertoire utilisateur
|
||||||
def gethome():
|
def gethome():
|
||||||
home = expanduser("~") + "/.wirechem"
|
home = expanduser("~") + "/.wirechem"
|
||||||
return home
|
return home
|
||||||
|
|
||||||
|
|
||||||
#Ecrit les variables spécifiés dans la base selectionnée (utilisateur ou système)
|
#Ecrit les variables spécifiés dans la base selectionnée (utilisateur ou système)
|
||||||
def write(afile, var):
|
def write(afile, var):
|
||||||
d = shelve.open(afile, writeback=True)
|
d = shelve.open(afile, writeback=True)
|
||||||
|
@ -62,6 +67,7 @@ def write(afile,var):
|
||||||
d.sync()
|
d.sync()
|
||||||
d.close()
|
d.close()
|
||||||
|
|
||||||
|
|
||||||
#Lit une base de donnée
|
#Lit une base de donnée
|
||||||
def read(afile):
|
def read(afile):
|
||||||
d = shelve.open(afile, writeback=True)
|
d = shelve.open(afile, writeback=True)
|
||||||
|
@ -69,12 +75,14 @@ def read(afile):
|
||||||
globals()[k] = copy.deepcopy(d[k])
|
globals()[k] = copy.deepcopy(d[k])
|
||||||
d.close()
|
d.close()
|
||||||
|
|
||||||
|
|
||||||
#Charge le dictionnaire sous forme de variables
|
#Charge le dictionnaire sous forme de variables
|
||||||
def load(d):
|
def load(d):
|
||||||
for k in d.keys():
|
for k in d.keys():
|
||||||
if k[0] != "_":
|
if k[0] != "_":
|
||||||
globals()[k] = copy.deepcopy(d[k])
|
globals()[k] = copy.deepcopy(d[k])
|
||||||
|
|
||||||
|
|
||||||
#Référence les variables
|
#Référence les variables
|
||||||
def reference(var, noms):
|
def reference(var, noms):
|
||||||
if len(noms) == 2:
|
if len(noms) == 2:
|
||||||
|
@ -86,6 +94,7 @@ def reference(var,noms):
|
||||||
for x in range(len(var[y])):
|
for x in range(len(var[y])):
|
||||||
var[x][y][noms[0]] = x
|
var[x][y][noms[0]] = x
|
||||||
|
|
||||||
|
|
||||||
#duplique les références
|
#duplique les références
|
||||||
def duplicateref(d):
|
def duplicateref(d):
|
||||||
for k in d.keys():
|
for k in d.keys():
|
||||||
|
@ -95,6 +104,7 @@ def duplicateref(d):
|
||||||
''' *********************************************************************************************** '''
|
''' *********************************************************************************************** '''
|
||||||
''' Sauvegarde/Restauration '''
|
''' Sauvegarde/Restauration '''
|
||||||
|
|
||||||
|
|
||||||
def readlevel(w, l, user):
|
def readlevel(w, l, user):
|
||||||
global tuto, worlds, cout, selected, sizex, sizey, stat, tech
|
global tuto, worlds, cout, selected, sizex, sizey, stat, tech
|
||||||
tuto = ''
|
tuto = ''
|
||||||
|
@ -113,6 +123,7 @@ def readlevel(w,l,user):
|
||||||
over = 0
|
over = 0
|
||||||
infos()
|
infos()
|
||||||
|
|
||||||
|
|
||||||
def savelevel(w, l):
|
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
|
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:
|
while len(Uworlds) <= w:
|
||||||
|
@ -146,6 +157,7 @@ def savelevel(w,l):
|
||||||
'world_new': world_new,
|
'world_new': world_new,
|
||||||
'world_art': world_art}
|
'world_art': world_art}
|
||||||
|
|
||||||
|
|
||||||
''' *********************************************************************************************** '''
|
''' *********************************************************************************************** '''
|
||||||
''' Fonction d'initialisation '''
|
''' Fonction d'initialisation '''
|
||||||
|
|
||||||
|
@ -162,6 +174,7 @@ def init():
|
||||||
else:
|
else:
|
||||||
debug = 0
|
debug = 0
|
||||||
|
|
||||||
|
|
||||||
''' *********************************************************************************************** '''
|
''' *********************************************************************************************** '''
|
||||||
''' initialisation '''
|
''' initialisation '''
|
||||||
|
|
||||||
|
@ -178,7 +191,9 @@ init()
|
||||||
class arect(object):
|
class arect(object):
|
||||||
def __init__(self, window, x1, y1, x2, y2, color):
|
def __init__(self, window, x1, y1, x2, y2, color):
|
||||||
self.window = window
|
self.window = window
|
||||||
self.vertex_list = window.batch.add(4, pyglet.gl.GL_QUADS, None,('v2i', [x1, y1, x2, y1, x2, y2, x1, y2]),('c4B', color * 4))
|
self.vertex_list = window.batch.add(4, pyglet.gl.GL_QUADS, None, ('v2i', [x1, y1, x2, y1, x2, y2, x1, y2]),
|
||||||
|
('c4B', color * 4))
|
||||||
|
|
||||||
|
|
||||||
#Classe d'un texte editable
|
#Classe d'un texte editable
|
||||||
class atext(object):
|
class atext(object):
|
||||||
|
@ -189,12 +204,16 @@ class atext(object):
|
||||||
self.text = text
|
self.text = text
|
||||||
self.color = color
|
self.color = color
|
||||||
self.document = pyglet.text.document.UnformattedDocument(text)
|
self.document = pyglet.text.document.UnformattedDocument(text)
|
||||||
self.document.set_style(0, len(self.document.text),dict(font_name=font,font_size=size,color=color,align="center",background_color=(200, 200, 200,0)))
|
self.document.set_style(0, len(self.document.text),
|
||||||
|
dict(font_name=font, font_size=size, color=color, align="center",
|
||||||
|
background_color=(200, 200, 200, 0)))
|
||||||
font = self.document.get_font()
|
font = self.document.get_font()
|
||||||
height = font.ascent - font.descent
|
height = font.ascent - font.descent
|
||||||
self.window = window
|
self.window = window
|
||||||
self.layout = pyglet.text.layout.IncrementalTextLayout(self.document, width, height, multiline=True, batch=self.window.batch, group=self.window.p3)
|
self.layout = pyglet.text.layout.IncrementalTextLayout(self.document, width, height, multiline=True,
|
||||||
|
batch=self.window.batch, group=self.window.p3)
|
||||||
self.layout.document.register_event_type('self.on_insert_text')
|
self.layout.document.register_event_type('self.on_insert_text')
|
||||||
|
self.layout.on_layout_update=self.on_layout_update
|
||||||
self.caret = pyglet.text.caret.Caret(self.layout)
|
self.caret = pyglet.text.caret.Caret(self.layout)
|
||||||
self.caret.visible = False
|
self.caret.visible = False
|
||||||
self.layout.x = self.x
|
self.layout.x = self.x
|
||||||
|
@ -208,14 +227,15 @@ class atext(object):
|
||||||
self.layout.document.set_style(0, len(self.layout.document.text), dict(color=self.color))
|
self.layout.document.set_style(0, len(self.layout.document.text), dict(color=self.color))
|
||||||
self.layout.end_update()
|
self.layout.end_update()
|
||||||
|
|
||||||
def on_insert_text(self,start, text):
|
def on_layout_update(self):
|
||||||
print "*********************"
|
|
||||||
if self.loaded != '':
|
if self.loaded != '':
|
||||||
exec(self.loaded+"='"+self.text+"p'")
|
exec (self.loaded + "='" + self.layout.document.text + "'")
|
||||||
|
self.text=self.layout.document.text
|
||||||
|
|
||||||
def hit_test(self, x, y):
|
def hit_test(self, x, y):
|
||||||
return (0 < x - self.layout.x < self.layout.width and 0 < y - self.layout.y < self.layout.height)
|
return (0 < x - self.layout.x < self.layout.width and 0 < y - self.layout.y < self.layout.height)
|
||||||
|
|
||||||
|
|
||||||
#Bouton sensible a plusieurs évènements
|
#Bouton sensible a plusieurs évènements
|
||||||
class abutton(object):
|
class abutton(object):
|
||||||
def update(self, dt):
|
def update(self, dt):
|
||||||
|
@ -246,7 +266,9 @@ class abutton(object):
|
||||||
else:
|
else:
|
||||||
color = (self.content[0], self.content[1], self.content[2], 255)
|
color = (self.content[0], self.content[1], self.content[2], 255)
|
||||||
self.vertex_list = self.window.batch.add(4, pyglet.gl.GL_QUADS, self.window.p1,
|
self.vertex_list = self.window.batch.add(4, pyglet.gl.GL_QUADS, self.window.p1,
|
||||||
('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)),
|
('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))
|
('c4B', color * 4))
|
||||||
elif self.typeof == 'function':
|
elif self.typeof == 'function':
|
||||||
self.vertex_list = eval(self.content)
|
self.vertex_list = eval(self.content)
|
||||||
|
@ -258,7 +280,8 @@ class abutton(object):
|
||||||
if self.width == 0 or self.height == 0:
|
if self.width == 0 or self.height == 0:
|
||||||
self.width = image.width
|
self.width = image.width
|
||||||
self.height = image.height
|
self.height = image.height
|
||||||
self.sprite = pyglet.sprite.Sprite(image, x=self.x, y=self.y, batch=self.window.batch, group=self.window.p1)
|
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):
|
if self.width / float(self.height) < image.width / float(image.height):
|
||||||
self.sprite.scale = float(self.width) / image.width
|
self.sprite.scale = float(self.width) / image.width
|
||||||
else:
|
else:
|
||||||
|
@ -270,17 +293,22 @@ class abutton(object):
|
||||||
if type(self.selected) is tuple:
|
if type(self.selected) is tuple:
|
||||||
color = (self.selected[0], self.selected[1], self.selected[2], 255)
|
color = (self.selected[0], self.selected[1], self.selected[2], 255)
|
||||||
self.vertex_list2 = self.window.batch.add(4, pyglet.gl.GL_LINE_LOOP, self.window.p2,
|
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)),
|
('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))
|
('c4B', color * 4))
|
||||||
elif type(self.selected) is list and self.isactive():
|
elif type(self.selected) is list and self.isactive():
|
||||||
self.sprite.color = (self.selected[0], self.selected[1], self.selected[2])
|
self.sprite.color = (self.selected[0], self.selected[1], self.selected[2])
|
||||||
if self.hilite and int(time.time()) % 2 == 0:
|
if self.hilite and int(time.time()) % 2 == 0:
|
||||||
color = (255, 0, 0, 128)
|
color = (255, 0, 0, 128)
|
||||||
self.vertex_list3 = self.window.batch.add(4, pyglet.gl.GL_QUADS, self.window.p2,
|
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)),
|
('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))
|
('c4B', color * 4))
|
||||||
|
|
||||||
def __init__(self, window, name, x, y, width, height , active, hilite, visible, selected, content, hint, typeof, text, text2):
|
def __init__(self, window, name, x, y, width, height, active, hilite, visible, selected, content, hint, typeof,
|
||||||
|
text, text2):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.time = 0
|
self.time = 0
|
||||||
self.index = 0
|
self.index = 0
|
||||||
|
@ -315,10 +343,12 @@ class abutton(object):
|
||||||
def launch(self, state):
|
def launch(self, state):
|
||||||
global debug
|
global debug
|
||||||
name = self.name.split('_')
|
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])):
|
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])):
|
||||||
eval("self.window.on_mouse_" + state['event'] + "_" + name[0] + "(" + str(name[1]) + "," + str(state) + ")")
|
eval("self.window.on_mouse_" + state['event'] + "_" + name[0] + "(" + str(name[1]) + "," + str(state) + ")")
|
||||||
#if debug>0: print state,self.name
|
#if debug>0: print state,self.name
|
||||||
if hasattr(self.window, "on_mouse_"+state['event']+"_"+self.name) and callable(eval("self.window.on_mouse_"+state['event']+"_"+self.name)):
|
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':
|
if self.typeof == 'multicon':
|
||||||
self.index += 1
|
self.index += 1
|
||||||
if self.index >= len(self.content):
|
if self.index >= len(self.content):
|
||||||
|
@ -425,7 +455,8 @@ class abutton(object):
|
||||||
#Classe du plateau de jeu
|
#Classe du plateau de jeu
|
||||||
class game(pyglet.window.Window):
|
class game(pyglet.window.Window):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(game, self).__init__(resizable=True, fullscreen=False, visible=True, caption="Wirechem: The new chemistry game")
|
super(game, self).__init__(resizable=True, fullscreen=False, visible=True,
|
||||||
|
caption="Wirechem: The new chemistry game")
|
||||||
self.batch = pyglet.graphics.Batch()
|
self.batch = pyglet.graphics.Batch()
|
||||||
self.clocks = [clock.schedule(self.draw)]
|
self.clocks = [clock.schedule(self.draw)]
|
||||||
self.labels = []
|
self.labels = []
|
||||||
|
@ -434,6 +465,7 @@ class game(pyglet.window.Window):
|
||||||
glClearColor(0, 0, 0, 255)
|
glClearColor(0, 0, 0, 255)
|
||||||
self.clear()
|
self.clear()
|
||||||
|
|
||||||
|
|
||||||
''' *********************************************************************************************** '''
|
''' *********************************************************************************************** '''
|
||||||
''' Gestion du menu principal '''
|
''' Gestion du menu principal '''
|
||||||
|
|
||||||
|
@ -441,9 +473,15 @@ class game(pyglet.window.Window):
|
||||||
class menu(pyglet.window.Window):
|
class menu(pyglet.window.Window):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
global debug, worlds, world
|
global debug, worlds, world
|
||||||
super(menu, self).__init__(width=1024, height=768, resizable=True, fullscreen=False, visible=True, caption="Wirechem: The new chemistry game")
|
super(menu, self).__init__(width=1024, height=768, resizable=True, fullscreen=False, visible=True,
|
||||||
|
caption="Wirechem: The new chemistry game")
|
||||||
self.focus = None
|
self.focus = None
|
||||||
self.cursors = [pyglet.window.ImageMouseCursor(pyglet.image.load('cursor/pointer.png'), 15, 46),pyglet.window.ImageMouseCursor(pyglet.image.load('cursor/text.png'), 24, 30),pyglet.window.ImageMouseCursor(pyglet.image.load('cursor/move.png'), 24, 24),pyglet.window.ImageMouseCursor(pyglet.image.load('cursor/create.png'), 12, 17),pyglet.window.ImageMouseCursor(pyglet.image.load('cursor/cross.png'), 24, 33),pyglet.window.ImageMouseCursor(pyglet.image.load('cursor/delete.png'), 24, 32)]
|
self.cursors = [pyglet.window.ImageMouseCursor(pyglet.image.load('cursor/pointer.png'), 15, 46),
|
||||||
|
pyglet.window.ImageMouseCursor(pyglet.image.load('cursor/text.png'), 24, 30),
|
||||||
|
pyglet.window.ImageMouseCursor(pyglet.image.load('cursor/move.png'), 24, 24),
|
||||||
|
pyglet.window.ImageMouseCursor(pyglet.image.load('cursor/create.png'), 12, 17),
|
||||||
|
pyglet.window.ImageMouseCursor(pyglet.image.load('cursor/cross.png'), 24, 33),
|
||||||
|
pyglet.window.ImageMouseCursor(pyglet.image.load('cursor/delete.png'), 24, 32)]
|
||||||
self.set_mouse_cursor(self.cursors[0])
|
self.set_mouse_cursor(self.cursors[0])
|
||||||
self.batch = pyglet.graphics.Batch()
|
self.batch = pyglet.graphics.Batch()
|
||||||
self.p0 = pyglet.graphics.OrderedGroup(0)
|
self.p0 = pyglet.graphics.OrderedGroup(0)
|
||||||
|
@ -454,36 +492,59 @@ class menu(pyglet.window.Window):
|
||||||
self.clocks = [clock.schedule(self.draw), clock.schedule_interval(self.movefond, 0.03)]
|
self.clocks = [clock.schedule(self.draw), clock.schedule_interval(self.movefond, 0.03)]
|
||||||
self.loc = [0, 0, 1, 1]
|
self.loc = [0, 0, 1, 1]
|
||||||
self.selected = -1
|
self.selected = -1
|
||||||
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.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]]
|
self.colors = [[0, 192, 244], [235, 118, 118], [5, 157, 60], [215, 33, 255], [201, 209, 98]]
|
||||||
self.sizes = [(50, 70), (50, 50), (30, 70), (50, 60), (28, 68)]
|
self.sizes = [(50, 70), (50, 50), (30, 70), (50, 60), (28, 68)]
|
||||||
#self.fond=pyglet.image.TileableTexture.create_for_image(image.load("picture/fond.png"))
|
#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.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")
|
self.fond = image.load("picture/fond.png")
|
||||||
self.buttons = [
|
self.buttons = [
|
||||||
abutton(self,'logo',185, 'self.window.height-200', 0, 0 , True, False, True, False, pyglet.image.load('picture/logo.png'), 'test', 'icon', '', ''),
|
abutton(self, 'logo', 185, 'self.window.height-200', 0, 0, True, False, True, False,
|
||||||
abutton(self,'logo2',45, 'self.window.height-150', 0, 0 , True, False, True, False, pyglet.image.load('picture/logo2.png'), 'test', 'icon', '', ''),
|
pyglet.image.load('picture/logo.png'), 'test', 'icon', '', ''),
|
||||||
abutton(self,'menu_0',840, 150, 0, 0 , True, False, True, False, pyglet.image.load('picture/arrows.png'), 'test', 'icon', '', ''),
|
abutton(self, 'logo2', 45, 'self.window.height-150', 0, 0, True, False, True, False,
|
||||||
abutton(self,'menu_1',920, 150, 0, 0 , True, False, True, False, pyglet.image.load('picture/arrows2.png'), 'test', 'icon', '', ''),
|
pyglet.image.load('picture/logo2.png'), 'test', 'icon', '', ''),
|
||||||
abutton(self,'menu_2',940, 'self.window.height-100', 0, 0 , True, False, True, False, pyglet.image.load('picture/exit2.png'), 'test', 'icon', '', '')
|
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.window.height-100', 0, 0, True, False, True, False,
|
||||||
|
pyglet.image.load('picture/exit2.png'), 'test', 'icon', '', '')
|
||||||
]
|
]
|
||||||
self.levels = [
|
self.levels = [
|
||||||
abutton(self,'level_0',-250, 0, 0, 0 , True, False, True, False, self.images[level], 'test', 'icon', '', ''),
|
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_1', -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_2', -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_3', -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_4', -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', '', ''),
|
''),
|
||||||
abutton(self,'level_10',-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', '',
|
||||||
|
''),
|
||||||
|
abutton(self, 'level_10', -250, 0, 0, 0, True, False, True, False, self.images[level], 'test', 'icon', '',
|
||||||
|
'')
|
||||||
]
|
]
|
||||||
self.untitled2=[atext(self,"text",-300,-300,300,(255, 255, 255,255),'Fluoxetine',18) for i in range(10)]
|
self.untitled2 = [atext(self, "text", -300, -300, 300, (255, 255, 255, 255), 'Fluoxetine', 18) for i in
|
||||||
|
range(10)]
|
||||||
self.untitled = [atext(self, "text", -300, -300, 60, (180, 180, 180, 255), 'Vademecum', 23) for i in range(10)]
|
self.untitled = [atext(self, "text", -300, -300, 60, (180, 180, 180, 255), 'Vademecum', 23) for i in range(10)]
|
||||||
self.special=pyglet.sprite.Sprite(pyglet.image.load('picture/boss.png'),batch=self.batch, group=self.p4,x=-300,y=-300)
|
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,x=-300,y=-300) for i in range(10)]
|
x=-300, y=-300)
|
||||||
|
self.lock = [
|
||||||
|
pyglet.sprite.Sprite(pyglet.image.load('picture/locked.png'), batch=self.batch, group=self.p4, x=-300,
|
||||||
|
y=-300) for i in range(10)]
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def on_resize(self, width, height):
|
def on_resize(self, width, height):
|
||||||
|
@ -532,14 +593,16 @@ class menu(pyglet.window.Window):
|
||||||
self.levels[l].active = (world, l) in finished or debug == 2
|
self.levels[l].active = (world, l) in finished or debug == 2
|
||||||
self.levels[l].x = ele['_xx']
|
self.levels[l].x = ele['_xx']
|
||||||
self.levels[l].y = ele['_yy'] / 768.0 * self.height
|
self.levels[l].y = ele['_yy'] / 768.0 * self.height
|
||||||
self.levels[l].setselected([255,120+int(ele['_xx']/1024.0*135),155+int(ele['_xx']/1024.0*100)])
|
self.levels[l].setselected(
|
||||||
|
[255, 120 + int(ele['_xx'] / 1024.0 * 135), 155 + int(ele['_xx'] / 1024.0 * 100)])
|
||||||
self.levels[l].content = self.images[world]
|
self.levels[l].content = self.images[world]
|
||||||
self.levels[l].update(0)
|
self.levels[l].update(0)
|
||||||
self.untitled[l].text = ele['element']
|
self.untitled[l].text = ele['element']
|
||||||
self.untitled[l].update()
|
|
||||||
self.untitled[l].x = ele['_xx'] + (self.images[world].width - 60) / 2
|
self.untitled[l].x = ele['_xx'] + (self.images[world].width - 60) / 2
|
||||||
self.untitled[l].y = ele['_yy'] / 768.0 * self.height + 18
|
self.untitled[l].y = ele['_yy'] / 768.0 * self.height + 18
|
||||||
self.untitled[l].color=(int(ele['_xx']/1024.0*150), int(ele['_xx']/1024.0*150), int(ele['_xx']/1024.0*150),255)
|
self.untitled[l].loaded = 'worlds[' + str(world) + '][' + str(l) + ']["element"]'
|
||||||
|
self.untitled[l].color = (
|
||||||
|
int(ele['_xx'] / 1024.0 * 150), int(ele['_xx'] / 1024.0 * 150), int(ele['_xx'] / 1024.0 * 150), 255)
|
||||||
self.untitled[l].update()
|
self.untitled[l].update()
|
||||||
self.untitled2[l].text = ele['nom'].decode('utf-8')
|
self.untitled2[l].text = ele['nom'].decode('utf-8')
|
||||||
self.untitled2[l].x = ele['_xx'] + (self.images[world].width - 300) / 2
|
self.untitled2[l].x = ele['_xx'] + (self.images[world].width - 300) / 2
|
||||||
|
@ -564,7 +627,8 @@ class menu(pyglet.window.Window):
|
||||||
if randomize != 0: glLineStipple(random.randint(0, randomize), random.randint(0, 65535))
|
if randomize != 0: glLineStipple(random.randint(0, randomize), random.randint(0, 65535))
|
||||||
glLineWidth(width)
|
glLineWidth(width)
|
||||||
glBegin(GL_LINES)
|
glBegin(GL_LINES)
|
||||||
glColor3ub(min(color[0]+power*width,255),min(color[1]+power*width,255),min(color[2]+power*width,255))
|
glColor3ub(min(color[0] + power * width, 255), min(color[1] + power * width, 255),
|
||||||
|
min(color[2] + power * width, 255))
|
||||||
glVertex2i(x1, y1)
|
glVertex2i(x1, y1)
|
||||||
glVertex2i(x2, y2)
|
glVertex2i(x2, y2)
|
||||||
width = width - 1
|
width = width - 1
|
||||||
|
@ -586,10 +650,13 @@ class menu(pyglet.window.Window):
|
||||||
for ele in worlds[world]:
|
for ele in worlds[world]:
|
||||||
for n in ele['link']:
|
for n in ele['link']:
|
||||||
if world == n[0]:
|
if world == n[0]:
|
||||||
src=(int(ele['_xx']+self.images[0].width/2),int(ele['_yy']/768.0*self.height+self.images[0].height/2))
|
src = (int(ele['_xx'] + self.images[0].width / 2),
|
||||||
dest=(int(worlds[n[0]][n[1]]['_xx']+self.images[0].width/2),int(worlds[n[0]][n[1]]['_yy']/768.0*self.height+self.images[0].height/2))
|
int(ele['_yy'] / 768.0 * self.height + self.images[0].height / 2))
|
||||||
|
dest = (int(worlds[n[0]][n[1]]['_xx'] + self.images[0].width / 2),
|
||||||
|
int(worlds[n[0]][n[1]]['_yy'] / 768.0 * self.height + self.images[0].height / 2))
|
||||||
else:
|
else:
|
||||||
src=(int(ele['_xx']+self.images[0].width/2),int(ele['_yy']/768.0*self.height+self.images[0].height/2))
|
src = (int(ele['_xx'] + self.images[0].width / 2),
|
||||||
|
int(ele['_yy'] / 768.0 * self.height + self.images[0].height / 2))
|
||||||
dest = (int(1024), int(worlds[n[0]][n[1]]['_yy'] / 768.0 * self.height + 50))
|
dest = (int(1024), int(worlds[n[0]][n[1]]['_yy'] / 768.0 * self.height + 50))
|
||||||
if dest[0] - src[0] != 0:
|
if dest[0] - src[0] != 0:
|
||||||
angle = math.atan(float(dest[1] - src[1]) / float(dest[0] - src[0]))
|
angle = math.atan(float(dest[1] - src[1]) / float(dest[0] - src[0]))
|
||||||
|
@ -597,9 +664,11 @@ class menu(pyglet.window.Window):
|
||||||
angle = 270 * 3.14 / 180.0
|
angle = 270 * 3.14 / 180.0
|
||||||
if dest[0] - src[0] < 0:
|
if dest[0] - src[0] < 0:
|
||||||
angle = angle + 180 * 3.14 / 180.0
|
angle = angle + 180 * 3.14 / 180.0
|
||||||
src=(src[0]+int(self.sizes[world][0]*math.cos(angle)),src[1]+int(self.sizes[world][1]*math.sin(angle)))
|
src = (src[0] + int(self.sizes[world][0] * math.cos(angle)),
|
||||||
|
src[1] + int(self.sizes[world][1] * math.sin(angle)))
|
||||||
if world == n[0]:
|
if world == n[0]:
|
||||||
dest=(dest[0]-int(self.sizes[world][0]*math.cos(angle)),dest[1]-int(self.sizes[world][1]*math.sin(angle)))
|
dest = (dest[0] - int(self.sizes[world][0] * math.cos(angle)),
|
||||||
|
dest[1] - int(self.sizes[world][1] * math.sin(angle)))
|
||||||
if n in finished or debug == 2:
|
if n in finished or debug == 2:
|
||||||
params = (random.randint(0, 8), 20, self.colors[world], 12)
|
params = (random.randint(0, 8), 20, self.colors[world], 12)
|
||||||
else:
|
else:
|
||||||
|
@ -612,21 +681,27 @@ class menu(pyglet.window.Window):
|
||||||
angle = 270 * 3.14 / 180.0
|
angle = 270 * 3.14 / 180.0
|
||||||
if dest[0] - src[0] < 0:
|
if dest[0] - src[0] < 0:
|
||||||
angle = angle + 180 * 3.14 / 180.0
|
angle = angle + 180 * 3.14 / 180.0
|
||||||
self.drawLaser(dest[0],dest[1],dest[0]-int(20*math.cos(angle+30*3.14/180)),dest[1]-int(20*math.sin(angle+30*3.14/180)),params[0],params[1],params[2],params[3])
|
self.drawLaser(dest[0], dest[1], dest[0] - int(20 * math.cos(angle + 30 * 3.14 / 180)),
|
||||||
self.drawLaser(dest[0],dest[1],dest[0]-int(20*math.cos(angle-30*3.14/180)),dest[1]-int(20*math.sin(angle-30*3.14/180)),params[0],params[1],params[2],params[3])
|
dest[1] - int(20 * math.sin(angle + 30 * 3.14 / 180)), params[0], params[1],
|
||||||
|
params[2], params[3])
|
||||||
|
self.drawLaser(dest[0], dest[1], dest[0] - int(20 * math.cos(angle - 30 * 3.14 / 180)),
|
||||||
|
dest[1] - int(20 * math.sin(angle - 30 * 3.14 / 180)), params[0], params[1],
|
||||||
|
params[2], params[3])
|
||||||
if world > 0:
|
if world > 0:
|
||||||
for ele in worlds[world - 1]:
|
for ele in worlds[world - 1]:
|
||||||
for n in ele['link']:
|
for n in ele['link']:
|
||||||
if n[0] == world:
|
if n[0] == world:
|
||||||
src = (int(0), int(worlds[n[0]][n[1]]['_yy'] / 768.0 * self.height + self.images[0].height / 2))
|
src = (int(0), int(worlds[n[0]][n[1]]['_yy'] / 768.0 * self.height + self.images[0].height / 2))
|
||||||
dest=(int(worlds[n[0]][n[1]]['_xx']+self.images[0].width/2),int(worlds[n[0]][n[1]]['_yy']/768.0*self.height+self.images[0].height/2))
|
dest = (int(worlds[n[0]][n[1]]['_xx'] + self.images[0].width / 2),
|
||||||
|
int(worlds[n[0]][n[1]]['_yy'] / 768.0 * self.height + self.images[0].height / 2))
|
||||||
if dest[0] - src[0] != 0:
|
if dest[0] - src[0] != 0:
|
||||||
angle = math.atan(float(dest[1] - src[1]) / float(dest[0] - src[0]))
|
angle = math.atan(float(dest[1] - src[1]) / float(dest[0] - src[0]))
|
||||||
else:
|
else:
|
||||||
angle = 270 * 3.14 / 180.0
|
angle = 270 * 3.14 / 180.0
|
||||||
if dest[0] - src[0] < 0:
|
if dest[0] - src[0] < 0:
|
||||||
angle = angle + 180 * 3.14 / 180.0
|
angle = angle + 180 * 3.14 / 180.0
|
||||||
dest=(dest[0]-int(self.sizes[world][0]*math.cos(angle)),dest[1]-int(self.sizes[world][1]*math.sin(angle)))
|
dest = (dest[0] - int(self.sizes[world][0] * math.cos(angle)),
|
||||||
|
dest[1] - int(self.sizes[world][1] * math.sin(angle)))
|
||||||
if n in finished or debug == 2:
|
if n in finished or debug == 2:
|
||||||
params = (random.randint(0, 8), 20, self.colors[world], 12)
|
params = (random.randint(0, 8), 20, self.colors[world], 12)
|
||||||
else:
|
else:
|
||||||
|
@ -635,9 +710,13 @@ class menu(pyglet.window.Window):
|
||||||
|
|
||||||
if type(self.selected) is tuple:
|
if type(self.selected) is tuple:
|
||||||
if self.selected[0] == world:
|
if self.selected[0] == world:
|
||||||
self.drawLaser(int(worlds[self.selected[0]][self.selected[1]]['_xx']+self.images[0].width/2),int(worlds[self.selected[0]][self.selected[1]]['_yy']/768.0*self.height+self.images[0].height/2),int(thex),int(they),random.randint(0,8),20,self.colors[world],12)
|
self.drawLaser(int(worlds[self.selected[0]][self.selected[1]]['_xx'] + self.images[0].width / 2), int(
|
||||||
|
worlds[self.selected[0]][self.selected[1]]['_yy'] / 768.0 * self.height + self.images[
|
||||||
|
0].height / 2), int(thex), int(they), random.randint(0, 8), 20, self.colors[world], 12)
|
||||||
else:
|
else:
|
||||||
self.drawLaser(int(0),int(worlds[self.selected[0]][self.selected[1]]['_yy']/768.0*self.height+self.images[0].height/2),int(thex),int(they),random.randint(0,8),20,self.colors[world],12)
|
self.drawLaser(int(0), int(
|
||||||
|
worlds[self.selected[0]][self.selected[1]]['_yy'] / 768.0 * self.height + self.images[
|
||||||
|
0].height / 2), int(thex), int(they), random.randint(0, 8), 20, self.colors[world], 12)
|
||||||
self.batch.draw()
|
self.batch.draw()
|
||||||
|
|
||||||
### Evenement générer par classe abutton ###
|
### Evenement générer par classe abutton ###
|
||||||
|
@ -728,7 +807,8 @@ class menu(pyglet.window.Window):
|
||||||
self.untitled2[n].update()
|
self.untitled2[n].update()
|
||||||
|
|
||||||
def on_mouse_leave_level(self, n, state):
|
def on_mouse_leave_level(self, n, state):
|
||||||
self.levels[n].setselected([255,120+int(self.levels[n].x/1024.0*135),155+int(self.levels[n].x/1024.0*100)])
|
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)
|
self.untitled2[n].color = (255, 255, 255, 255)
|
||||||
self.untitled2[n].update()
|
self.untitled2[n].update()
|
||||||
|
|
||||||
|
@ -869,6 +949,7 @@ class menu(pyglet.window.Window):
|
||||||
self.focus.caret.mark = 0
|
self.focus.caret.mark = 0
|
||||||
self.focus.caret.position = len(self.focus.document.text)
|
self.focus.caret.position = len(self.focus.document.text)
|
||||||
|
|
||||||
|
|
||||||
''' *********************************************************************************************** '''
|
''' *********************************************************************************************** '''
|
||||||
''' Lancement du menu principal '''
|
''' Lancement du menu principal '''
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue