sandbox_v3.py

Created by mathieu-croslacoste

Created on September 16, 2025

7.26 KB

Sandbox by squarepoint ( https://my.numworks.com/python/squarepoint/sandbox ) with world save. (press [EXE], then paste code in the script, line 64, in saved.)


from kandinsky import fill_rect as s,draw_string as txt
from ion import keydown as k
from time import sleep as P,monotonic as m
from random import randint as r
M2=[]
C=((0,200,200),(0,150,0),(100,)*3,(150,100,0),(0,100,255),(255,100,0),(100,50,0),"g","r",(200,)*3,(100,0,0),(255,120,0),(200,200,150),(200,120,80),(220,180,130),(220,)*3,"g",(255,200,0),(255,200,0),(255,0,255))
N=("Erase","Plant","Rock ","Dirt ","Water","Fire ","Wood ","Tree ","TNT  ","Steel","Ember","Boom ","Human","Fuse ","Sand ","Snow ","Cacti","FBomb","FBoom","NUKE ")
MS=((-2,-4,5,"0111011111111110060000600"),(-1,-2,3,"111111060"),(-2,-6,5,"00100011100060011111006001111100600"),(-2,-2,5,"0555055555555555555505550"),(-1,-1,3,"555555555"),(0,-2,1,"111"),(0,-2,2,"101110"),(-1,-3,3,"010110011010"),(-2,-6,5,"00100001000010110101101100110000100"),(-2,-2,5,"0bbb0bbbbbbbbbbbbbbb0bbb0"))
B,G="w",(150,)*3
def bc(i,x,y):return 1-((i+x)//32!=i//32 or (i+y*32)%32!=i%32 or i+x+y*32>639 or i+x+y*32<0)
def p(i,w,t):
 w=MS[w]
 for j in range(len(w[3])):
  z,mx,my=int(w[3][j],36),j%w[2]+w[0],j//w[2]+w[1];l=i+mx+my*32
  if bc(i,mx,my)and z!=0:
   if t==11:
    if M[l]==9:
     if r(0,3)==0:M[l]=z
    elif M[l]!=8 and M[l]!=17 and M[l]!=19:M[l]=z
   elif t==18:
    if M[l]==9:
     if r(0,2)==0:M[l]=z
    elif M[l]!=8 and M[l]!=17 and M[l]!=19:M[l]=z
   elif t==5:
    if M[l]==1 or M[l]==12:
     if r(0,4)==0:M[l]=z
    elif M[l]==6:
     if r(0,4)==0:M[l]=10
    elif M[l]==8:M[l]=11
    elif M[l]==17:M[l]=18
    elif M[l]==19:n(l)
    elif M[l]==13:M[l]=z
   elif t==10:
    if M[l]==0 or M[l]==1:
     if r(0,10)==0:M[l]=z
   else:M[l]=z
def n(w):
 M[w]=5
 for i in range(21):
  if bc(w,-10+i,1):p(w+22+i,9,18)
 for i in range(7):
  if bc(w,-3+i,2):p(w+61+i,9,18)
  if bc(w,-3+i,-8):p(w-259+i,9,18);p(w-128,9,18)
def convert(i,mode=1):
 add="abcdefghijklmnopqrstuvwxy"
 if mode:
  for count,j in enumerate(add):
   if i==j:return count+10
  return int(i)
 else:return add[i]
try:save=int(input("import saved world ? (0 or 1)\n"))
except:save=0
while k(4):0
s(0,0,320,222,G)
txt("Save maps with [EXE],then copy\nthe code and paste it in\nsaved=[] (in the code,line 175).\nnavigate map with arrow keys.\nPress [OK] to start/place.\nclear/power y to change block.\nShift to go to erase mode.",0,0,"b",G)
while 1-k(4):0
while k(4):0
s(0,0,320,222,(0,200,200))
s(50,30,220,150,B)
txt("Squarepoint's",95,50)
txt("SANDBOX",125,70)
b,kp=0,0
if save:
 saved=("zy0zy0zy0zy0zy0zg01zu0z31zi0z31z906zi0z51z60z51z60z31z70z51z806z80z31z906z80z51z706za06za06z50zw1zy3zy3zy3zq3zy2zy2zs2",
"0zvdzvezydzvezwdzvezydzvezwdzvezydzvezwdzvezydzvezwdzv0dzv8",
"zy0zy0zy0zy0zy0zg01zu0z31zi0z31z906zi0z51z60z51zy0zy0zv04zb14z514zb1414zb34z534zb3434za34z734z934z334z834z934z734z534z634zb34z534z43z324z424zd24z324z924224zf2424zb244zg244",
"zwdzwjzwdzw8zwdzm0cz50czi0cz40cz70ccz30cz60cz70c0c0c00z3c0z3c0c0c0cc0z9c00z7c0c0z5c0c00z4cz40zkczyhzyhzyhzyhzyhzyhzyhzyhzyhzeh")
 if len(saved)==0:print("save maps first");raise Exception("No Saved Map.")
 while 1:
  if k(17):
   if kp==0 or kp>5:b+=1
   kp+=1
  elif k(23):
   if kp==0 or kp>5:b-=1
   kp+=1
  else:kp=0
  if b<0:b=len(saved)-1
  if b>len(saved)-1:b=0
  txt("Saved world #"+str(b+1),80,120)
  if k(4):break
  P(.1)
 M,id,nb=[],0,0
 for i in saved[b]:
  if i=="z":id=1
  elif id==1:nb,id=convert(i),2
  elif id==2:
   for j in range(nb):M.append(convert(i))
   id=0
  else:M.append(convert(i))
 del saved,id
 for i in range(64):M.append(0)
else:
 W=("Empty ","Flat  ","Plains","Desert","Winter")
 while 1:
  if k(17):
   if kp==0 or kp>5:b+=1
   kp+=1
  elif k(23):
   if kp==0 or kp>5:b-=1
   kp+=1
  else:kp=0
  if b<0:b=4
  if b>4:b=0
  txt("World gen: "+W[b],80,120)
  if k(4):
   if b==0:M=[0]*672
   elif b==1:M=[0]*384+[1]*32+[3]*128+[2]*96+[0]*32
   else:
    M,d,e,b1=[0]*608+[2]*32+[0]*32,r(-2,0),r(0,1),2
    if b==3:b2=14
    else:b2=3
    for x in range(32):
     for i in range(0-d):M[576+x-i*32]=b1
     M[576+x+d*32]=b1
     if e==0:M[544+x+d*32]=b1
     else:M[544+x+d*32]=b2
     M[512+x+d*32]=b2;M[480+x+d*32]=b2;M[448+x+d*32]=b2
     if b==2:M[416+x+d*32]=1
     elif b==4:M[416+x+d*32]=15
     if r(0,4)==0:
      if b==3:M[416+x+d*32]=16
      else:M[384+x+d*32]=7
     if r(0,4)==0:e=1-e
     if r(0,4)==0:
      if r(0,1) and d<0:d+=1
      elif d>-2:d-=1
   break
  P(.1)
x,y,b,t,tps=0,0,0,0,0
s(0,0,320,222,G)
t0=m()
while 1:
 if k(4):M[y*32+x]=b
 x,y=(x+k(3)-k(0))%32,(y+k(2)-k(1))%20
 if k(12):b=0
 if k(52):
  oldId,code,nb="","",1
  for i in M:
   if i<10:id=str(i)
   else:id=convert(i-10,0)
   if id==oldId and nb<34:nb+=1
   elif nb>1:
    if nb==2:code+=oldId*2
    elif nb<10:code+="z"+str(nb)+oldId
    else:code+="z"+convert(nb-10,0)+oldId
    nb=1
   else:code+=oldId
   oldId=id
  msg=""
  for i in range(len(code)//219+1):msg+=code[219*i:219*i+min(219,len(code))]+"\n"
  print(msg);del code,nb,msg;txt("saved, press [EXE]",0,0,B,G)
  while k(52):0
  while 1-k(52):0
  while k(52):0
 if k(17):
  if kp==0 or kp>5:b+=1
  kp+=1
 elif k(23):
  if kp==0 or kp>5:b-=1
  kp+=1
 else:kp=0
 if b<0:b=19
 if b>19:b=0
 M2=M.copy()
 for i in range(640):
  if M2[i]==4:
   a=0
   if bc(i,-1,0)and M[i-1]==0:a=-1
   if bc(i,1,0)and M[i+1]==0:
    if a==-1:a=-1+r(0,1)*2
    else:a=1
   if bc(i,-1,1)and M[i+31]==0:a=31
   if bc(i,1,1)and M[i+33]==0:
    if a==31:a=31+r(0,1)*2
    else:a=33
   if bc(i,0,1)and M[i+32]==0:a=32
   if a!=0:M[i+a]=M2[i];M[i]=0
  elif M2[i]==10 or M2[i]==17 or M2[i]==19:
   if M2[i]==10 and r(0,10)==0:M[i]=5
   if bc(i,0,1):
    if M[i+32]==4:
     if r(0,1):
      M[i]=4
      if M2[i]==17 and((M[i+64]!=0 and M[i+64]!=4)or i+64>640):M[i+32]=18
      elif M2[i]==19 and((M[i+64]!=0 and M[i+64]!=4)or i+64>640):n(i+32)
      else:M[i+32]=M2[i]
      M2[i+32]=0
    elif M[i+32]==0:
     M[i]=0
     if M2[i]==17 and((M[i+64]!=0 and M[i+64]!=4)or i+64>640):M[i+32]=18
     elif M2[i]==19 and((M[i+64]!=0 and M[i+64]!=4)or i+64>640):n(i+32)
     else:M[i+32]=M2[i]
  elif M2[i]==8 or M2[i]==14 or M2[i]==15:
   a=0
   if bc(i,-1,1)and(M[i+31]==0 or M[i+31]==4):a=31
   if bc(i,1,1)and(M[i+33]==0 or M[i+33]==4):
    if a==31:a=31+r(0,1)*2
    else:a=33
   if bc(i,0,1)and(M[i+32]==0 or M[i+32]==4):a=32
   if a!=0:
    if M[i+a]==4:
     if r(0,1):M[i]=4;M[i+a]=M2[i];M2[i+a]=0
    else:M[i]=0;M[i+a]=M2[i]
  elif M2[i]==12:
   a=0
   if r(0,4)==0:
    if bc(i,-1,1)and(M[i-33]==0 or M[i-33]==4):a=-33
    if bc(i,1,1)and(M[i-31]==0 or M[i-31]==4):
     if a==-33:a=-33+r(0,1)*2
     else:a=-31
   if bc(i,0,1)and(M[i+32]==0 or M[i+32]==4):a=32
   if M[i-32]==4 and r(0,6)==0:M[i]=0
   if a!=0:
    if M[i+a]==4:
     if r(0,1):M[i]=4;M[i+a]=M2[i];M2[i+a]=0
    else:M[i]=0;M[i+a]=M2[i]
  elif M2[i]==5:
   a=0
   if bc(i,-1,-1)and M[i-33]==0:a=-33
   if bc(i,1,-1)and M[i-31]==0:
    if a==-33:a=-33+r(0,1)*2
    else:a=-31
   if bc(i,0,-1)and M[i-32]==0:
    if a!=0:
     if r(0,1):a=-32
    else:a=-32
   if r(0,3)==0:a=0
   if a!=0:M[i+a]=5
   M[i]=0
  elif M2[i]==3:
   if bc(i,0,-1)and M[i-32]==0 and r(0,200)==0:M[i-32]=1
  if M2[i]==7 or M2[i]==11 or M2[i]==5 or M2[i]==10 or M2[i]==16 or M2[i]==18:
   if M2[i]==7:w=r(0,2)
   elif M2[i]==11:w=3
   elif M2[i]==16:w=r(5,8)
   elif M2[i]==18:w=9
   else:w=4
   p(i,w,M2[i])
 for i in range(640):
  if i%32==x and i//32==y:s(x*10,y*10,10,10,B)
  else:s((i%32)*10,(i//32)*10,10,10,C[M[i]])
 txt("Selected block: "+N[b],10,202,B,G);t+=1
 if m()-t0>1:t0,tps,t=m(),t,0
 txt("FPS: "+str(tps)+" ",240,202,B,G)

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.