Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #The egg and basket game
  2.  
  3. import pygame
  4. from pygame.locals import *
  5. import time
  6. import random
  7. x=260
  8. y=500
  9. score = 0
  10. lives = 3
  11.  
  12. #Screen initialize
  13. pygame.init()
  14. pygame.font.init()
  15. screen=pygame.display.set_mode((600,600))
  16. pygame.display.set_caption("egg")
  17. clock = pygame.time.Clock()
  18.  
  19. #Basket
  20. basket=pygame.image.load("art/basket.png")
  21. basket_rect = basket.get_rect()
  22.  
  23. #egg
  24. egg=pygame.image.load("art/egg.png")
  25. egg_rect = egg.get_rect()
  26.  
  27. def eggy(xegg, yegg):
  28. screen.blit(egg,(xegg, yegg))
  29.  
  30. def basketey(x, y):
  31. screen.blit(basket,(x, y))
  32.  
  33. #Movement of basket
  34. ychange=0
  35. xchange=0
  36. exiting=False
  37.  
  38.  
  39. xegg = random.randrange(50,550)
  40. yegg = 20
  41. while not exiting:
  42. if yegg<550:
  43. yegg += 2
  44. eggy(xegg, yegg)
  45.  
  46. # Doesn't work.
  47. ## elif pygame.sprite.spritecollideany(egg, basket):
  48. ## yegg=20
  49. ## xegg = random.randrange(50,550)
  50. ## yegg=yegg+ychange
  51. ##
  52. ## score += 1
  53. ##
  54. ## eggy(xegg, yegg)
  55.  
  56. else:
  57. yegg=20
  58. xegg = random.randrange(50,550)
  59. yegg=yegg+ychange
  60.  
  61. lives -= 1
  62.  
  63. eggy(xegg, yegg)
  64.  
  65. clock.tick(60)
  66. for event in pygame.event.get():
  67. if event.type==pygame.QUIT:
  68. exiting=True
  69. pygame.quit()
  70. quit()
  71. if event.type==pygame.KEYDOWN:
  72. if event.key==pygame.K_LEFT:
  73. xchange=-5
  74. if event.key==pygame.K_RIGHT:
  75. xchange=5
  76. if event.type==pygame.KEYUP:
  77. if event.key==pygame.K_LEFT or event.key==pygame.K_RIGHT:
  78. xchange=0
  79.  
  80. x=x+xchange
  81.  
  82. screen.fill((255, 255, 255))
  83. basketey(x, y)
  84. eggy(xegg, yegg)
  85.  
  86. if x > 600 - 80 or x < 0:
  87. xchange = 0
  88.  
  89. if lives == 0:
  90. print("Game Over, Your score was: %s" % score)
  91. exiting = True
  92.  
  93. pygame.display.update()
  94.  
  95. ychange=0
  96. #random position of eggs
  97.  
  98. #MOVEMENT OF egg
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement