SHARE
TWEET

Untitled

a guest May 23rd, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def load_save():
  2.     f = open('data/save_file.txt','r')
  3.     dat = f.read()
  4.     f.close()
  5.     dat = dat.split('\n')
  6.     while len(dat) < 6:
  7.         dat.append('0000000000')
  8.     return dat
  9.  
  10. def save(dat):
  11.     s = ''
  12.     for line in dat:
  13.         s += line + '\n'
  14.     s = s[:-1]
  15.     f = open('data/save_file.txt','w')
  16.     f.write(s)
  17.     f.close()
  18.  
  19. def get_progress(dat):
  20.     world = 1
  21.     for line in dat:
  22.         if '0' not in line:
  23.             world += 1
  24.         else:
  25.             break
  26.     return world
  27.  
  28. def level_select():
  29.     global right_key, left_key, up_key, down_key, select_key
  30.     bg = menu_background()
  31.  
  32.     tips = ['Jump Off The Sides of a Wall to Prevent Falling',
  33.             'Use WASD or Arrow Key to Move',
  34.             'Use Space-bar or Enter Key to Shoot',
  35.             'Collect Hidden Gems to Gain a Higher Score',
  36.             'Avoid Enemy Projectiles by Jumping']
  37.     tip = random.choice(tips)
  38.  
  39.     #images
  40.     arrow_img = load_img('arrow')
  41.     level_line_img = load_img('line')
  42.     lock_img = load_img('lock')
  43.  
  44.     #save file
  45.     save_dat = load_save()
  46.     level_progress = get_progress(save_dat)
  47.  
  48.     #other stuff
  49.     selected_level = None
  50.     level_target = 0
  51.     level_target = 1
  52.     arrow_timer = 0
  53.     start_level = False
  54.  
  55.     level_scroll = 300
  56.     white_bar_width = 200
  57.     level_img_fade = [900,'u',1]
  58.  
  59.     level_count = 2 #Extend to X amount for more levels
  60.     level_amount = 2 #Extend to X amount for more levels
  61.     level_images = []
  62.     for i in range(level_amount):
  63.         level_images.append(load_img('levels/' + str(i+1)))
  64.  
  65.     #loop
  66.     in_play = True
  67.     while in_play:
  68.  
  69.         display.fill((0,0,0))
  70.         bg.render(display)
  71.         text_to_show = 'Level ' + str(level_target)
  72.         if selected_level != None:
  73.             text_to_show += '-' + str(level_target+1)
  74.         text.show_text(text_to_show,198-int(get_text_width(text_to_show,1)/2),50,1,9999,font,display)
  75.  
  76.         arrow_timer += 1
  77.         if arrow_timer == 60:
  78.             arrow_timer = 0
  79.         if selected_level == None:
  80.             display.blit(arrow_img,(195,115+int(arrow_timer/45)))
  81.         text.show_text('Tip: ' + tip,5,240,1,9999,font,display)
  82.  
  83.         #world stuff
  84.         world_surf = pygame.Surface((400,9))
  85.         for i in range(level_amount-1):
  86.             world_surf.blit(level_line_img,(round(level_scroll,0)+i*50,0))
  87.  
  88.         world_surf_base = pygame.Surface((400,9))
  89.         world_surf_base.fill((188,183,197))
  90.         pygame.draw.rect(world_surf_base,(248,248,248),pygame.Rect(0,0,white_bar_width,9))
  91.         world_surf.set_colorkey((248,248,248))
  92.         world_surf_base.blit(world_surf,(0,0))
  93.         world_surf_base.set_colorkey((0,0,0))
  94.         display.blit(world_surf_base,(0,100))
  95.         change_rate = ((195-(level_target-1)*50)-level_scroll)/5
  96.         level_scroll += change_rate
  97.        
  98.         if abs(change_rate) > 1.2:
  99.             white_bar_width += change_rate
  100.         elif white_bar_width < 204:
  101.             white_bar_width += 4
  102.             if white_bar_width > 204:
  103.                 white_bar_width = 204
  104.         elif white_bar_width > 204:
  105.             white_bar_width -= 4
  106.             if white_bar_width < 204:
  107.                 white_bar_width = 204
  108.         world_img = level_images[level_img_fade[2]-1].copy()
  109.         world_img.set_alpha(level_img_fade[0])
  110.        
  111.         if level_img_fade[1] == 'u':
  112.             level_img_fade[0] += 25
  113.             if level_img_fade[0] > 255:
  114.                 level_img_fade[0] = 255
  115.         else:
  116.             level_img_fade[0] -= 25
  117.             if level_img_fade[0] < 0:
  118.                 level_img_fade[0] = 0
  119.                 level_img_fade[1] = 'u'
  120.                 level_img_fade[2] = level_target
  121.         display.blit(world_img,(186,66))
  122.         if level_target > level_progress:
  123.             display.blit(lock_img,(194,70))
  124.  
  125.         if start_level == False:
  126.             for event in pygame.event.get():
  127.                 if event.type == QUIT:
  128.                     pygame.quit()
  129.                     sys.exit()
  130.                 if event.type == KEYDOWN:
  131.                     if event.key == right_key:
  132.                         if selected_level == None:
  133.                             level_target += 1
  134.                             if level_target > level_count:
  135.                                 level_target = 1
  136.                             level_img_fade[1] = 'd'
  137.                         else:
  138.                             level_target += 1
  139.                             if level_target > levels[selected_level]-1:
  140.                                 level_target = 0
  141.                     if event.key == left_key:
  142.                         if selected_level == None:
  143.                             level_target -= 1
  144.                             if level_target <= 0:
  145.                                 level_target = level_count
  146.                             level_img_fade[1] = 'd'
  147.                         else:
  148.                             level_target -= 1
  149.                             if level_target < 0:
  150.                                 level_target = levels[selected_level]-1
  151.                     if (event.key == down_key) or (event.key == select_key):
  152.                         if selected_level == None:
  153.                             if event.key == up_key:
  154.                                 if start_level == False:
  155.                                     selected_level = None
  156.                     if event.key == K_ESCAPE:
  157.                         in_play = False
  158.             save_dat = load_save()
  159.             level_progress = get_progress(save_dat)
  160.                    
  161.  
  162.         screen.blit(pygame.transform.scale(display,(WINDOWWIDTH,WINDOWHEIGHT)),(0,0))
  163.         pygame.display.update()
  164.         fps.tick(60)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top