Advertisement
Arcot

geometry dash test

Jul 25th, 2022
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.05 KB | None | 0 0
  1. # Initializing pygame + some important variables
  2.  
  3. import pygame
  4. from random import randint
  5.  
  6. pygame.init()
  7.  
  8. score = 0
  9. total = 0
  10.  
  11. myfont = pygame.font.SysFont('monospace', 50)
  12.  
  13. # Jumping Variables
  14. yVel = 0
  15. Jumping = 0
  16. # Dead People :D
  17. Dead = False
  18. # Making dictionaries with settings for everything.
  19.  
  20. display = {
  21.   "width": 800,
  22.   "height": 600
  23. }
  24.  
  25. character = {
  26.   "width": 20,
  27.   "height": 20,
  28.   "x": 200,
  29.   "y": 580,
  30.   "velocity": 50
  31. }
  32.  
  33.  
  34. platform = {
  35.     'y': 580,
  36.     "x": 700,
  37.     "pass": 0,
  38.     "length": 20,
  39.     "ammount": 2,
  40.     "distanceApart": 50
  41. }
  42. spike = {
  43.   "height": -15,
  44.   "y": 600,
  45.   "x": 700,
  46.   "pass": 0,
  47.   "length": 20,
  48.   "ammount": 2,
  49.   "distanceApart": 50
  50. }
  51. test = 0
  52.  
  53.  
  54. def nextSection(a):
  55.     spike["x"] = 700
  56.     spike['pass'] += spike['ammount']
  57.     spike['ammount'] = randint(1,5)
  58.     spike['distanceApart'] = randint(2,8)*10
  59.     return a + 1
  60.  
  61.  
  62. def triangleDraw(i):  # Draws the triangles
  63.     pygame.draw.polygon(win,(0,0,0),((spike["x"]+spike['distanceApart']*i,spike["y"]),(spike['x']+spike['distanceApart']*i+spike["length"],spike['y']),(spike['x']+spike['length']/2+spike['distanceApart']*i,spike['y']+spike['height'])))
  64.  
  65.  
  66. def jump():  # Start Jumping
  67.     global yVel
  68.     global Jumping
  69.     if Jumping == 0:
  70.         Jumping = 1
  71.         yVel = 10
  72.         character['y'] = character['y']-yVel
  73.         if character['y'] > platform['y']:
  74.             Jumping = 0
  75.         yVel -= 0.5
  76.  
  77.  
  78. def cJump():  # Contine Jump
  79.     global yVel
  80.     global Jumping
  81.     if Jumping == 0:
  82.         if character['y'] > platform['y']:
  83.             pass
  84.         else:
  85.             Jumping = 1
  86.     if Jumping == 1:
  87.         character['y'] = character['y']-yVel
  88.         if character['y'] > platform['y']:
  89.             Jumping = 2
  90.         yVel -= 0.5
  91.     elif Jumping == 2:
  92.         Jumping =3
  93.     elif Jumping == 3:
  94.         Jumping = 4
  95.     elif Jumping == 4:
  96.         Jumping = 5
  97.     elif Jumping == 5:
  98.         Jumping = 0
  99.  
  100.  
  101. def next():
  102.     cJump()
  103.     pygame.draw.rect(win, (255, 0, 0), (character["x"], character["y"], character["width"], character["height"]))
  104.     pygame.display.update()
  105.     spike['x'] -= 5
  106.  
  107.  
  108. # Launching the window, setting it to the dimensions of the `display` dictionary.
  109. win = pygame.display.set_mode((display["width"], display["height"]))
  110.  
  111. jump()
  112. while True:  # Main Game Loop
  113.     pygame.time.delay(10)
  114.     win.fill((255, 255, 255))
  115.     for i in range(spike['ammount']):  # Spike Drawing
  116.         triangleDraw(i)
  117.     keys = pygame.key.get_pressed()
  118.     if keys[pygame.K_UP] or keys[pygame.K_w]:  # Checks if need to Jump
  119.         jump()
  120.     for event in pygame.event.get():  # Quit statement
  121.         if event.type == pygame.QUIT:
  122.             break
  123.     if spike['x']+spike['distanceApart']*spike['ammount'] < character['x']:  # checks to start next section
  124.         i = nextSection(i)
  125.     if spike['pass'] < 100:  # Win Statement
  126.         textsurface = myfont.render("Debug {0}".format(Dead), False, (0, 0, 0))
  127.         textsurface2 = myfont.render("Percentage {0}%".format(spike['pass']), False, (0, 0, 0))
  128.         win.blit(textsurface, (0,10))
  129.         win.blit(textsurface2, (300,10))
  130.     else:
  131.         textsurface2 = myfont.render("YOU WIN",False, (255,0,0))
  132.         win.blit(textsurface2, (300,10))
  133.         break
  134.     for i in range(spike['ammount']):  # Checks if death occurs
  135.         if spike['x']+spike['distanceApart']*i <= character['x'] and spike['x']+spike['distanceApart']*i+spike['length'] >= character['x']:
  136.             posOnSpike = abs(character['x'] - (spike['x']+spike['length']/2))
  137.             test = 1
  138.             if posOnSpike*2+spike['y'] > character['y'] and spike['y'] < character['y'] or posOnSpike*2+spike['y'] > character['y'] + character['height'] and spike['y'] < character['y']+character['height']:
  139.                 textsurface2 = myfont.render("YOU LOSE",False, (255,0,0))
  140.                 win.blit(textsurface2, (300,10))
  141.                 Dead = True
  142.         else:
  143.             None
  144.     # Drawing Stuff
  145.     next()
  146.     if Dead:
  147.         break
  148. pygame.time.delay(1000)
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement