sandbox.py

Created by squarepoint

Created on May 20, 2024

6.18 KB

SQUAREPOINT’S SANDBOX

A faithful recreation of games like The Sandbox, Sandboxels, you name it… BASICALLY 2D MINECRAFT AVAILABLE HERE TO PLAY DURING CLASS!!!!!!!

This game has everything you need for a proper sandboxing experience. It’s got more than 20 DIFFERENT BLOCKS each with their unique realistic physics, WORLD GENERATION, and, of course, EXPLOSIVES!

How to play:
- Move your cursor with ARROWS
- Place block with OK
- Change blocks with keys BACKSPACE and POWER (in the top right corner)
- Press SHIFT to quickly select “Erase”.

A few screenshots:


i would’ve made more if i didn’t have to make them on the emulator :(

A few notes:
- Embers can spawn fire underwater when they dissapear
- Fuse is the only block that is 100% flammable
- Steel is blast resistant
- Humans can drown underwater (don’t hurt these little dudes pls)
- Nuke and Firebomb WILL EXPLODE if they touch the ground while falling, however they won’t if they are placed directly on top of a block.
- I wanted this game to run on Epsilon, but if you use a better OS you’ll have the space to add a few more blocks! I had some more ideas such as more liquids (oil, lava, acid), more bombs and snow burning into water upon touching fire, feel free to add them!

Enjoy!


#SANDBOX GAME by SQUAREPOINT
#Keys:Move with ARROWS,place with OK,scroll with BACKSPACE and POWER,SHIFT to quickly select"Erase"
from kandinsky import fill_rect as s,draw_string as txt
from ion import keydown as k
from time import*
from random import randint as r
M2=[]
C=[(0,200,200),(0,150,0),(100,100,100),(150,100,0),(0,100,255),(255,100,0),(100,50,0),(0,255,0),(255,0,0),(200,200,200),(100,0,0),(255,120,0),(200,200,150),(200,120,80),(220,180,130),(220,220,220),(0,255,0),(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=(255,255,255),(150,150,150)
def bc(i,x,y):
  if (i+x)//32!=i//32 or (i+y*32)%32!=i%32 or i+x+y*32>639 or i+x+y*32<0:return 0
  else:return 1
def p(i,w,t):
  w=MS[w]
  for j in range(len(w[3])):
    z=int(w[3][j],36)
    mx=j%w[2]+w[0]
    my=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)
b=0
kp=0
s(0,0,320,222,(0,200,200))
s(50,30,220,150,B)
txt("Squarepoint's",95,50)
txt("SANDBOX",125,70)
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=[0]*608+[2]*32+[0]*32
      d=r(-2,0)
      e=r(0,1)
      b1=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)==0 and d<0:d+=1
          elif d>-2:d-=1
    break
  sleep(0.1)
x=0
y=0
b=0
t=0
tps=0
s(0,0,320,222,G)
t0=monotonic()
while 1:
  if k(4):M[y*32+x]=b
  if k(0)and x>0:x-=1
  if k(3)and x<31:x+=1
  if k(1)and y>0:y-=1
  if k(2)and y<19:y+=1
  if k(12):b=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)==0:
            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)==0:
            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)==0:
            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)==0: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 monotonic()-t0>1:
    t0=monotonic()
    tps=t
    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.