Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python pygame how to start a game

import pygame,os
from win32api import GetSystemMetrics

os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (0,+30) # place the window in the screen( in this example 300 from the left side of the screen and 50 from the top of the screen)
pygame.init()

screen_x,screen_y = GetSystemMetrics(0),GetSystemMetrics(1) - 70
window = pygame.display.set_mode((screen_x,screen_y)) # 
pygame.display.set_caption("game name")

font = pygame.font.SysFont('Corbel', screen_x//48)
bigger_font = pygame.font.Font('fruitaloo//font.ttf', screen_x//35)
huge_font = pygame.font.Font('fruitaloo//font.ttf', screen_x//20)


def main():
    clock = pygame.time.Clock()
    game_on = True

    while game_on:
        clock.tick(60)
        window.fill((255,255,255))

        mouse = pygame.mouse.get_pos()
        pressed_left_mouse_button = pygame.mouse.get_pressed(3)[0]
        keys = pygame.key.get_pressed()
        for event in pygame.event.get():
            if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                pygame.quit()

        pygame.display.update()
if __name__ == '__main__':
    main()
 
PREVIOUS NEXT
Tagged: #python #pygame #start #game
ADD COMMENT
Topic
Name
8+1 =