Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- def main():
- # initialize pygame (some modules need initialization)
- pygame.init()
- # create a display window
- pygame.display.set_mode((500, 400))
- # add a window title
- pygame.display.set_caption("Test pygame graphics")
- # get the window surface
- w_surface = pygame.display.get_surface()
- # Game objects and their setting
- # objects common to all games
- bg_color = pygame.Color("black")
- frame_rate = 60
- game_clock = pygame.time.Clock()
- # game specific object
- # draw a red dot on the window surface
- small_dot = Dot()
- small_dot.init('red', 30, [30, 30], [1, 2])
- # draw a blue dot on the window surface
- big_dot = Dot('blue', 40, [200, 100], [2,1])
- # for the game end condition: play at most 150 frames
- frame_counter = 0
- max_frames = 150
- continue_game = True
- close_window = False
- while not close_window:
- # handle events
- events = pygame.event.get()
- for event in events:
- if event.type == pygame.QUIT:
- close_window = True
- # draw all objects in the current frame
- w_surface.fill(bg_color)
- pygame.draw.circle(w_surface, d_color, d_center, d_radius)
- small_dot.draw()
- big_dot.draw()
- # make things visible on the display window
- pygame.display.update()
- # update object for the next frame if the game is not over
- if continue_game:
- # d_center[0] = d_center[0] + d_velocity[0]
- # d_center[1] = d_center[1] + d_velocity[1]
- for index in range(len(d_center)):
- d_center[index] = d_center[index] + d_velocity[index]
- frame_counter = frame_counter + 1
- # check i =f the game is over or not
- if frame_counter == max_frames:
- continue_game = False
- game_clock.tick(frame_rate)
- # quit pygame and clean up the display window
- pygame.quit()
- # user defined classes
- class Dot:
- def init(self, color, radius, center, velocity):
- self.color = pygame.Color(color)
- self.center = center
- self.velocity = velocity
- self.radius = radius
- def move(self):
- # for index in range(len(d_center)):
- # d_center[index] = d_center[index] + d_velocity[index]
- pass
- def draw(self):
- pass
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement