def titlescreen(screen,musicpath="music/TitleScreen.ogg"): run = 1 # 1 for mainloop # 0 for quit # -1 for continue pygame.mixer.init() pygame.mixer.music.load("music/TitleScreen.ogg") pygame.mixer.music.set_volume(1) pygame.mixer.music.play(-1) pygame.mixer.music.load(musicpath) pygame.mixer.music.play(-1) logo = pygame.image.load('logo.png') start = Button(text("Start",40,[128,32,2]),[320,320],True) new = Button(text("New",40,[128,32,2]),[320,360],True) load = Button(text("Continue",40,[128,32,2]),[320,400],True) canvas=pygame.Surface(screen.get_size()) canvas=canvas.convert() canvas.fill([0,0,0]) while run == 1: canvas.fill([0,0,0]) new.render(canvas) load.render(canvas) blitcenter(logo,[320,128],canvas) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() raise SystemExit if event.type == pygame.MOUSEBUTTONDOWN: if new.hover(): usrname = utils.enterbox(screen,"Name:") if os.path.isfile('users/'+usrname+'.txt'): msgbox("Name is taken.") else: fl = open('users/'+usrname+'.txt','w+') fl.write('''level=level/origins/level1.txt hp=0 sp=0 inv=[] stealth=0 perception=0 ''') # Indentation much? fl.close() if load.hover(): namesfls = os.listdir('users/') names = [] for i in namesfls: if i.startswith('.'): continue names.append(i.strip('.txt')) utils.choicebox(screen,names,"Choose a save file") screen.fill([0,0,0]) screen.blit(canvas, [0,0]) if new.hover(): new = Button(text("New Game",45,[200,32,2]),[320,360],True) else: new = Button(text("New Game",40,[128,32,2]),[320,360],True) if load.hover(): load = Button(text("Continue",45,[200,32,2]),[320,400],True) else: load = Button(text("Continue",40,[128,32,2]),[320,400],True) pygame.display.flip() pygame.mixer.music.stop()
def titlescreen(screen,musicpath="res/music/TitleScreen.ogg"): run = 1 # 1 for mainloop # 0 for quit # -1 for continue images=os.listdir("res/sprites/") if silliness:musicpath="res/music/sillymusic.ogg" pygame.mixer.init() #pygame.mixer.music.load(musicpath) #pygame.mixer.music.set_volume(1) #pygame.mixer.music.play(-1) logo = pygame.image.load('logo.png') start = Button(text("Start",40,[128,32,2]),[320,320],True) new = Button(text("New",40,[128,32,2]),[320,360],True) load = Button(text("Continue",40,[128,32,2]),[320,400],True) developer = Button(text("Extras",40,[128,32,2]),[320,440],True) canvas=pygame.Surface(screen.get_size()) canvas=canvas.convert() canvas.fill([0,0,0]) imgs=[] print "Initializing Main Loop" while run == 1: canvas.fill([0,0,0]) new.render(canvas) load.render(canvas) developer.render(canvas) blitcenter(logo,[320,128],canvas) if silliness: if random.random()<=0.5: imgs.append([random.randrange(640), 0, pygame.image.load("res/sprites/"+random.choice(images)), 0]) nimgs=[] for img in imgs: x=img[0] y=img[1] image=img[2] speed=img[3] canvas.blit(image, [x, y]) y+=speed speed+=1 if y<=640: nimgs.append([x, y, image, speed]) imgs=nimgs for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() raise SystemExit if event.type == pygame.MOUSEBUTTONDOWN: if new.hover(): while 1: usrname = utils.enterbox(screen,"Name:") usrname = utils.enterbox(screen,"Name:") if usrname == 'OminAdmin108': msgbox(screen,"You're an developer!?!", "Uh, yeah...") pswd = passcodebox(screen,"Prove it.") if pswd == "VSurvival": msgbox(screen, "Access Granted") admin=1 else: msgbox(screen, "Go away.") break if os.path.isfile('users/'+usrname+'.txt'): msgbox(screen, "Name is taken.") else: fl = open('users/'+usrname+'.txt','w+') #TODO:Save stuff if load.hover(): namesfls = os.listdir('users/') names = [] for i in namesfls: if i.startswith('.'): continue names.append(i.strip('.txt')) utils.choicebox(screen,names,"Choose a save file") if developer.hover(): #PASSCODE IS VSurvival passcode = passcodebox(screen,"Password:"******"VSurvival": choice=choicebox(screen,["Silly Mode", "Level Editor","Crash Test"],"Developer Action?") if choice=="Level Editor": pygame.quit() import editor elif choice=="Silly Mode": return "silly" elif choice=="Crash Test": raise Exception else: msgbox(screen,"Incorrect.") screen.fill([0,0,0]) screen.blit(canvas, [0,0]) if new.hover(): new = Button(text("New Game",45,[200,32,2]),[320,360],True) else: new = Button(text("New Game",40,[128,32,2]),[320,360],True) if load.hover(): load = Button(text("Continue",45,[200,32,2]),[320,400],True) else: load = Button(text("Continue",40,[128,32,2]),[320,400],True) if developer.hover(): developer = Button(text("Developers Only",45,[200,32,2]),[320,440],True) else: developer = Button(text("Developers Only",40,[128,32,2]),[320,440],True) pygame.display.flip() pygame.mixer.music.stop()