Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random, sys, pygame, math
- #Game variables
- pg = pygame
- bg=(0,0,0)
- FPS=300
- x = 540
- y = 300
- Up = pygame.K_w
- Down = pygame.K_s
- Left = pygame.K_a
- Right = pygame.K_d
- Dir = None
- Oldx = 0
- Oldy = 0
- Speed = 20
- Scrollx = -720
- Scrolly = 0
- Win = True
- Debug = False
- i = 0
- Ix=0
- bgImg = pg.image.load("bg1.png")
- Found = True
- overlay = pg.image.load("overlay.png")
- ladder = (83,33,0)
- Health = 20
- #Setup pygame
- pg = pygame
- pg.init()
- #Display variables
- h = 700
- w = 1080
- Cx = 0
- Cy = 0
- Cookies = 0
- clock = pygame.time.Clock()
- screen = pg.display.set_mode((w,h),0,32)
- char = "charRight.png"
- cookiecrumb = pg.image.load("CookieCrumb.png")
- GUI = pg.image.load("GUI.png")
- Font = pygame.font.Font(None, 48)
- FTime = pygame.font.Font(None, 72)
- Left2 = 50
- Time = 12000
- running = True
- win = None
- pg.display.set_caption("Cookie Hunter 1.2.7 By Dylan Dunn")
- #Image Loader
- def ImageLoad(ImageName,ImageX,ImageY):
- img = pygame.image.load(ImageName)
- screen.blit(img,(ImageX,ImageY))
- #Loading Screen
- while Debug == False:
- ImageLoad("LoadingScreen.png",0,0)
- print "Loading Game..."
- pg.display.update()
- pg.time.wait(10000)
- Debug = True
- i = 0
- #Main Loop
- pygame
- while running == True:
- SpawnPoints = [(540,600),(2217,587),(2965,600),(7777,600),(5292,1399),(6427,1398),(5713,2090),(1743,1994),(368,1958),(119,1265)]
- pygame.display.update()
- for event in pygame.event.get():
- if event.type == pg.QUIT:
- pygame.quit()
- sys.exit()
- elif event.type == pg.KEYDOWN:
- if event.key == Up:
- Dir = "Up"
- if event.key == Down:
- Dir = "Down"
- if event.key == Right:
- Dir = "Right"
- if event.key == Left:
- Dir = "Left"
- if event.type == pg.KEYUP:
- Dir = None
- LastDir = Dir
- Current_Bottom = screen.get_at((604,y+128))
- Current_Up = screen.get_at((604,y+132))
- Current_Right = screen.get_at((x+128,y))
- Current_Down = screen.get_at((x+64,y+132))
- Current_Left = screen.get_at((x,y))
- if Dir == "Left":
- Scrollx = Scrollx + Speed
- Cx = Cx + Speed
- if Dir == "Right":
- Scrollx = Scrollx - Speed
- Cx = Cx - Speed
- if Dir != None:
- if Current_Bottom == (0,0,0):
- Scrolly = Scrolly + 5
- Cy = Cy + 5
- if Current_Up == (0,0,0):
- Scrolly = Scrolly + 3
- Cy = Cy + 3
- if Current_Down != (0,0,0) and Current_Down != (ladder):
- Scrolly = Scrolly - 10
- Cy = Cy - 10
- if Current_Down != (0,0,0):
- Scrolly = Scrolly - 1
- Cy = Cy - 1
- if LastDir == "Right" and Current_Bottom != (0,0,0):
- Scrollx = Scrollx + 1
- Cx = Cx + 1
- if LastDir == "Left" and Current_Bottom != (0,0,0):
- Scrollx = Scrollx - 1
- Cx = Cx - 1
- if y < 1:
- y = Oldy
- if y + 150 > h:
- y = Oldy
- if Current_Down == (ladder) and Dir == "Down":
- Scrolly = Scrolly - 10
- Cy = Cy - 10
- if Current_Down == (ladder) and Dir == "Up":
- Scrolly = Scrolly + 10
- Cy = Cy + 10
- Oldx = x
- Oldy = y
- OldScrolly = Scrolly
- #Spawning Cookie Crumb
- if Found == True:
- R_Pos = random.randint(0,3)
- C_Pos = SpawnPoints[R_Pos]
- print "New Cookie Spawned"
- Found = False
- Cx,Cy = C_Pos
- Cx = Cx + Scrollx
- Cy = Cy + Scrolly
- Time = Time + 1000
- if Dir == "Right":
- char = "charRight.png"
- if Dir == "Left":
- char = "charLeft.png"
- if Time != 0:
- Time = Time - 10
- else:
- running = False
- win = False
- screen.blit(bgImg,(Scrollx,Scrolly))
- pg.draw.rect(screen,(0,0,0),((0,0),(w,h)),200)
- screen.blit(overlay,(0,(y - 400)))
- ImageLoad(char,540, y)
- ImageLoad("GUI.png",0,0)
- Border = 260
- if Cx > Border and Cx < w - Border and Cy > Border and Cy < h - Border:
- screen.blit(cookiecrumb,(Cx,Cy))
- CD = screen.get_at((Cx, Cy))
- if CD == (0,0,0):
- Found = True
- Cookies = Cookies + 1
- Left2 = Left2 - 1
- print ("Cookie Crumbs Found")
- TimeS = "Seconds Left: " + str(Time / 100)
- Num_Cookie = "Cookies Crumbs Found: " + str(Cookies)
- Left_Cookie = "Cookies Crumbs Left: " + str(Left2)
- Times = FTime.render(TimeS, 1, (0,0, 0))
- Score = Font.render(Num_Cookie, 1, (255, 0, 0))
- CLeft = Font.render(Left_Cookie, 1, (255, 0, 0))
- screen.blit(Score,(620,50))
- screen.blit(CLeft,(620,100))
- screen.blit(Times,(100,75))
- clock.tick(FPS)
- if Left2 == 0:
- win = True
- running = False
- pygame.display.update()
- if win == True:
- img = "win.png"
- if win == False:
- img = "lose.png"
- ImageLoad(img,0,0)
- pg.display.update()
- pg.time.wait(10000)
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment