ClearCode

main (start)

Mar 11th, 2022
6,954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. import pygame, sys, time
  2. from settings import *
  3.  
  4. class Game:
  5.     def __init__(self):
  6.        
  7.         # setup
  8.         pygame.init()
  9.         self.display_surface = pygame.display.set_mode((WINDOW_WIDTH,WINDOW_HEIGHT))
  10.         pygame.display.set_caption('Flappy Bird')
  11.         self.clock = pygame.time.Clock()
  12.  
  13.     def run(self):
  14.         last_time = time.time()
  15.         while True:
  16.            
  17.             # delta time
  18.             dt = time.time() - last_time
  19.             last_time = time.time()
  20.  
  21.             # event loop
  22.             for event in pygame.event.get():
  23.                 if event.type == pygame.QUIT:
  24.                     pygame.quit()
  25.                     sys.exit()
  26.            
  27.             # game logic
  28.            
  29.             pygame.display.update()
  30.             self.clock.tick(FRAMERATE)
  31.  
  32. if __name__ == '__main__':
  33.     game = Game()
  34.     game.run()
Advertisement
Add Comment
Please, Sign In to add comment