labyrinthe.py

Created by stimorol

Created on June 27, 2024

6.93 KB

Jeu du labyrinthe avec beaucoup d’options intégrées, j’ai aussi crée une version plus légère du meme jeu. Un tutoriel est présent a l’intérieur pour vous expliquer les différentes options :D.


from kandinsky import draw_string as txt, fill_rect as rect, get_pixel as get_px, set_pixel as px
from ion import *
from random import *
from time import *

#   SCRIPT MADE BY ARMAND JAMET
#   STARTED 2022 LAST UPDATE : 12.10.22
bgColor='gray'
black=(40,40,40)
green=(0,100,0)
fgreen=(0,175,0)
target=(0,225,0)
Upsilon=(123,162,205)
NW=(255,183,52)
Omega=(193,50,46)
keys=[KEY_UP,KEY_DOWN,KEY_RIGHT,KEY_LEFT]
movementsKey=[-1,1,1,-1]

try:
  from kandinsky import draw_line as line
except:
  def line(x0,y0,x1,y1,color):
    h=((x1-x0)**2+(y1-y0)**2)**0.5
    cos=(x1-x0)/h
    sin=(y1-y0)/h
    for p in range(int(h)+1):
      px(x0+int(cos*p),y0+int(sin*p),color)

def kd(key):
  if keydown(key):
    while keydown(key):pass
    return True
  return False

def menu(elements,title,colors):
  rect(0,0,322,222,colors[2])
  y,stop,select=0,False,0
  sColor=[colors[3]]
  for i in elements:
    sColor.append(colors[1])
  txt(title,(161-len(title)*4),50,colors[0],colors[2])
  for x in range(321):
    line(x,0,x,int(4*uniform(-3.5,3.5)**2)+8,colors[6])
  for i in elements:
    txt(str(i), 160-round(len(i)/2)*8, 100+25*elements.index(i),sColor[elements.index(i)],colors[2])
  while True:
    if keydown(KEY_DOWN) or keydown(KEY_UP):
      if keydown(KEY_UP):select-=1
      else:select+=1
      while keydown(KEY_DOWN) or keydown(KEY_UP):pass
      sColor.clear()
      if select > len(elements)-1: select=0
      elif select < 0: select=len(elements)-1
      for n in range(len(elements)):
        sColor.append(colors[1])
      sColor.insert(select,colors[3])
      for l in elements:
        txt(str(l),160-round(len(l)/2)*8,100+25*elements.index(l),sColor[elements.index(l)],colors[2])
    if kd(KEY_OK):
      return select

def tutoriel(diff,speed,level,colors):
  rect(0,0,322,222,colors[2])
  stop,frame=False,0
  tutorielText=[" Salut ! Je suis le dev du jeu :D.\nLe jeu et ses options sont assez simples,\nmais un tuto est toujous sympa.\nAlors voila:","Le mode normal lance le jeu du\nlabyrinthe. Les controles sont les\nquatres fleches en dessous de l'ecran,\nla touche OK pour utitiser votre capatite:\nvous teleporter de cinq pixels (c'est\nutile) et enfin la touche clear pour\nrevenir au menu.\nLe but du jeu est d'atteindre le cote\ndroit de l'ecran."," Les options jeu permettent de modifier\nle jeu: vous pouvez choisir la vitesse\ndu joueur, la difficulte du labyrinthe et\njouer en mode EXTREME."," Enfin, les options graphiques servent a\nmodifier la couleur du joueur ou le\ntheme de couleur du jeu.\n\n   Voila les bases du jeu: amusez-vous :D!"]
  txt(tutorielText[0],20,30,colors[1],colors[2],1)
  while not stop:
    if kd(KEY_OK):
      if frame==3:  mainMenu(diff,speed,level,colors)
      frame+=1
      rect(0,0,322,222,colors[2])
      txt(tutorielText[frame],20,20,colors[1],colors[2],1)
      sleep(0.75)

def gameSettings(diff,speed,level,colors):
  userSelection=menu(["VITESSE","DIFFICULE","MODE EXTREME"],"OPTION JEU",colors)
  if userSelection==0:speed=(5-menu(["1","2","3","4","5"],"VITESSE",colors))*0.002
  elif userSelection==1:diff=((menu(["1","2","3","4","5"],"DIFFICULTE",colors)+1)*30)
  elif userSelection==2:extreme(90,0,0.0035,colors)
  mainMenu(diff,speed,level,colors)
  
def videoSettings(diff,speed,level,colors):
  userSelection=menu(["COULEUR JOUEUR","THEME"],"OPTIONS VIDEO",colors)
  color=['black','green','red','blue','white']
  if userSelection==0:colorPlayer=color[menu(color,"COULEUR JOUEUR",colors)]
  elif userSelection==1:
    theme=menu(["THEME LABYRINTHE","THEME SOMBRE","THEME CLAIR","THEME OMEGA","THEME UPSILON"],"THEMES",colors)
    colors=[[green,'white','gray',green,'red','black',fgreen], ['gray','gray',black,'white','white','gray',fgreen], ['orange','black','white','orange','orange','black',NW], [Omega,'black','gray',Omega,Omega,'black',Omega], ['blue','black','gray','blue','blue','black',Upsilon]][theme]
  mainMenu(diff,speed,level,colors)
  
def draw_lab(diff,colors,maxx=16,maxy=11,coef=20,lenMurs=60):
  numx,numy=[],[]
  rect(0,0,322,222,colors[2])
  rect(316,0,20,222,target)
  line(0,0,322,0,'black')
  line(0,0,0,222,'black')
  line(0,222,322,222,'black')
  for i in range(diff):
    x, y=randint(1,maxx)*coef, randint(1,maxy)*coef
    numx.append(x)
    line(x,y,x+randint(20,lenMurs),y,colors[5])
    x, y=randint(0,maxx)*coef, randint(0,maxy)*coef
    numy.append(y)
    line(x,y,x,y+randint(20,lenMurs),colors[5])

def labyrinthe(diff,level,speed,colors,maxx=16,maxy=11,coef=20,lenMurs=45):
  draw_lab(diff,colors,maxx,maxy,coef,lenMurs)
  x,y,stop=3,111,False
  txt(str(level),10,10,'black',colors[2])
  rect(x,y,2,2,colors[4])
  startTime=monotonic()
  if player(diff,speed,level,3,111,colors):
    level+=1
    rect(0,0,322,222,colors[2])
    txt("     BRAVO!\n"+str(level)+" NIVEAU(X) REUSSI(S)\n\n   TEMPS:"+str(int(monotonic()-startTime))+"s",80,90,colors[1],colors[2])
    sleep(1.5)
    labyrinthe(diff+1,level,speed,colors)
    return diff

def extreme(diff,level,speed,colors,maxx=16,maxy=11,coef=20,lenMurs=45):
  draw_lab(diff,colors,maxx,maxy,coef,lenMurs)
  x,y,stop=3,111,False
  txt(str(level),10,10,'black',colors[2])
  rect(x,y,2,2,colors[4])
  startTime=monotonic()
  if player(diff,speed,level,3,111,colors,True):
    level+=1
    rect(0,0,322,222,colors[2])
    txt("FELICITATIONS!\n    "+str(level)+" NIVEAU(X) EXTREME REUSSI(S)\n\n   TEMPS:"+str(int(montonic()-startTime))+"s",80,90,colors[1],colors[2])
    sleep(1.25)
    extreme(diff+1,level,speed,colors)

def player(diff,speed,level,x,y,colors,extreme=False):
  stop,power=False,1
  mouvX=mouvY=movementY=0
  movementX=1
  while not stop:
    if extreme == True:
      for i in range(4):
        x+=mouvX
        y+=mouvY
        if get_px(x,y) != (0, 0, 0):px(x,y,colors[4])
        else:
          x-=mouvX
          y-=mouvY
    for i in keys:
      if keydown(KEY_BACKSPACE):
        while keydown(KEY_BACKSPACE):pass
        stop=True
        mainMenu(diff,speed,level,colors)
      if kd(KEY_OK):
        if power>0:
          x+=movementX*5
          y+=movementY*5
          if get_px(x,y) != (0, 0, 0):px(x,y,colors[4])
        power=0
      if keydown(i):
        if extreme==True:
          mouvX=randint(-2,1)
          mouvY=randint(-2,2)
        number=keys.index(i)
        if number>=2:movementX, movementY=movementsKey[number], 0
        elif number<2:movementX, movementY=0, movementsKey[number]
        while keydown(i):
          x+=movementX
          y+=movementY
          if get_px(x,y) != (0, 0, 0):px(x,y,colors[4])
          else:
            x-=movementX
            y-=movementY
          sleep(speed)
        if x > 316:return True

def mainMenu(diff,speed,level,colors=['blue','black','gray','blue','blue','black',Upsilon]):
  userSelect=menu(["NORMAL","OPTIONS JEU","OPTIONS GRAPHIQUES","TUTORIEL"],"LABYRINTHE",colors)
  if userSelect==0:diff=labyrinthe(diff,level,speed,colors)
  elif userSelect==1:gameSettings(diff,speed,level,colors)
  elif userSelect==2:videoSettings(diff,speed,level,colors)
  elif userSelect==3:tutoriel(diff,speed,level,colors)

mainMenu(95,0.0075,0)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.