Advertisement
Guest User

Source Code Help!

a guest
Oct 27th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. import pygame
  2. import time
  3.  
  4. if 1 >= 1:
  5. print("Yes")
  6.  
  7. FPS = 30
  8.  
  9. block_size = 5
  10.  
  11. red = (255, 0, 0)
  12. green = (0, 255, 0)
  13. blue = (0, 0, 255)
  14. black = (0, 0, 0)
  15. white = (255, 255, 255)
  16.  
  17. window_width = 800
  18. window_height = 600
  19.  
  20. font_size = 25
  21. pygame.font.init()
  22. font = pygame.font.SysFont(None, font_size)
  23.  
  24. pygame.init()
  25.  
  26. clock = pygame.time.Clock()
  27. gameDisplay = pygame.display.set_mode((window_width, window_height))
  28. title = pygame.display.set_caption("Slithering Snake!")
  29.  
  30.  
  31. def message_to_screen(msg, colour):
  32. screen_text = font.render(msg, True, colour)
  33. gameDisplay.blit(screen_text, (window_width/2, window_height/2))
  34.  
  35. def gameLoop():
  36.  
  37. lead_x = 100
  38. lead_y = 100
  39.  
  40. change_x = 0
  41. change_y = 0
  42.  
  43. gameExit = False
  44. gameOver = False
  45.  
  46. while not gameExit:
  47. gameDisplay.fill(black)
  48. pygame.draw.rect(gameDisplay, red, (lead_x, lead_y, block_size, block_size))
  49. lead_x += change_x
  50. lead_y += change_y
  51.  
  52. while gameOver == True:
  53. gameDisplay.fill(black)
  54. message_to_screen("Game Over! Press R To Play Again Or Q To Quit!", white)
  55. pygame.display.update()
  56.  
  57. for event in pygame.event.get():
  58. if event.type == pygame.KEYDOWN:
  59. if event.key == pygame.K_Q:
  60. gameExit = True
  61. gameOver = False
  62.  
  63. elif event.key == pygame.K_R:
  64. gameLoop()
  65.  
  66. pygame.display.update()
  67. for event in pygame.event.get():
  68. print (event)
  69. if event.type == lead_x >= window_width or lead_y >= window_height or lead_y <= 0 or lead_x <= 0:
  70. gameOver = True
  71. elif event.type == pygame.QUIT:
  72. gameExit = True
  73. elif event.type == pygame.KEYDOWN:
  74. if event.key == pygame.K_RETURN or event.key == pygame.K_ESCAPE:
  75. gameExit = True
  76. if event.type == pygame.KEYDOWN:
  77. if event.key == pygame.K_LEFT:
  78. change_x = -block_size
  79. change_y = 0
  80. elif event.key == pygame.K_RIGHT:
  81. change_x = block_size
  82. change_y = 0
  83. elif event.key == pygame.K_DOWN:
  84. change_y = block_size
  85. change_x = 0
  86. elif event.key == pygame.K_UP:
  87. change_y = -block_size
  88. change_x = 0
  89.  
  90. clock.tick(FPS)
  91.  
  92. message_to_screen("Game Over!", white)
  93. pygame.display.update()
  94. time.sleep(2)
  95. pygame.quit()
  96. quit()
  97.  
  98.  
  99. gameLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement