์ด ๋ฌธ์์ ์๋ณธ์ ์ธ๋ถ ์ํค์์ ๊ฐ์ ธ์์ต๋๋ค.
|๊ณต์ ์ฌ์ดํธ. ๊ณต์ ๋ฌธ์์ ์ปค๋ฎค๋ํฐ ๋ฑ์ ๊ธฐ๋ฅ์ ํ๋ค.
1. ๊ฐ์[ํธ์ง]
Python์ผ๋ก ์์ฑ ๊ฐ๋ฅํ ๊ฒ์ ๋ฑ์ ๋ฉํฐ๋ฏธ๋์ด ํํ์ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ด๋ค. SDL ๊ธฐ๋ฐ์ด๋ค. ์คํ ์์ค์ด์ ๋ฌด๋ฃ ๋๊ตฌ์ด๋ฉฐ, Python์ ๋๋ฆด ์ ์๋ ํ๋ซํผ์ด๋ผ๋ฉด ์ด๋์๋ ์คํํ ์ ์๋ค. ๊ฒ์ ๊ฐ๋ฐ ๋๊ตฌ์ด์ง๋ง ์ด๋ฏธ์ง ํ๋ก์ธ์ค ๋๋ ์กฐ์ด์คํฑ ์
๋ ฅ, ์์
์ฌ์ ๋ฑ์ ๊ธฐ๋ฅ๋ง ๋ผ์ด๋ค ์ธ ์๋ ์๋ค.
์์ง์ ๊ฒ์ํจ๋๋ฅผ ๋ฌผ๊ณ ์๋ ๋ ธ๋์ ๋ฑ์ด๋ค.
๋น์ฃผ์ผ ๋ ธ๋ฒจ ํด์ธ Ren'Py ๋ํ Pygame์ ๊ธฐ๋ฐํ๊ณ ์๋ค.
์์ง์ ๊ฒ์ํจ๋๋ฅผ ๋ฌผ๊ณ ์๋ ๋ ธ๋์ ๋ฑ์ด๋ค.
๋น์ฃผ์ผ ๋ ธ๋ฒจ ํด์ธ Ren'Py ๋ํ Pygame์ ๊ธฐ๋ฐํ๊ณ ์๋ค.
2. ์ฃผ์ ๋ชจ๋[ํธ์ง]
2.1. pygame[ํธ์ง]
pygame ๋ชจ๋๋ค์ ์ฌ์ฉํ๊ธฐ ์ํด์๋ pygame.init(), pygame.quit() ๋ฑ์ผ๋ก ์ด๊ธฐํ, ์ข
๋ฃ๋ฅผ ์์ผ์ค์ผ ํ๋ค.
2.2. sprite[ํธ์ง]
pygame.sprite.Sprite() ํด๋์ค๋ก ์คํ๋ผ์ดํธ ๊ฐ์ฒด๋ฅผ ์์ฑํ ์ ์๋ค. sprite์ ๋ชจ์์ธ pygame.sprite.Group() ํด๋์ค๋ก ์คํ๋ผ์ดํธ๋ค์ ํจ์จ์ ์ผ๋ก ๊ด๋ฆฌํ ์ ์๋ค.
3. ์์ [ํธ์ง]
3.1. Hello, world![ํธ์ง]
import pygame # pygame ๋ชจ๋์ ์ํฌํธ
import sys # ์ธ์ฅ ๋ชจ๋
from pygame.locals import * # QUIT ๋ฑ์ pygame ์์๋ค์ ๋ก๋ํ๋ค.
width = 600 # ์์ ์ค์
height = 400
white = (255, 255, 255)
black = ( 0, 0, 0)
fps = 30
pygame.init() # ์ด๊ธฐํ
pygame.display.set_caption('Hello, world!') # ์ฐฝ ์ ๋ชฉ ์ค์
displaysurf = pygame.display.set_mode((width, height), 0, 32) # ๋ฉ์ธ ๋์คํ๋ ์ด๋ฅผ ์ค์ ํ๋ค
clock = pygame.time.Clock() # ์๊ฐ ์ค์
gulimfont = pygame.font.SysFont('๊ตด๋ฆผ', 70) # ์์ฒด ์ค์
helloworld = gulimfont.render('Hello, world!', 1, black)
# .render() ํจ์์ ๋ด์ฉ๊ณผ ์ํฐ์จ๋ฆฌ์ด์ฑ, ์์ ์ ๋ฌํ์ฌ ๊ธ์ ์ด๋ฏธ์ง ์์ฑ
hellorect = helloworld.get_rect() # ์์ฑํ ์ด๋ฏธ์ง์ rect ๊ฐ์ฒด๋ฅผ ๊ฐ์ ธ์จ๋ค
hellorect.center = (width / 2, height / 2) # ํด๋น rect์ ์ค์์ ํ๋ฉด ์ค์์ ๋ง์ถ๋ค
while True: # ์๋์ ์ฝ๋๋ฅผ ๋ฌดํ ๋ฐ๋ณตํ๋ค.
for event in pygame.event.get(): # ๋ฐ์ํ ์
๋ ฅ event ๋ชฉ๋ก์ event๋ง๋ค ๊ฒ์ฌ
if event.type == QUIT: # event์ type์ด QUIT์ ํด๋นํ ๊ฒฝ์ฐ
pygame.quit() # pygame์ ์ข
๋ฃํ๋ค
sys.exit() # ์ฐฝ์ ๋ซ๋๋ค
displaysurf.fill(white) # displaysurf๋ฅผ ํ์์์ผ๋ก ์ฑ์ด๋ค
displaysurf.blit(helloworld, hellorect) # displaysurf์ hellorect์ ์์น์ helloworld๋ฅผ ๋ฟ๋ฆฐ๋ค
pygame.display.update() # ํ๋ฉด์ ์
๋ฐ์ดํธํ๋ค
clock.tick(fps) # ํ๋ฉด ํ์ ํ์ ์ค์ ๋งํผ ๋ฃจํ์ ๊ฐ๊ฒฉ์ ๋๋คpygame ์ด๊ธฐํ, ๊ธฐ๋ณธ ์ธํ ๊ณผ ๋์คํ๋ ์ด ์์ ํฐํธ๋ฅผ ๋ ๋๋งํ๋ ๊ธฐ์ด ์์ ์ด๋ค. ๊ฒฐ๊ณผ๋ ์๋์ ๊ฐ๋ค.
4. ์ฌ๋ด[ํธ์ง]
ํ๋, pygame ๋ฉ์ธ ํ๋ฉด์ ์์นด์ด๋ธ ๋งํฌ์ github ๋งํฌ๊ฐ ์๊ณ , ๊ฒ์ ํ๋ฉด์ I can't breathe๋ผ๊ณ ์ ํ์๋ ์ ์ด ์์๋ค.์์นด์ด๋ธ ๋งํฌ