Guest User

Untitled

a guest
Aug 16th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. import pygame
  2. import time
  3. import random
  4.  
  5. pygame.init()
  6. width = 800
  7. height = 600
  8. white = (255,255,255)
  9. black = (0,0,0)
  10. gameDisplay = pygame.display.set_mode((width, height))
  11. pygame.display.set_caption('Moving image')
  12. clock = pygame.time.Clock()
  13.  
  14. image = pygame.image.load('67.png').convert()
  15.  
  16. def moving_image(x, y):
  17. gameDisplay.blit(image,(x, y))
  18.  
  19. def text_objects(text, font):
  20. textSurface = font.render(text, True, black)
  21. return textSurface, textSurface.get_rect()
  22.  
  23. def message_display(text):
  24. largeText = pygame.font.Font('freesansbold.ttf', 115)
  25. TextSurf, TextRect = text_objects(text, largeText)
  26. TextRect.center = ((width/2),(height/2))
  27. gameDisplay.blit(TextSurf, TextRect)
  28.  
  29. pygame.display.update()
  30.  
  31. time.sleep(2)
  32.  
  33. def things(thingx, thingy, thingw, thingh, color):
  34. pygame.draw.rect(gameDisplay, color, [thingx,thingy,thingw,thingh])
  35.  
  36. def crash():
  37. message_display('Hello')
  38. pygame.quit()
  39. quit()
  40.  
  41. def game_loop():
  42. x = (width * 0.35)
  43. y = (height * 0.8)
  44. x_change = 0
  45. image_width = 67
  46. x2 = x + image_width #### this line of code
  47.  
  48. thing_startx = random.randrange(0, width)
  49. thing_starty = -600
  50. thing_speed = 7
  51. thing_width = 100
  52. thing_height = 100
  53.  
  54. game_exit = False
  55. while not game_exit:
  56. for event in pygame.event.get():
  57. if event.type == pygame.QUIT:
  58. pygame.quit()
  59. quit()
  60. if event.type == pygame.KEYDOWN:
  61. if event.key == pygame.K_LEFT:
  62. x_change = -5
  63. if event.type == pygame.KEYDOWN:
  64. if event.key == pygame.K_RIGHT:
  65. x_change = 5
  66.  
  67. if event.type == pygame.KEYUP:
  68. if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
  69. x_change = 0
  70.  
  71. gameDisplay.fill(white)
  72. moving_image(x, y)
  73. x += x_change
  74.  
  75. things(thing_startx, thing_starty, thing_width, thing_height, black)
  76. thing_starty += thing_speed
  77.  
  78. if thing_starty > height:
  79. thing_starty = 0 - thing_height
  80. thing_startx = random.randrange(0, width)
  81.  
  82. x2 = x + image_width #### this line of code
  83.  
  84. if x2 > width or x < 0:
  85. crash()
  86.  
  87. pygame.display.update()
  88. clock.tick(59)
  89. game_loop()
  90. pygame.quit()
  91. quit()
Add Comment
Please, Sign In to add comment