1. pygame 선언 - import
2. pygame 초기화 - pygame.init()
3. 전역 변수 - size, screen(pygame.display.set_mode(size)), clock(pygame.time.Clock())
4. pygame 메인 루프 (while)
{
<pygame Event>
<pygame 그리기>
<추가 작업>
}
아래는 pygame의 구조를 파악하는데 도움이 된 예제이다
# Import a library of functions called 'pygame'
import pygame
# Initialize the game engine
pygame.init()
# Define the colors we will use in RGB format
BLACK= ( 0, 0, 0)
WHITE= (255,255,255)
BLUE = ( 0, 0,255)
GREEN= ( 0,255, 0)
RED = (255, 0, 0)
# Set the height and width of the screen
size = [400,300]
screen= pygame.display.set_mode(size)
pygame.display.set_caption("Game Title")
#Loop until the user clicks the close button.
done= False
clock= pygame.time.Clock()
while not done:
# This limits the while loop to a max of 10 times per second.
# Leave this out and we will use all CPU we can.
clock.tick(10)
# Main Event Loop
for eventin pygame.event.get():# User did something
if event.type == pygame.QUIT:# If user clicked close
done=True # Flag that we are done so we exit this loop
# All drawing code happens after the for loop and but
# inside the main while done==False loop.
# Clear the screen and set the screen background
screen.fill(WHITE)
# Go ahead and update the screen with what we've drawn.
# This MUST happen after all the other drawing commands.
pygame.display.flip()
# Be IDLE friendly
pygame.quit()
'Python' 카테고리의 다른 글
[파이썬] pymongo - count() (0) | 2022.04.27 |
---|---|
[파이썬] pygame - pygame.key (2) | 2022.04.26 |
[파이썬] if문 삼항연산자 (2) | 2022.04.22 |
[파이썬] pymongo.errors.OperationFailure: Authentication failed 에러 (0) | 2022.04.21 |
[파이썬] pymongo - ObjectId 로 인덱스 사용하기 (0) | 2022.04.21 |