squaregeometry.py

Created by alexandre-merle

Created on December 30, 2025

10 KB

Une petite copie de geometry dash. J’espère qu’elle vous plaira. Il reste des petits bugs de collisions.


from kandinsky import fill_rect,draw_string,get_pixel
from random import randint as rdt
from time import sleep,monotonic
from ion import *

import micropython as mp
mp.kbd_intr(KEY_BACKSPACE)
KEYS={"start":KEY_OK,"back":KEY_BACK,"up":KEY_UP,"down":KEY_DOWN,"left":KEY_LEFT,"right":KEY_RIGHT}

def keys(k):
  return keydown(KEYS[k])
def wait(k):
  while keys(k):1
def Wait(k):
  while not keys(k):1

MAPS=[[
"111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"000000000000000000000000000000000000000000000000000000000000000001000010000000000000000330300100001000300110004",
"000000000000000000000000000020000000000000000000000000000000000001000030000000000000000000000300003000000110004",
"000000000000000000000000000010000000000000000000020000000000000001000000000000000020000000200000000000000310004",
"000000000000000000002000001000000002000000000050010000000000000001000000000000000010000000100000002000000070004",
"000000000000900000111111103000000001000000005000030000500000000006000020000000000030000000300000003000000070004",
"000000000000000010330000000011000003000001100011000010000500000006000010000000000000000000000200000000000210004",
"000000000000011000000110000000000100000103300033011210022222100001000010000000000000000220200100002000200110004",
"111111111111111111111111115011111111111120022200211111111111111111111111111111111111111111111111111111111111111",
"111111111111111111111111112211111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"],[
"000000000000000000000000000000000000000000000000011111111111111111000000000000000000000000000000000000000000024",
"000000000000000000000000000000000000000000000000011111111111111111000000000000000000000000000000000000000000014",
"000000000000000000000000000000000000010000000000011110110110101111000000000000000000000200000000000000000001004",
"000000000000000000000000000000000000030000000000030130300310301131000000000000000000050100000100000001000100004",
"000000000000000000000000000001000001000000000010000300000030003101000000000000000005000000010001000100010000004",
"000000000000000000000000000003000100000000000060000000000000000301000000000000000500011111000000010001000000004",
"000000000000900005000000000100010000111000000060000000000002000007000000000000050000000000000000030000010001024",
"000000000000000500020050110001000000000011011110020200020001202007000110110111000000000000000000000000000100014",
"000000000000010000011000000000000000000000000000010120011001101021110000000000000000000000000000000000000300014",
"111111111111000000000000000000000000000000000000011111111111111111000000000000000000000000000000000000000000014",
"000000000000000000000000000000000000000000000000011111111111111111000000000000000000000000000000000000000000004",
"000000000000000000000000000000000000000000000000011111111111111111000000000000000000000000000000000000000000004",
"000000000000000000000000000000000000000000000000011111111111111111000000000000000000000000000000000000000000004"],[
"000000000000000000000000000000000000000000000000000211111111111111000000000000000000000000000000000000000000004",
"000000000000000000000000000000000000000000000002000111111111111111000000000000000000000000000000000000000000004",
"000000000000000000000000000000000000000000000001002111111111111111000000000000000000000000000000000000000000004",
"000000000000000000000000000000200000000000000101111111311111300111000000000000000000000000002000000000000000004",
"000000000000000000052000200010101000000000000301300313011130000311000000000000000000000000001000000000002000004",
"000000000000000005001666100030703000000000001003000000030000000031000000000000200000000000000000000000001000004",
"000000000000000500003000301000700000000116613000020000000002177771000000000000100000000000001000010000000000004",
"000000000000050000000000003000100211110310000020010020000201100000000000000010000250000000100011030110001000204",
"000000000005000000001000000020111100000030000010210210002111121111111111011000111101111110000000000000100011104",
"111111111100000000003000200010300000000002000211111110201111111111000000000000000000000000000000000000300000004",
"000000000000000000000011102030000000000001111100000012101111111111000000000000000000000000000000000000000000004",
"000000000000000000000000001000000000000000000000000011111111111111000000000000000000000000000000000000000000004",
"000000000000000000000000000000000000000000000000000011111111111111000000000000000000000000000000000000000000004"]
]
def col_mixer(col1,col2,c1=1,c2=1):return ((col1[0]*c1+col2[0]*c2)//(c1+c2),(col1[1]*c1+col2[1]*c2)//(c1+c2),(col1[2]*c1+col2[2]*c2)//(c1+c2))
font=(0,)*3
solid=(100,)*3
spike=(200,)*3
Plr_c1=(0,0,255)
Plr_c2=(0,0,200)
def DRAW_BLOCKS(n,x,y,l=0,txt=[""],font=font):
  if n=="0":
    fill_rect(x,y,24,24,font)
  if n=="1":
    fill_rect(x,y,24,24,solid)
  if n=="2":
    fill_rect(x,y,24,24,font)
    fill_rect(x+2,y+20,20,4,spike)
    fill_rect(x+4,y+16,16,4,spike)
    fill_rect(x+6,y+12,12,4,spike)
    fill_rect(x+8,y+8,8,4,spike)
    fill_rect(x+10,y+4,4,4,spike)
  if n=="3":
    fill_rect(x,y,24,24,font)
    fill_rect(x+10,y+16,4,4,spike)
    fill_rect(x+8,y+12,8,4,spike)
    fill_rect(x+6,y+8,12,4,spike)
    fill_rect(x+4,y+4,16,4,spike)
    fill_rect(x+2,y,20,4,spike)
  if n=="4":
    fill_rect(x,y,24,24,col_mixer((100,255,100),font,3,1))
  if n=="5":
    fill_rect(x,y,24,24,font)
    fill_rect(x+6,y+6,12,12,col_mixer((255,0,0),font,2,1))
    fill_rect(x+9,y+9,6,6,(255,0,0))
  if n in"67":
    fill_rect(x,y,24,24,col_mixer((180,100,255),font,3,1))
  if n=="9":
    fill_rect(x,y,24,24,font)
    draw_string(txt[0],x-(len(txt[0])-2)*10,y,(255,)*3,font)

def DRAW_MAP(m,x,y,l=0,txt=[""],font=font,S=24,s=[14,10],):
  sy=len(m)
  sx=len(m[0])
  for Y in range(-1,s[1]):#  for Y in range(-1,s[1]-1):
    for X in range(-1,s[0]):
      current_block=m[(Y-(y//S))%sy][(X-(x//S))%sx]
      DRAW_BLOCKS(current_block,(X*S)+(x%S),(Y*S)+(y%S),l,txt,font)

def DRAW_PLAYER(x,y):
    fill_rect(x-6,y-8,12,2,Plr_c1)
    fill_rect(x-8,y-6,2,12,Plr_c1)
    fill_rect(x-6,y+6,12,2,Plr_c1)
    fill_rect(x+6,y-6,2,12,Plr_c1)
    fill_rect(x-6,y-6,12,12,Plr_c2)

class PARTICULE:
  def __init__(self,X=152,Y=126):
    self.x,self.y=X,Y
    self.vx,self.vy=rdt(-8,-6),rdt(-8,-6)
  def draw(self,c=solid):
    fill_rect(self.x,self.y,2,2,c)
  def move(self):
    self.x+=self.vx
    self.y+=self.vy
    self.vy+=4
    return self.y>130

def percentbar(x,y,n,n2,c1,c2):
  fill_rect(x+n,y,200-n,18,c1)
  fill_rect(x,y,n,18,c2)
  N=str(n2)+"%"
  X=(x+100)-(len(N)*5)
  for i in range(len(N)):
    draw_string(N[i],X+i*10,y,(0,)*3,get_pixel(X+5+i*10,y+9))

def GAME(MAP,Attemps=0,font=font):
  running,l=True,0
  X,Y=0,-72
  WINDOW_Y=120
  SPEED=0
  MODE=0
  LENGTH=(len(MAP[0])*24)-170
  YMAX=(len(MAP)*24)-160
  PARTICULES=[]
  while running:
    X-=6
    COOR=[int(160-X)//24,int(WINDOW_Y-Y)//24]
    CurrentTile=MAP[COOR[1]][COOR[0]]
    UpTile=MAP[COOR[1]-1][COOR[0]]
    DownTile=MAP[COOR[1]+1][COOR[0]]
    DRAW_MAP(MAP,int(X),int(Y),l,["Attemps "+str(Attemps)],font)
    DRAW_PLAYER(160,WINDOW_Y)
    percent=abs(X)/LENGTH
    percentbar(60,2,round(percent*200),round(percent*100),(10,200,10),(50,255,50))
    if MODE==0:
      if DownTile=="1":
        PARTICULES.append(PARTICULE())
      try:
        for p in range(len(PARTICULES)):
          P=PARTICULES[p]
          P.draw()
          if P.move():del PARTICULES[p]
      except:1
    pY=Y%24
    SPEED=min(SPEED,16)
    Y-=SPEED
    if MODE==0:
      if CurrentTile in"0235679":
        SPEED+=4
      if DownTile in"1"and SPEED>0 and pY-8-SPEED<=-4:
        SPEED=0
        Y=(Y-((Y+8)%24))+16
      if UpTile in"1"and(pY-8)+SPEED<4 and SPEED<0:
        SPEED=0
        Y=(Y-((Y-8)%24))+8
      if(DownTile in"15"or CurrentTile in"5"or(DownTile in"5"and pY>16))and(keys("start")or keys("up")):
        SPEED=-10
    if MODE==1:
      if DownTile in"1"and SPEED>0 and pY-8<=16:
        SPEED=0
        Y=(Y-((Y+8)%24))+16
      if UpTile in"1"and SPEED<0 and pY-8>=8:
        SPEED=1
        Y=(Y-((Y-8)%24))+8
      if keys("start")or keys("up"):
        SPEED=-6
      else:
        SPEED=6
    if keys("back"):
      wait("back")
      draw_string("Pause",135,102,(255,)*3,get_pixel(160,111))
      Wait("back")
      wait("back")
    if CurrentTile in"1234"or abs(Y)>YMAX:running=False;return round(percent*100)
    if keys("down"):return 0
    if CurrentTile in"6":MODE=1
    if CurrentTile in"7":MODE=0
    sleep(1/90)
    l+=1
  return 0

def lvl_menu(liste):
  name,percent,bg_col=liste[0],liste[1],liste[2]
  write_col=(255,)*3 if bg_col==(0,)*3 else (0,)*3
  fill_rect(0,0,320,222,bg_col)
  fill_rect(159-len(name)*5,59,len(name)*10+2,20,write_col)
  draw_string(name,160-len(name)*5,60,write_col,bg_col)
  percentbar(60,130,percent*2,percent,(10,200,10),(50,255,50))

def menu():
  global MAPS
  MAP_INDEX={"Cave":MAPS[0],"Sky":MAPS[1],"Islands":MAPS[2]}
  Select=0
  Redraw=True
  Lvl_List=[["Cave",0,(0,)*3],["Sky",0,(0,100,200)],["Islands",0,(180,50,0)]]
  Length=len(Lvl_List)
  wait("start")
  while True:
    if Redraw:lvl_menu(Lvl_List[Select]);draw_string(str(Select+1)+"/"+str(len(Lvl_List)),290,204,(0,)*3 if Lvl_List[Select][2]!=(0,)*3 else (255,)*3,Lvl_List[Select][2]);Redraw=False
    if keys("start"):
      lvl_percent=-1
      lvl_attemps=0
      while lvl_percent!=0:
        max_percent=Lvl_List[Select][1]
        lvl_percent=GAME(MAP_INDEX[Lvl_List[Select][0]],lvl_attemps,Lvl_List[Select][2])
        if lvl_percent>max_percent:
          Lvl_List[Select][1]=lvl_percent
        wait("start")
        Wait("start")
        lvl_attemps+=1
      wait("start")
      Redraw=True
    if keys("left"):Select-=1;wait("left");Redraw=True
    elif keys("right"):Select+=1;wait("right");Redraw=True
    Select%=Length
    sleep(1/30)
menu()

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.