Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. # Pygame development 1
  2. # Start the basic game set up
  3. # Set up the display
  4.  
  5. #Gain access to the pygame library
  6. import pygame
  7.  
  8. #Size of the screen
  9. SCREEN_TITLE = 'Cross the Skreet'
  10. SCREEN_WIDTH = 800
  11. SCREEN_HEIGHT = 800
  12. #Colors according to RGB codes
  13. WHITE_COLOR = (255, 255, 255)
  14. BLACK_COLOR = (0, 0, 0)
  15. #Clock used to update game events and frames
  16. clock = pygame.time.Clock()
  17. pygame.font.init()
  18. font = pygame.font.SysFont('comicsans', 75)
  19.  
  20. class Game:
  21.  
  22. #Typical rate of 60, equivalent to FPS
  23. TICK_RATE = 60
  24.  
  25. #Initializer for the game class to set up width, height, and title
  26. def __init__(self, title, width, height):
  27. self.title = title
  28. self.width = width
  29. self.height = height
  30.  
  31. #Creates the window of specified size in white to display the game
  32. self.game_window = pygame.display.set_mode((width, height))
  33. #Set the game window color to white
  34. self.game_window.fill(WHITE_COLOR)
  35. pygame.display.set_caption(title)
  36.  
  37. def run_game_loop(self):
  38. is_game_over = False
  39.  
  40. #Main game loop, used to update all gameplay such as movement, checks, and graphics
  41. #Runs until is_game_over = True
  42. while not is_game_over:
  43.  
  44. #A loop to get all of the events occuring at any given time
  45. #Events are most often mouse movement, mouse and button clicks, or exit events
  46. for event in pygame.event.get():
  47. #If we have a quit type event(Exit out) then exit out of the game loop
  48. if event.type == pygame.QUIT:
  49. is_game_over = True
  50.  
  51. print(event)
  52.  
  53. #Update all game graphics
  54. pygame.display.update()
  55. #Tick the clock to update everything
  56. clock.tick(self.TICK_RATE)
  57.  
  58.  
  59. pygame.init()
  60.  
  61. new_game = Game(TITLE, SCREEN_WIDTH, SCREEN_HEIGHT)
  62. new_game.run_game_loop()
  63.  
  64. #Quit pygame and the program
  65. pygame.quit()
  66. quit()
  67.  
  68.  
  69. # Load the player image from file directory
  70. #player_image = pygame.image.load('player.png')
  71. #scale the image up
  72. #player_image = pygame.transform.scale(player_image, (50,50))
  73. #Draw the player image on top of the screen at (x,y) position
  74. #game_window.blit(player_image, (375, 375))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement