cube_dash2.py

Created by mathieu-croslacoste

Created on September 15, 2025

7.77 KB

cube_dash.py that works. and compressed.


from kandinsky import fill_rect as F,draw_string as D,get_pixel as G,color as C,set_pixel
from ion import keydown as K
from time import monotonic as M,sleep as S
try:from kandinsky import wait_vblank as V
except:V=lambda:S(.1)
W=range
e=0
Stats=[["Sauts","Jumps",[["0 "],["0 "]],0],
["Morts","Deaths ",[["0 "],["0 "]],0],
["Blocs parcourus","Traveled blocks",[["0 "],["0 "]],0]]
Param=[["Langue","Language",(("Francais",),(0,"English ")),0],["Theme sombre",
"Dark theme","o/n",1],["Affichage du FPS","FPS display","o/n",0],
["Version","Version",(("1.0 ",),("1.0 ",)),0]]
def po(x,y,w=1,h=2):F(int(x),int(y),20,20*h,C(0,245,0));F(int(x+4),int(y+4),12,20*h-8,C(0,200,0))
def b(x,y,w=1,h=1):F(int(x),int(y),20*w,20*h,C(245,0,0));F(int(x),int(y),20*w,1,C(245,0,0))
def pl(x,y,w=1,h=1):F(int(x),int(y),20*w,10,C(245,0,0));F(int(x),int(y),20*w,1,C(245,0,0))
def p(x,y,w=1,h=1):F(int(x+6),int(y+2),8,18,(128,)*3);F(int(x+2),int(y+11),16,9,(128,)*3)
def r(x,y,w=1,h=1):F(int(x+6),int(y),8,18,(128,)*3);F(int(x+2),int(y),16,9,(128,)*3)
def dGame(lv,x,ch):
 for a in W(int(x),int(x)+17):
  for y in lv[a]:
   if len(y)==2:y[0]((a-x)*20,222-y[1]*20)
   elif len(y)==3:y[0]((a-x)*20,222-y[1]*20,y[2])
   elif len(y)==4:y[0]((a-x)*20,222-y[1]*20,y[2],y[3])
lv1=((),)*21+(((p,1),),)*2+((),)*5+(((b,1),
),(),(),((b,2,1,2),),(),(),((b,3,1,3),),
((p,1),),((p,1),),((p,1),),((p,1),),(),(),
(),(),((pl,1,5),),(),(),((p,2),),(),((p,1),
),((p,1),),((pl,1,3),))+((),)*4+(((pl,2),
),(),(),((pl,3),),(),(),((pl,4),),(),(),
((pl,5),),(),(),((pl,6),),(),(),((pl,7),),
(),(),((pl,8,3),))+((),)*4+(((pl,9),),
((pl,11,2),),((b,8,5),),((b,11),(r,10)),#
(),((p,
9),),(),(),((pl,7),),(),((pl,6),),(),((pl,
5),),(),((pl,4),),(),((b,3,1,3),),(),((p,
1),),((p,1),),((pl,1,3,1),))+((),)*6+(
((b,2,1,2),(r,4),(b,5)),)+((),)*7+(
(),(),((b,2,1,2),(r,4),(b,5)),(),((p,1),),
((pl,2,4),),(),(),((p,3),),(),(),((pl,1,4),
))+((),)*5+(((po,3,1,3),(p,4)),)+((),)*7+(
((p,1),),)+((),)*4+(((b,2,
1,2),),)+((),)*15+(((b,1),),(),((b,2,1,2),),(),((b,3,
1,3),),(),(),(),((b,11.25,1,8),),((b,4.25,
5),),((p,1),),((p,1),),((p,1),),((p,1),),
)+((),)*10+(((p,1),),((p,
1),),((b,2,1,2),),)+((),)*4+(((b,6,1,10),
),((pl,6,4),),(),((p,7),),(),((pl,6,4),),
(),((p,7),),)+((),)*6+(((b,11,1,6),
(pl,5),(pl,3,6)),(),(),(),((po,5),(b,11,1,
6)),(),((p,1),),((p,1),),((p,1),),((p,1),),
((p,1),),(),(),(),((pl,1),),(),(),((pl,2),
),(),(),((pl,3),),(),(),((pl,4),),(),(),
((pl,5),),(),(),((pl,6,5),),(),((p,7),),
((pl,8,2),),(),((p,7),(pl,6,5)),)+((),)*4+(
((pl,6,5),(p,7)),((pl,8,2),),(),((p,7),
),(),((pl,6,3),),(),((p,7),),((p,5),(pl,4,
5)),(),(),(),((p,5),),(),(),((pl,3,4),(b,3,
1,3)),)+((),)*12
def game(lv=lv1,x=0):
 global Stats,e;e+=1;t=.05;F(0,0,320,2,(250,180,0));c=[C(255/(Param[1][3]+1),0,255/(Param[1][3]+1)),"w"];F(0,2,320,220,c[0]);mode=1;D(["Essai n°","Attempt "][Param[0][3]]+str(e),0,2,c[1],c[0])
 for y in W(2,212):F(150,y,20,20,"b");S(.0025);F(150,y,20,20,c[0])
 onground=1;end=0;change=0;fps=20;hj=9;y=202;jump=1;t1=M();t2=M();start=M();ch=c[0]
 while 1:
  st=M();t/=1.0002;x+=.28;onground=0;hight=0;F(0,0,320,2,(250,180,0));F(0,2,320,220,c[0]);D(["Essai n°","Attempt "][Param[0][3]]+str(e),0,2,c[1],c[0]);prct=(x/(len(lv)-15))*100;D(str(prct)[:4]+"%",245,12,c[1],c[0]);F(208,2,104,10,(200,150,200));F(210,4,int(prct),6,"orange")
  if mode==1:F(150,int(y),20,20,"b")
  else:F(150,int(y)+6,20,11,(100,100,255));F(155,int(y),10,10,"b");F(155,int(y)+16,10,4,(100,100,255))
  try:dGame(lv,x,ch)
  except KeyboardInterrupt:raise TypeError(str(x))
  except IndexError:F(0,0,320,222,c[0]);D(["Vous avez termine le niveau !","      Level completed!"][Param[0][3]],17,102,c[1],c[0]);Stats[2][2]=[[str(int(Stats[2][2][0][0][:-1])+int(x))+" "]]*2;S(1);break
  except TypeError:print(x);raise
  if Param[2][3]:D(str(fps)[:5]+" FPS"[:5],0,25,c[1],c[0]);fps=1/(M()-t1);t1=M()
  for i in W(0,20):
   if G(150+i,int(y)-1)==(96,100,96)or G(150+i,int(y)+20)==3*(128,)or G(170,int(y)+i)==3*(128,):end=1
   elif G(150+i,int(y)+20)!=ch:onground=1
   elif G(150+i,int(y)-1)!=ch:hight=1
   if G(150+i,int(y)-1)==(248,0,0)or G(150+i,int(y)+20)==(248,0,0)or G(170,int(y)+i)==(248,0,0):end=1
   elif G(170,int(y)+i)==(0,244,0):change=1
  if end:
   if mode==1:F(150,int(y),20,20,"b")
   else:F(150,int(y)+6,20,11,(100,100,255));F(155,int(y),10,10,"b");F(155,int(y)+16,10,4,(100,100,255))
   Stats[1][2]=[[str(int(Stats[1][2][0][0][:-1])+1)+" "]]*2;Stats[2][2]=[[str(int(Stats[2][2][0][0][:-1])+int(x))+" "]]*2;break
  if change:mode=abs(mode-3);x+=1.12;y-=10;change=0
  if K(1)or K(4)or K(52):
   if 1-jump and onground and mode==1:jump=1;hj=9;Stats[0][2]=[[str(int(Stats[0][2][0][0][:-1])+1)+" "]]*2
   elif mode==2 and 1-hight:y-=10
  if jump and 1-end:y-=hj/1.8*2;hj-=1;jump=bool(hj)
  if hj==1:y+=1
  if hj==8:y-=1
  if(onground or end or jump)^1:y+=10/mode
  if K(13):S(.5)
  if K(3):
   D("PAUSE",135,102,c[1],c[0])
   while K(3):0
   while(K(3)|K(17))^1:0
   while K(3):0
   if K(17):raise KeyboardInterrupt
  while M()-st<t:0
 S(.5)
 if end:
  while y<=222:F(150,int(y),20,20,"b");S(.0125);F(150,int(y),20,20,c[0]);y+=10
  F(0,2,320,220,c[0]);return prct
def dMenu(m,sel,lst,lg):
 tstd=222/len(lst);c1=(255*m,)*3;c2=(100+100*m,)*3;c3=(255*abs(m-1),)*3;F(0,0,100,222,c1);F(100,0,1,222,c2);i=0
 if sel+1:F(0,int(sel*tstd),100,int(tstd),c2)
 for y in W(int((tstd-18)/2),222,int(tstd)):D(lst[i][lg],0,y,c3,c1);i+=1
 if sel+1:D(lst[sel][lg],0,int((int(tstd)-18)/2+int(tstd)*sel),c3,c2)
def transition(c):
 for x in W(101,320,5):F(x,0,5,222,c);S(.005)
def shop():0
def setts():
 sel=0;m=abs(Param[1][3]-1);lg=Param[0][3];dSetts(m,lg,0);S(.2)
 while 1:
  if K(1)and sel>0:sel-=1;dSetts(m,lg,sel);S(.2)
  elif K(2)and sel<2:sel+=1;dSetts(m,lg,sel);S(.2)
  elif(K(4)or K(52)):Param[sel][3]=abs(Param[sel][3]-1);m=abs(Param[1][3]-1);lg=Param[0][3];dSetts(m,lg,sel);dMenu(m,-1,Liste,lg);S(.2)
  elif K(0):dSetts(m,lg);break
def stats():0
def dPlay(m,lg):F(101,0,219,222,(255*m,)*3)
def dShop(m,lg):c=((255*m,)*3,(100+100*abs(m-1),)*3,(255*abs(m-1),)*3);c4=(100+100*m,)*3;F(101,0,219,222,c[0]);D(("Fonctionnalite en\n\t\t  cours de developpement","Feature in development")[lg],101,92,c[2],c[0]);F(100,0,1,222,c4)
def dSetts(m,lg,sel=-1,lst=Param):
 tstd=222/len(lst);c=[(255*m,)*3,(100+100*abs(m-1),)*3,(255*abs(m-1),)*3];c4=(100+100*m,)*3;F(101,0,219,222,c[0]);n=0
 for y in W(int(tstd/2-9),222,int(tstd)):
  D(lst[n][lg],101,y,c[2],c[0])
  if lst[n][2]=="o/n":
   if lst[n][3]:F(280,y+1,32,16,"orange");F(294,y-2,22,22,c[1])
   else:F(280,y+1,32,16,"gray");F(276,y-2,22,22,c[1])
  else:D(lst[n][2][lg][lst[n][3]],320-len(lst[n][2][lg][lst[n][3]])*10,y,c[1],c[0])
  n+=1
 if sel+1:
  c[0]=c4;n=sel;F(101,int(tstd*n),219,int(tstd),c[0]);y=int(tstd/2-9+tstd*n);D(lst[n][lg],101,y,c[2],c[0])
  if lst[n][2]=="o/n":
   if lst[n][3]:F(280,y+1,32,16,"orange");F(294,y-2,22,22,c[1])
   else:F(280,y+1,32,16,"gray");F(276,y-2,22,22,c[1])
  else:D(lst[n][2][lg][lst[n][3]]+" >",320-len(lst[n][2][lg][lst[n][3]])*10,y,c[1],c[0])
def dStats(m,lg):dSetts(m,lg,lst=Stats)
Liste=(("Jouer","Play",dPlay,game),("Costumes","Skins",dShop,shop),("Parametres","Settings",dSetts,setts),("Stats","Stats",dStats,stats))
def play(m=abs(Param[1][3]-1),lg=Param[0][3]):
 c=((255*m,)*3,(100+100*m,)*3,(100+100*abs(m-1),)*3);liste=Liste;sel=0;dMenu(m,sel,liste,lg);liste[sel][2](m,lg);S(.5)
 while 1:
  try:
   if K(1)and sel:sel-=1;dMenu(m,sel,liste,lg);transition(c[0]);liste[sel][2](m,lg)
   elif K(2)and sel<3:sel+=1;dMenu(m,sel,liste,lg);transition(c[0]);liste[sel][2](m,lg)
   elif K(4)|K(52)|K(3):dMenu(m,-1,liste,lg);liste[sel][3]();m=abs(Param[1][3]-1);lg=Param[0][3];dMenu(m,sel,liste,lg);c=((255*m,)*3,(100+100*m,)*3,(100+100*abs(m-1),)*3);Liste[sel][2](m,lg);S(.2)
   elif K(17):break
  except KeyboardInterrupt:
   t=M()
   while 1:
    try:break
    except:
     if(M()-t)>=1:raise
   m=abs(Param[1][3]-1);lg=Param[0][3];dMenu(m,sel,liste,lg);c=((255*m,)*3,(100+100*m,)*3,(100+100*abs(m-1),)*3);Liste[sel][2](m,lg);S(.2)
play(1)

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.