본문 바로가기

pygame

(18)
파이썬 게임 016. pygame.Surface의 set_alpha()로 투명도 설정 pygame.Surface 객체의 set_alpha() 함수로 surface의 투명도 설정이 가능하다. 아래의 이미지는 투명도(alpha)가 서로 다른 6개의 surface를 화면에 표시한 결과이다. # python 3.9.6 # pygame 2.0.1 import pygame def main(): pygame.init() screen = pygame.display.set_mode((640, 480), flags=pygame.NOFRAME) clock = pygame.time.Clock() screen.fill('white') surf1 = pygame.Surface((100, 100)) surf1.fill('blue') screen.blit(surf1, (50, 50)) surf1.set_alpha(5..
파이썬 게임 015. pygame의 게임 화면 크기 (display size) 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, 76..
파이썬 게임 014. pygame에서 지원하는 색상 이름 (color name) pygame에서 지원하는 색상 이름은 657개 이다. 아래 이미지는 pygame에서 지원하는 색상 이름을 이용해 색상을 출력한 결과이다. # python 3.9.6 # pygame 2.0.1 import pygame import pygame.colordict def main(): pygame.init() screen = pygame.display.set_mode((700, 600), flags=pygame.NOFRAME) screen_h = screen.get_height() clock = pygame.time.Clock() screen.fill((0, 0, 0)) colors_list = list(pygame.colordict.THECOLORS.keys()) print('THECOLORS :', len..
파이썬 게임 013. Pygame Documentation Summary 아래 내용은 Pygame 2.x Documentation을 기준으로 한다. pygame Top level pygame package pygame.get_init() -> bool pygame.get_sdl_version() -> (major, minor, patch) pygame.init() -> (numpass, numfail) pygame.quit() -> None pygame.Color pygame object for color representations Color(r, g, b) -> Color Color(r, g, b, a=255) -> Color Color(color_value) -> Color color_value: pygame.Color str or tuple or list (r, g, ..
파이썬 게임 012. pygame.image.load 함수로 이미지 불러와 게임 화면에 그리고 pygame.image.save 함수로 게임 화면 저장하기 pygame.image.load() 함수로 이미지를 불러와 pygame.Surface.blit() 함수로 게임 화면에 그려본다. 본 글에서 사용하는 기능 및 참고되는 기능에 대한 정의는 다음과 같다. pygame.image.load(fileobj, namehint="") -> Surface pygame.Surface.blit(source, dest, area=None, special_flags=0) -> Rect pygame.Rect.move(x, y) -> Rect pygame.image.save(Surface, fileobj, namehint="") -> None pygame.image.get_extended() -> bool pygame.image.get_extended() 함수의 반환값이 True..
파이썬 게임 011. pygame.draw 모듈로 그외 도형 그리기 (타원, 다각형, 타원호) pygame.draw.ellipse() 함수, pygame.draw.polygon() 함수, pygame.draw.arc() 함수를 이용해 타원, 다각형 및 타원호를 그려본다. 본 글에서 사용하는 기능 및 참고되는 기능에 대한 정의는 다음과 같다. pygame.draw.ellipse(surface, color, rect, width=0) -> Rect pygame.draw.polygon(surface, color, points, width=0) -> Rect pygame.draw.arc(surface, color, rect, start_angle, stop_angle, width=1) -> Rect 그외 도형 그리기 (ellipse, polygon, arc) # python 3.9.6 # pygame 2..
파이썬 게임 010. pygame.draw.circle 함수로 원 그리기 pygame.draw.circle() 함수로 원을 그려본다. 본 글에서 사용하는 기능 및 참고되는 기능에 대한 정의는 다음과 같다. pygame.draw.circle(surface, color, center, radius, width=0, draw_top_right=None, draw_top_left=None, draw_bottom_left=None, draw_bottom_right=None) -> Rect pygame.draw.circle() 함수로 원 그리기 # python 3.9.6 # pygame 2.0.1 import pygame BLACK = (0, 0, 0) WHITE = (255, 255, 255) RED = (255, 0, 0) GREEN = (0, 255, 0) BLUE = (0, 0,..
파이썬 게임 009. pygame.draw.rect 함수로 사각형 그리기 pygame.draw.rect() 함수로 사각형을 그려본다. 본 글에서 사용하는 기능 및 참고되는 기능에 대한 정의는 다음과 같다. pygame.draw.rect(surface, color, rect, width=0, border_radius=0, border_top_left_radius=-1, border_top_right_radius=-1, border_bottom_left_radius=-1, border_bottom_right_radius=-1) -> Rect pygame.event.custom_type() -> int pygame.time.set_timer(eventid, milliseconds) -> None pygame.time.set_timer(eventid, milliseconds, onc..