Search
 
SCRIPT & CODE EXAMPLE
 

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()
Comment

PREVIOUS NEXT
Code Example
Python :: selenium if statement python 
Python :: maxsize in python 
Python :: discord py fetch channel by id 
Python :: python dataframe replace nan with 0 
Python :: python how to get the folder name of a file 
Python :: numpy 3 dimensional array 
Python :: python save dictionary 
Python :: first and last digit codechef solution 
Python :: python run exe 
Python :: excel write in row 
Python :: wintp python manage.py createsuperuser 
Python :: reverse an array pyton 
Python :: pandas dataframe filter 
Python :: how to read multiple csv file from different directory in python 
Python :: add a button pyqt5 
Python :: pandas get value not equal to 
Python :: how to iterate through a list in python 
Python :: turn a list into a string python 
Python :: count different values in list python 
Python :: how to have requirement file in python for libs 
Python :: dataframe string find count 
Python :: how to give bar plot groupby python different colors 
Python :: what is the difference between python 2 and 3 
Python :: django add middleware 
Python :: matplotlib styles attr 
Python :: how to map longitude and latitude in python 
Python :: how to get int input in python 
Python :: iterative dfs python 
Python :: euclidean distance python 3 variables 
Python :: if main python 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =