Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygameextra as pe
- import pyperclip
- pe.init()
- pe.display.make((500,500), "lvl designer 1.0",1)
- pe.E_intro.run()
- pe.settings.UPDATE_AUTO = False
- s = 20
- hold = False
- holdS = (0,0)
- level = []
- motionX = 0
- motionY = 0
- LP = (0,0)
- menu = False
- menuPos = (0,0)
- menuClose = False
- high = False
- selected = None
- touchMenu = False
- def CloseMenu():
- global selected, menu, menuClose, touchMenu
- menuClose = True
- selected = None
- menu = False
- touchMenu = False
- def erase():
- global level
- level = []
- CloseMenu()
- def Print():
- global level
- print("\nlevel was copied to clipboard")
- text = ""
- start = 100
- end = 0
- for x in level:
- if x[0][0] < start:
- start = x[0][0]-1
- if x[0][0]+x[0][2] > end:
- end = x[0][0]+x[0][2]
- if x[1] == pe.color.red:
- color = "pe.color.red"
- elif x[1] == pe.color.green:
- color = "pe.color.green"
- elif x[1] == pe.color.yellow:
- color = "pe.color.yellow"
- rect = "("+str(x[0][0])+", "+str(x[0][1])+", "+str(x[0][2])+", "+str(x[0][3])+")"
- text = text + "\n" + "["+rect+", "+color+", "+str(x[2])+"],"
- startT = "[("+str(start)+", 40, 1, 50), pe.color.black, 0],"
- endT = "[("+str(end)+", 40, 1, 50), pe.color.black, 0],"
- pyperclip.copy(startT+"\n"+endT+"\n"+text)
- print("Level Start: "+str(start)+" blocks\n"+"Level End: "+str(end*s)+" px")
- CloseMenu()
- def eraseBlock():
- global selected, menu, menuClose, touchMenu
- del level[selected]
- selected = None
- menu = False
- menuClose = True
- touchMenu = False
- def setC(id):
- global selected
- level[selected][2] = id
- if id == 0:
- color = pe.color.red
- elif id == 1:
- color = pe.color.green
- elif id == 2:
- color = pe.color.yellow
- level[selected][1] = color
- while True:
- pe.fill.full(pe.color.white)
- for pe.event.c in pe.event.get():
- pe.event.quitcheckauto()
- if pe.event.key_DOWN(100): # RIGHT ARROW KEY CODE
- motionX = 1
- elif pe.event.key_DOWN(97): # LEFT ARROW KEY CODE
- motionX = -1
- elif pe.event.key_UP(100) or pe.event.key_UP(97): # IF BOTH KEYS ARE NOT PRESSED
- motionX = 0
- if pe.event.key_DOWN(115): # RIGHT ARROW KEY CODE
- motionY = 1
- elif pe.event.key_DOWN(119): # LEFT ARROW KEY CODE
- motionY = -1
- elif pe.event.key_UP(115) or pe.event.key_UP(119): # IF BOTH KEYS ARE NOT PRESSED
- motionY = 0
- LP = (LP[0] + motionX * s/4 * -1, LP[1] + motionY * s/4 * -1) # move the camera
- a = (round((LP[0] - s / 2) / s) * s)
- b = (round((LP[1] - s) / s) * s) + s
- pe.Layer[0][1] = (a,b)
- mp = pe.mouse.pos()
- a = (round((mp[0] - s / 2) / s) * s)
- b = (round((mp[1] - s) / s) * s) + s
- if pe.mouse.clicked()[0] and not hold and not menu and not menuClose and not high and not touchMenu:
- hold = True
- holdS = (a,b)
- elif pe.mouse.clicked()[2] and not hold and not high and not touchMenu:
- menu = True
- menuPos = (a,b)
- elif hold:
- if not pe.mouse.clicked()[0]:
- hold = False
- rect = (rect[0]-pe.Layer[0][1][0],rect[1]-pe.Layer[0][1][1],rect[2],rect[3])
- realRect = (rect[0]/s,(500 - rect[1])/s,rect[2]/s,rect[3]/s)
- level.append([realRect,pe.color.red,0])
- else:
- if a-holdS[0]+s > 0 and b-holdS[1]+s > 0:
- rect = (holdS[0],holdS[1],a-holdS[0]+s,b-holdS[1]+s)
- pe.draw.rect(pe.color.pink, (holdS[0],holdS[1],a-holdS[0]+s,b-holdS[1]+s),0,layer=1)
- elif a-holdS[0]+s <= 0 and b-holdS[1]+s <= 0:
- rect = (a, b, holdS[0]-a+s, holdS[1]-b+s)
- pe.draw.rect(pe.color.pink, (a, b, holdS[0]-a+s, holdS[1]-b+s), 0,layer=1)
- elif a-holdS[0]+s <= 0:
- rect = (a, holdS[1],holdS[0]-a+s , b-holdS[1]+s)
- pe.draw.rect(pe.color.pink, (a, holdS[1],holdS[0]-a+s , b-holdS[1]+s), 0,layer=1)
- elif b-holdS[1]+s <= 0:
- rect = (holdS[0], b, a-holdS[0]+s, holdS[1]-b+s)
- pe.draw.rect(pe.color.pink, (holdS[0], b, a-holdS[0]+s, holdS[1]-b+s), 0,layer=1)
- if not pe.mouse.clicked()[0] and not pe.mouse.clicked()[2]:
- high = False
- if selected != None:
- block = level[selected]
- if not pe.pygame.Rect(( (block[0][0] * s)+pe.Layer[0][1][0], (500 - block[0][1] * s)+pe.Layer[0][1][1], block[0][2] * s, block[0][3] * s)).colliderect(pe.pygame.Rect(a,b,s,s)) and not touchMenu:
- selected = None
- i = 0
- for block in level: # do this for all the level blocks
- lvlrect = (block[0][0] * s, 500 - block[0][1] * s, block[0][2] * s, block[0][3] * s)
- pe.draw.rect(block[1], lvlrect, 0) # draw the block
- r1 = pe.pygame.Rect(( (block[0][0] * s)+pe.Layer[0][1][0], (500 - block[0][1] * s)+pe.Layer[0][1][1], block[0][2] * s, block[0][3] * s))
- r2 = pe.pygame.Rect(a,b,s,s)
- if r1.colliderect(r2) and not menu and not menuClose:
- pe.draw.rect(pe.color.black,lvlrect,5)
- high = True
- if pe.mouse.clicked()[2]:
- selected = i
- menuPos = (a,b)
- i += 1
- if menu:
- p = menuPos
- pe.button.rect((p[0]+s,p[1],s,s),(255,0,0),(255,150,150), action=CloseMenu,layer=1)
- pe.draw.line(pe.color.black, (p[0]+s,p[1]),(p[0]+s*2-2,p[1]+s-2),2,layer=1)
- pe.draw.line(pe.color.black, (p[0]+s*2-2,p[1]),(p[0]+s,p[1]+s-2),2,layer=1)
- pe.button.rect((p[0],p[1],s,s),(0,255,255),(100,255,255),action=erase,layer=1)
- pe.draw.line(pe.color.red,(p[0],p[1]+s/2),(p[0]+s,p[1]+s/2),5,layer=1)
- pe.button.rect((p[0] - s, p[1], s, s), (0, 255, 0), (150, 255, 150), action=Print, layer=1)
- elif selected != None:
- p = menuPos
- menuRect = pe.pygame.Rect(p[0] - s, p[1]-s,s*3,s*3)
- touchMenu = menuRect.colliderect(pe.pygame.Rect(a,b,s,s))
- pe.draw.rect(pe.color.black, (p[0] - s-s/4, p[1] - s-s/4, s * 3.5, s * 3.5), 0, layer=1)
- pe.draw.rect(pe.color.white,(p[0] - s, p[1]-s,s*3,s*3),0,layer=1)
- pe.button.rect((p[0] + s, p[1], s, s), (255, 0, 0), (255, 150, 150), action=CloseMenu, layer=1)
- pe.draw.line(pe.color.black, (p[0] + s, p[1]), (p[0] + s * 2 - 2, p[1] + s - 2), 2, layer=1)
- pe.draw.line(pe.color.black, (p[0] + s * 2 - 2, p[1]), (p[0] + s, p[1] + s - 2), 2, layer=1)
- pe.button.rect((p[0], p[1], s, s), (0, 255, 255), (100, 255, 255), action=eraseBlock, layer=1)
- pe.draw.line(pe.color.red, (p[0], p[1] + s / 2), (p[0] + s, p[1] + s / 2), 5, layer=1)
- pe.button.rect((p[0] - s, p[1]+s, s, s), (255, 255, 0), (255, 255, 100), action=setC, data=2, layer=1)
- pe.button.rect((p[0] - s, p[1], s, s), (0, 255, 0), (150, 255, 150), action=setC, data=1, layer=1)
- pe.button.rect((p[0] - s, p[1]-s, s, s), (255, 0, 0), (255, 150, 150), action=setC, data=0, layer=1)
- if menuClose:
- menu = False
- selected = None
- if not pe.mouse.clicked()[0]:
- menuClose = False
- if not menu and not high and not touchMenu:
- pe.draw.rect(pe.color.black, (a, b, s, s), 2,layer=1)
- pe.draw.line(pe.color.black, (0,0),(0,500+s),1)
- pe.draw.line(pe.color.black, (-s,500),(500,500),1)
- pe.display.update()
- pe.time.tick(500)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement