ruin_lvl_maker.py

Created by fime

Created on September 21, 2022

3.45 KB

— Level maker for R U I N

After creating a level, copy it’s code and past it on the end of the levels() function (at the end of the program) : else : return [] #insert your lvl code here

Download the game

ruin.py

Controls:

-Arrows: move/resize platforms -[OK]: switch editing mode -[Power]: add platform -[(] and [)]: previous and next platform -[+] and [-]: incrase and decrase ennemy number\n -Backspace: delete current platform -[exe]:print level hash -[0]:Quit (will also print the hash)

Interface:

-Left-Up:Platform data (x,y,w,h,enemy number) -Left-down:Current mode and level size

-Red:current platform -Orange:spawn platform -Green:door’s platform

Pro tip: use the key to see the available functions


from ion import *
from kandinsky import *
from time import monotonic as cTime,sleep

def printLvl():
  try:print("\nLevel hash:\n"+__compressLvl(),end="\n\n")
  except:print("\nNo lvl loaded\n")
def doc():
  print("""
--- Level maker for R U I N ---

Controls:

  -Arrows: move/resize platforms
  -[OK]: switch editing mode
  -[Power]: add platform
  -[(] and [)]: previous and next platform
  -[+] and [-]: incrase and decrase ennemy number\n  -Backspace: delete current platform
  -[exe]:print level hash
  -[0]:Quit (will also print the hash)

Interface:

  -Left-Up:Platform data (x,y,w,h,enemy number)
  -Left-down:Current mode and level size
  
  -Red:current platform
  -Orange:spawn platform
  -Green:door's platform

Pro tip: use the <var> key to see the
available functions
""")

def __update():
  draw_string("Platform {}, Number :{}".format(select,len(lvl)),0,0)
  draw_string("Mode:"+["Position","Size"][mode],0,202)
  draw_string(str(lvl[select]),0,20)
  draw_string("{} bytes".format(len(lvl)*9),0,181)
  for id,arg in enumerate(lvl):
    if id==select:c="red"
    elif id==0:c="orange"
    elif id==len(lvl)-1:c="green"
    else :c="blue"
    fill_rect(*arg[0:-1]+[c])

def __compressLvl():
  string=""
  for i in lvl:
    x,y,w,h,nb_nmy=i
    x,y,w,h=x//5,y//5,w//5,h//5
    for j in [x,y,w,h]:
      string+=("0" if j<16 else "")+hex(j)[2:]
    string+=str(nb_nmy)
  return string

def __uncompressLvl(string):
  Hex2Int=lambda n:int("0x"+n)
  platforms=[]
  for i in range(0,len(string),9):
    ptf_str=string[i:i+9]
    plat=[]
    for j in range(0,8,2):plat+=[Hex2Int(ptf_str[j:j+2])*5]
    plat.append(int(ptf_str[-1]))
    platforms.append(plat)
  return platforms

def launch():
  print("\n---Press button---\n")
  print(" 1-New Level\n 2-Load level from hash")
  lvl,loop=[[160,110,30,5,0]],1
  while loop:
    for i in (42,43):
      if keydown(i):
        loop=0
        break
  del loop
  if i==43:
    print(">Load level...")
    try:lvl=__uncompressLvl(input("\nPaste level code:\n"))
    except:print("\n>Error: unable to load from hash")
  else:print(">New level...")
  print("\n>>>Launching editor")
  __editor(lvl)
  
def __editor(in_lvl):
  global lvl,mode,select
  lvl,select,mode=in_lvl,0,0
  __update()
  while True:
    if keydown(48):
      break
    for i in (0,1,2,3,4,8,16,17,33,34,45,46,52):
      if keydown(i):
        fill_rect(0,0,320,222,"white")
        if i==0:lvl[select][mode*2]-=5
        if i==3:lvl[select][mode*2]+=5
        if i==1:lvl[select][mode*2+1]-=5
        if i==2:lvl[select][mode*2+1]+=5
        if i==4:mode=int(not mode)
        if i==8:
          lvl.insert(select,list(lvl[select]))
          select,mode=select+1,0
        if i==17 and len(lvl)>1:
          lvl.pop(select)
          select-=1
        if i==33:select=(select-1)%len(lvl)
        if i==34:select=(select+1)%len(lvl)
        if i==45:lvl[select][4]+=1
        if i==46:lvl[select][4]-=1
        for j,l in enumerate((320,222,320,20)):
          lvl[select][j]=lvl[select][j]%(l-5)
        if i==52:printLvl()
        lvl[select][4]=lvl[select][4]%10
        __update()
        press_time=cTime()
        while keydown(i):
          if cTime()-press_time>(0.2,0.02)[i<4 and not keydown(6)]:break
  fill_rect(0,0,320,222,"white")
  draw_string("Press back to leave",65,101)
  printLvl()
  print("\nLevel size:{} bytes\nPlatforms number:{}\nCompression ratio:{}".format( len(lvl)*9,len(lvl),round(len(str(lvl))/len(__compressLvl()),2)))

while keydown(4):pass
doc()
#launch()

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.