본문 바로가기

코딩/파이썬 pygame

파이썬 게임 015. pygame의 게임 화면 크기 (display size)

Game - Python - Pygame

 

pygame.display.list_modes()를 이용해 사용 가능한 게임 화면 크기를 확인할 수 있다.

 

아래의 화면 크기는 사용하는 컴퓨터 환경에 따라 다를 수 있다.

 

size = ( 320,  200)
size = ( 320,  240)
size = ( 400,  300)
size = ( 512,  384)
size = ( 640,  400)
size = ( 640,  480)
size = ( 800,  600)
size = (1024,  768)
size = (1152,  864)
size = (1280,  600)
size = (1280,  720)
size = (1280,  768)
size = (1280,  800)
size = (1280,  960)
size = (1280, 1024)
size = (1360,  768)
size = (1366,  768)
size = (1400, 1050)
size = (1440,  900)
size = (1600,  900)
size = (1680, 1050)
size = (1920, 1080)

 

1920 x 1080을 기준으로 위의 각 화면 크기를 비교해 보면 아래와 같다.

 

 

<코드 1>

# python 3.9.6
# pygame 2.0.1

import pygame
import random

THECOLORS = {
    'aliceblue': (240, 248, 255, 255),
    'antiquewhite': (250, 235, 215, 255),
    'antiquewhite1': (255, 239, 219, 255),
    'antiquewhite2': (238, 223, 204, 255),
    'antiquewhite3': (205, 192, 176, 255),
    'antiquewhite4': (139, 131, 120, 255),
    'aquamarine': (127, 255, 212, 255),
    'aquamarine1': (127, 255, 212, 255),
    'aquamarine2': (118, 238, 198, 255),
    'aquamarine3': (102, 205, 170, 255),
    'aquamarine4': (69, 139, 116, 255),
    'azure': (240, 255, 255, 255),
    'azure1': (240, 255, 255, 255),
    'azure3': (193, 205, 205, 255),
    'azure2': (224, 238, 238, 255),
    'azure4': (131, 139, 139, 255),
    'beige': (245, 245, 220, 255),
    'bisque': (255, 228, 196, 255),
    'bisque1': (255, 228, 196, 255),
    'bisque2': (238, 213, 183, 255),
    'bisque3': (205, 183, 158, 255),
    'bisque4': (139, 125, 107, 255),
    'black': (0, 0, 0, 255),
    'blanchedalmond': (255, 235, 205, 255),
    'blue': (0, 0, 255, 255),
    'blue1': (0, 0, 255, 255),
    'blue2': (0, 0, 238, 255),
    'blue3': (0, 0, 205, 255),
    'blue4': (0, 0, 139, 255),
    'blueviolet': (138, 43, 226, 255),
    'brown': (165, 42, 42, 255),
    'brown1': (255, 64, 64, 255),
    'brown2': (238, 59, 59, 255),
    'brown3': (205, 51, 51, 255),
    'brown4': (139, 35, 35, 255),
    'burlywood': (222, 184, 135, 255),
    'burlywood1': (255, 211, 155, 255),
    'burlywood2': (238, 197, 145, 255),
    'burlywood3': (205, 170, 125, 255),
    'burlywood4': (139, 115, 85, 255),
    'cadetblue': (95, 158, 160, 255),
    'cadetblue1': (152, 245, 255, 255),
    'cadetblue2': (142, 229, 238, 255),
    'cadetblue3': (122, 197, 205, 255),
    'cadetblue4': (83, 134, 139, 255),
    'chartreuse': (127, 255, 0, 255),
    'chartreuse1': (127, 255, 0, 255),
    'chartreuse2': (118, 238, 0, 255),
    'chartreuse3': (102, 205, 0, 255),
    'chartreuse4': (69, 139, 0, 255),
    'chocolate': (210, 105, 30, 255),
    'chocolate1': (255, 127, 36, 255),
    'chocolate2': (238, 118, 33, 255),
    'chocolate3': (205, 102, 29, 255),
    'chocolate4': (139, 69, 19, 255),
    'coral': (255, 127, 80, 255),
    'coral1': (255, 114, 86, 255),
    'coral2': (238, 106, 80, 255),
    'coral3': (205, 91, 69, 255),
    'coral4': (139, 62, 47, 255),
    'cornflowerblue': (100, 149, 237, 255),
    'cornsilk': (255, 248, 220, 255),
    'cornsilk1': (255, 248, 220, 255),
    'cornsilk2': (238, 232, 205, 255),
    'cornsilk3': (205, 200, 177, 255),
    'cornsilk4': (139, 136, 120, 255),
    'cyan': (0, 255, 255, 255),
    'cyan1': (0, 255, 255, 255),
    'cyan2': (0, 238, 238, 255),
    'cyan3': (0, 205, 205, 255),
    'cyan4': (0, 139, 139, 255),
    'darkblue': (0, 0, 139, 255),
    'darkcyan': (0, 139, 139, 255),
    'darkgoldenrod': (184, 134, 11, 255),
    'darkgoldenrod1': (255, 185, 15, 255),
    'darkgoldenrod2': (238, 173, 14, 255),
    'darkgoldenrod3': (205, 149, 12, 255),
    'darkgoldenrod4': (139, 101, 8, 255),
    'darkgray': (169, 169, 169, 255),
    'darkgreen': (0, 100, 0, 255),
    'darkgrey': (169, 169, 169, 255),
    'darkkhaki': (189, 183, 107, 255),
    'darkmagenta': (139, 0, 139, 255),
    'darkolivegreen': (85, 107, 47, 255),
    'darkolivegreen1': (202, 255, 112, 255),
    'darkolivegreen2': (188, 238, 104, 255),
    'darkolivegreen3': (162, 205, 90, 255),
    'darkolivegreen4': (110, 139, 61, 255),
    'darkorange': (255, 140, 0, 255),
    'darkorange1': (255, 127, 0, 255),
    'darkorange2': (238, 118, 0, 255),
    'darkorange3': (205, 102, 0, 255),
    'darkorange4': (139, 69, 0, 255),
    'darkorchid': (153, 50, 204, 255),
    'darkorchid1': (191, 62, 255, 255),
    'darkorchid2': (178, 58, 238, 255),
    'darkorchid3': (154, 50, 205, 255),
    'darkorchid4': (104, 34, 139, 255),
    'darkred': (139, 0, 0, 255),
    'darksalmon': (233, 150, 122, 255),
    'darkseagreen': (143, 188, 143, 255),
    'darkseagreen1': (193, 255, 193, 255),
    'darkseagreen2': (180, 238, 180, 255),
    'darkseagreen3': (155, 205, 155, 255),
    'darkseagreen4': (105, 139, 105, 255),
    'darkslateblue': (72, 61, 139, 255),
    'darkslategray': (47, 79, 79, 255),
    'darkslategray1': (151, 255, 255, 255),
    'darkslategray2': (141, 238, 238, 255),
    'darkslategray3': (121, 205, 205, 255),
    'darkslategray4': (82, 139, 139, 255),
    'darkslategrey': (47, 79, 79, 255),
    'darkturquoise': (0, 206, 209, 255),
    'darkviolet': (148, 0, 211, 255),
    'deeppink': (255, 20, 147, 255),
    'deeppink1': (255, 20, 147, 255),
    'deeppink2': (238, 18, 137, 255),
    'deeppink3': (205, 16, 118, 255),
    'deeppink4': (139, 10, 80, 255),
    'deepskyblue': (0, 191, 255, 255),
    'deepskyblue1': (0, 191, 255, 255),
    'deepskyblue2': (0, 178, 238, 255),
    'deepskyblue3': (0, 154, 205, 255),
    'deepskyblue4': (0, 104, 139, 255),
    'dimgray': (105, 105, 105, 255),
    'dimgrey': (105, 105, 105, 255),
    'dodgerblue': (30, 144, 255, 255),
    'dodgerblue1': (30, 144, 255, 255),
    'dodgerblue2': (28, 134, 238, 255),
    'dodgerblue3': (24, 116, 205, 255),
    'dodgerblue4': (16, 78, 139, 255),
    'firebrick': (178, 34, 34, 255),
    'firebrick1': (255, 48, 48, 255),
    'firebrick2': (238, 44, 44, 255),
    'firebrick3': (205, 38, 38, 255),
    'firebrick4': (139, 26, 26, 255),
    'floralwhite': (255, 250, 240, 255),
    'forestgreen': (34, 139, 34, 255),
    'gainsboro': (220, 220, 220, 255),
    'ghostwhite': (248, 248, 255, 255),
    'gold': (255, 215, 0, 255),
    'gold1': (255, 215, 0, 255),
    'gold2': (238, 201, 0, 255),
    'gold3': (205, 173, 0, 255),
    'gold4': (139, 117, 0, 255),
    'goldenrod': (218, 165, 32, 255),
    'goldenrod1': (255, 193, 37, 255),
    'goldenrod2': (238, 180, 34, 255),
    'goldenrod3': (205, 155, 29, 255),
    'goldenrod4': (139, 105, 20, 255)
}


def main():
    pygame.init()

    screen = pygame.display.set_mode((1920, 1080))
    clock = pygame.time.Clock()

    size_list = []

    for i in pygame.display.list_modes():
        if i not in size_list:
            size_list.append(i)

    size_list.sort()
    color_table = list(THECOLORS.keys())

    for i in size_list:
        print('size = ({0:>4}, {1:>4}), depth = {2:>2}'.format(
            i[0], i[1], pygame.display.mode_ok(size=i)))
        x = i[0] - 1
        y = i[1] - 1
        draw_color = random.choice(color_table)
        pygame.draw.line(screen, 'gray70', (0, 0), (x, y), 1)
        pygame.draw.rect(screen, draw_color, (0, 0, x, y), 2)
        pygame.draw.circle(screen, draw_color, (x, y), 5)

    pygame.display.update()

    pygame.event.clear()

    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT\
                    or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
                running = False
                break
        if not running:
            break

        clock.tick(30)

    pygame.quit()


if __name__ == '__main__':
    main()