Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Pygame development 1
- # Start the basic game set up
- # Set up the display
- #Gain access to the pygame library
- import pygame
- #Size of the screen
- SCREEN_TITLE = 'Cross the Skreet'
- SCREEN_WIDTH = 800
- SCREEN_HEIGHT = 800
- #Colors according to RGB codes
- WHITE_COLOR = (255, 255, 255)
- BLACK_COLOR = (0, 0, 0)
- #Clock used to update game events and frames
- clock = pygame.time.Clock()
- pygame.font.init()
- font = pygame.font.SysFont('comicsans', 75)
- class Game:
- #Typical rate of 60, equivalent to FPS
- TICK_RATE = 60
- #Initializer for the game class to set up width, height, and title
- def __init__(self, title, width, height):
- self.title = title
- self.width = width
- self.height = height
- #Creates the window of specified size in white to display the game
- self.game_window = pygame.display.set_mode((width, height))
- #Set the game window color to white
- self.game_window.fill(WHITE_COLOR)
- pygame.display.set_caption(title)
- def run_game_loop(self):
- is_game_over = False
- #Main game loop, used to update all gameplay such as movement, checks, and graphics
- #Runs until is_game_over = True
- while not is_game_over:
- #A loop to get all of the events occuring at any given time
- #Events are most often mouse movement, mouse and button clicks, or exit events
- for event in pygame.event.get():
- #If we have a quit type event(Exit out) then exit out of the game loop
- if event.type == pygame.QUIT:
- is_game_over = True
- print(event)
- #Update all game graphics
- pygame.display.update()
- #Tick the clock to update everything
- clock.tick(self.TICK_RATE)
- pygame.init()
- new_game = Game(TITLE, SCREEN_WIDTH, SCREEN_HEIGHT)
- new_game.run_game_loop()
- #Quit pygame and the program
- pygame.quit()
- quit()
- # Load the player image from file directory
- #player_image = pygame.image.load('player.png')
- #scale the image up
- #player_image = pygame.transform.scale(player_image, (50,50))
- #Draw the player image on top of the screen at (x,y) position
- #game_window.blit(player_image, (375, 375))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement