Guest User

Cookie Hunter Source

a guest
Dec 15th, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.92 KB | None | 0 0
  1. import random, sys, pygame, math
  2.  
  3. #Game variables
  4. pg = pygame
  5. bg=(0,0,0)
  6. FPS=300
  7. x = 540
  8. y = 300
  9. Up = pygame.K_w
  10. Down = pygame.K_s
  11. Left = pygame.K_a
  12. Right = pygame.K_d
  13. Dir = None
  14. Oldx = 0
  15. Oldy = 0
  16. Speed = 20
  17. Scrollx = -720
  18. Scrolly = 0
  19. Win = True
  20. Debug = False
  21. i = 0
  22. Ix=0
  23. bgImg = pg.image.load("bg1.png")
  24. Found = True
  25. overlay = pg.image.load("overlay.png")
  26. ladder = (83,33,0)
  27. Health = 20
  28. #Setup pygame
  29. pg = pygame
  30. pg.init()
  31. #Display variables
  32. h = 700
  33. w = 1080
  34. Cx = 0
  35. Cy = 0
  36. Cookies = 0
  37. clock = pygame.time.Clock()
  38. screen = pg.display.set_mode((w,h),0,32)
  39. char = "charRight.png"
  40. cookiecrumb = pg.image.load("CookieCrumb.png")
  41. GUI = pg.image.load("GUI.png")
  42. Font = pygame.font.Font(None, 48)
  43. FTime = pygame.font.Font(None, 72)
  44. Left2 = 50
  45. Time = 12000
  46. running = True
  47. win  = None
  48. pg.display.set_caption("Cookie Hunter 1.2.7 By Dylan Dunn")
  49. #Image Loader
  50. def ImageLoad(ImageName,ImageX,ImageY):
  51.     img = pygame.image.load(ImageName)
  52.     screen.blit(img,(ImageX,ImageY))
  53. #Loading Screen
  54. while Debug == False:
  55.     ImageLoad("LoadingScreen.png",0,0)
  56.     print "Loading Game..."
  57.     pg.display.update()
  58.     pg.time.wait(10000)
  59.     Debug = True
  60.     i = 0
  61. #Main Loop
  62. pygame
  63. while running == True:
  64.     SpawnPoints = [(540,600),(2217,587),(2965,600),(7777,600),(5292,1399),(6427,1398),(5713,2090),(1743,1994),(368,1958),(119,1265)]
  65.     pygame.display.update()
  66.     for event in pygame.event.get():
  67.         if event.type == pg.QUIT:
  68.             pygame.quit()
  69.             sys.exit()
  70.         elif event.type == pg.KEYDOWN:
  71.             if event.key == Up:
  72.                 Dir = "Up"
  73.             if event.key == Down:
  74.                 Dir = "Down"
  75.             if event.key ==  Right:
  76.                 Dir = "Right"
  77.             if event.key == Left:
  78.                 Dir = "Left"
  79.         if event.type == pg.KEYUP:
  80.             Dir = None
  81.         LastDir = Dir
  82.     Current_Bottom = screen.get_at((604,y+128))
  83.     Current_Up = screen.get_at((604,y+132))
  84.     Current_Right = screen.get_at((x+128,y))
  85.     Current_Down = screen.get_at((x+64,y+132))
  86.     Current_Left = screen.get_at((x,y))
  87.     if Dir == "Left":
  88.         Scrollx = Scrollx + Speed
  89.         Cx = Cx + Speed
  90.     if Dir == "Right":
  91.         Scrollx = Scrollx - Speed
  92.         Cx = Cx - Speed
  93.     if Dir != None:
  94.         if Current_Bottom == (0,0,0):
  95.             Scrolly = Scrolly + 5
  96.             Cy = Cy + 5
  97.         if Current_Up == (0,0,0):
  98.             Scrolly = Scrolly + 3
  99.             Cy = Cy + 3
  100.  
  101.     if Current_Down != (0,0,0) and Current_Down != (ladder):
  102.         Scrolly = Scrolly - 10
  103.         Cy = Cy - 10
  104.     if Current_Down != (0,0,0):
  105.         Scrolly = Scrolly - 1
  106.         Cy = Cy - 1
  107.        
  108.     if LastDir == "Right" and Current_Bottom != (0,0,0):
  109.             Scrollx = Scrollx + 1
  110.             Cx = Cx + 1
  111.     if LastDir == "Left" and Current_Bottom != (0,0,0):
  112.             Scrollx = Scrollx - 1
  113.             Cx = Cx - 1
  114.     if y < 1:
  115.         y = Oldy
  116.     if y + 150 > h:
  117.         y = Oldy
  118.     if Current_Down == (ladder) and Dir == "Down":
  119.         Scrolly = Scrolly - 10
  120.         Cy = Cy - 10
  121.     if Current_Down == (ladder) and Dir == "Up":
  122.         Scrolly = Scrolly + 10
  123.         Cy = Cy + 10
  124.     Oldx = x
  125.     Oldy = y
  126.     OldScrolly = Scrolly
  127.     #Spawning Cookie Crumb
  128.     if Found == True:
  129.         R_Pos = random.randint(0,3)
  130.         C_Pos = SpawnPoints[R_Pos]
  131.         print "New Cookie Spawned"
  132.         Found = False
  133.         Cx,Cy = C_Pos
  134.         Cx = Cx + Scrollx
  135.         Cy = Cy + Scrolly
  136.         Time = Time + 1000
  137.     if Dir == "Right":
  138.         char = "charRight.png"
  139.     if Dir == "Left":
  140.         char = "charLeft.png"
  141.     if Time != 0:
  142.         Time = Time - 10
  143.     else:
  144.         running = False
  145.         win = False
  146.     screen.blit(bgImg,(Scrollx,Scrolly))
  147.     pg.draw.rect(screen,(0,0,0),((0,0),(w,h)),200)
  148.     screen.blit(overlay,(0,(y - 400)))
  149.     ImageLoad(char,540, y)
  150.     ImageLoad("GUI.png",0,0)
  151.     Border = 260
  152.     if Cx > Border and Cx < w - Border and Cy > Border and Cy < h - Border:
  153.         screen.blit(cookiecrumb,(Cx,Cy))
  154.         CD = screen.get_at((Cx, Cy))
  155.         if CD == (0,0,0):
  156.             Found = True
  157.             Cookies = Cookies + 1
  158.             Left2 = Left2 - 1
  159.             print ("Cookie Crumbs Found")
  160.     TimeS = "Seconds Left: " + str(Time / 100)
  161.     Num_Cookie = "Cookies Crumbs Found: " + str(Cookies)
  162.     Left_Cookie = "Cookies Crumbs Left: " + str(Left2)
  163.     Times = FTime.render(TimeS, 1, (0,0, 0))
  164.     Score = Font.render(Num_Cookie, 1, (255, 0, 0))
  165.     CLeft = Font.render(Left_Cookie, 1, (255, 0, 0))
  166.     screen.blit(Score,(620,50))
  167.     screen.blit(CLeft,(620,100))
  168.     screen.blit(Times,(100,75))
  169.     clock.tick(FPS)
  170.     if Left2 == 0:
  171.         win = True
  172.         running = False
  173.     pygame.display.update()
  174. if win == True:
  175.     img = "win.png"
  176. if win == False:
  177.     img = "lose.png"
  178. ImageLoad(img,0,0)
  179. pg.display.update()
  180. pg.time.wait(10000)
  181. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment