Advertisement
Guest User

main.py

a guest
Feb 11th, 2017
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys, pygame
  4. from pygame.locals import *
  5. import constants as const
  6. import mario
  7.  
  8. # Initialise Pygame
  9. pygame.init()
  10.  
  11. # Create display
  12. DISPLAYSURF = pygame.display.set_mode(const.SCREEN_DIMENSIONS)
  13. pygame.display.set_caption("Mario in Pygame")
  14.  
  15. class Game(object):
  16.     def __init__(self):
  17.         self.fps = 60
  18.         self.showfps = True
  19.         self.clock = pygame.time.Clock()
  20.  
  21.         # Set FPS
  22.         self.clock.tick(self.fps)
  23.  
  24.         # Load background
  25.         bg = pygame.image.load("../assets/images/level_12.png").convert()
  26.         self.main_loop()
  27.  
  28.     # Quit function
  29.     def closegame(self):
  30.         pygame.display.quit() # Quit display first to make it look like the game closes quicker
  31.         pygame.quit()
  32.         sys.exit()
  33.  
  34.     def main_loop(self):
  35.         while True:
  36.             for event in pygame.event.get():
  37.                 if event.type == pygame.QUIT:
  38.                     self.closegame()
  39.             self.Mario = mario.Mario()
  40.             DISPLAYSURF.fill(const.BLACK)
  41.  
  42.  
  43.             pygame.display.flip()
  44.             if self.showfps:
  45.                 pygame.display.set_caption("Mario in Pygame - %s FPS" % self.clock.get_fps())
  46.  
  47. game = Game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement