Advertisement
Guest User

poke

a guest
Oct 10th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. import pygame
  2.  
  3.  
  4. def main():
  5. # initialize pygame (some modules need initialization)
  6. pygame.init()
  7.  
  8. # create a display window
  9. pygame.display.set_mode((500, 400))
  10.  
  11. # add a window title
  12. pygame.display.set_caption("Test pygame graphics")
  13.  
  14. # get the window surface
  15. w_surface = pygame.display.get_surface()
  16.  
  17. # Game objects and their setting
  18. # objects common to all games
  19. bg_color = pygame.Color("black")
  20. frame_rate = 60
  21. game_clock = pygame.time.Clock()
  22.  
  23. # game specific object
  24. # draw a red dot on the window surface
  25. small_dot = Dot()
  26. small_dot.init('red', 30, [30, 30], [1, 2])
  27.  
  28. # draw a blue dot on the window surface
  29. big_dot = Dot('blue', 40, [200, 100], [2,1])
  30.  
  31. # for the game end condition: play at most 150 frames
  32. frame_counter = 0
  33. max_frames = 150
  34.  
  35. continue_game = True
  36. close_window = False
  37. while not close_window:
  38. # handle events
  39. events = pygame.event.get()
  40. for event in events:
  41. if event.type == pygame.QUIT:
  42. close_window = True
  43.  
  44. # draw all objects in the current frame
  45. w_surface.fill(bg_color)
  46. pygame.draw.circle(w_surface, d_color, d_center, d_radius)
  47. small_dot.draw()
  48. big_dot.draw()
  49. # make things visible on the display window
  50. pygame.display.update()
  51.  
  52. # update object for the next frame if the game is not over
  53. if continue_game:
  54. # d_center[0] = d_center[0] + d_velocity[0]
  55. # d_center[1] = d_center[1] + d_velocity[1]
  56. for index in range(len(d_center)):
  57. d_center[index] = d_center[index] + d_velocity[index]
  58. frame_counter = frame_counter + 1
  59.  
  60. # check i =f the game is over or not
  61. if frame_counter == max_frames:
  62. continue_game = False
  63.  
  64. game_clock.tick(frame_rate)
  65.  
  66. # quit pygame and clean up the display window
  67. pygame.quit()
  68.  
  69. # user defined classes
  70.  
  71.  
  72. class Dot:
  73.  
  74. def init(self, color, radius, center, velocity):
  75. self.color = pygame.Color(color)
  76. self.center = center
  77. self.velocity = velocity
  78. self.radius = radius
  79.  
  80. def move(self):
  81. # for index in range(len(d_center)):
  82. # d_center[index] = d_center[index] + d_velocity[index]
  83. pass
  84.  
  85. def draw(self):
  86. pass
  87.  
  88.  
  89. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement