import pygame import sys import os # Change current working directory to file location. Solves problem with relative path of images os.chdir(sys.path[0]) # initialize pygame s.t. is ready to use pygame.init() # GAME CONSTANTS WIDTH = 1000 HEIGHT = 600 # create display you're going to see when playing the game, determine windows size screen = pygame.display.set_mode((WIDTH,HEIGHT)) # label windows, typically game name pygame.display.set_caption("My Game") clock = pygame.time.Clock() # CREATE SPRITES, LOAD IMAGES, TEXT... # CREATE PLAYER () player_surface = pygame.Surface((80,150)) player_surface.fill('blue') player_rect = player_surface.get_rect(bottomleft = (20,500)) # load image for background, convert png/jpg to something pygame can deal better with (use .convert() or .convert_alpha() for non-rectangular images) background_surface = pygame.image.load(os.path.join('data','town_bg_2x_600.png')).convert() background_rect = background_surface.get_rect(topleft = (0,0)) # font and text my_font = pygame.font.Font(None,50) # set font type and size, use other fonts by adding respective file in folder and give reference here text = my_font.render('',False,'red') # 2nd argument is anti-aliasing, set False for pixel art # permanent game loop while True: # Deal with key events for event in pygame.event.get(): # Exit app if click quit button if event.type == pygame.QUIT: pygame.quit() sys.exit() # Naviation of player keys = pygame.key.get_pressed() if keys[pygame.K_SPACE]: pass # DISPLAY screen.blit(background_surface,background_rect) screen.blit(text,(400,50)) screen.blit(player_surface,player_rect) # COLLISION DETECTION # Update everything pygame.display.update() # Set maximum frame rate, typically to 60(fps) -> have at most 60fps clock.tick(60)