-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_main_sprite.py
More file actions
38 lines (28 loc) · 1.55 KB
/
3_main_sprite.py
File metadata and controls
38 lines (28 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pygame
pygame.init() # 초기화 (반드시 필요)
# 화면 크기 설정
screen_width = 480 # 가로 크기
screen_height = 640 # 세로 크기
screen = pygame.display.set_mode((screen_width, screen_height))
# 화면 타이틀 설정
pygame.display.set_caption("Nado Game") # 게임 이름
# 배경 이미지 불러오기
background = pygame.image.load(r"C:\Users\Siki\Desktop\python\pygame_basic\background.png")
# 캐릭터(스프라이트) 불러오기
character = pygame.image.load(r"C:\Users\Siki\Desktop\python\pygame_basic\character.png")
character_size = character.get_rect().size # 이미지의 크기를 구해옴
character_width = character_size[0] # 캐릭터의 가로 크기
character_height = character_size[1] # 캐릭터의 세로 크기
character_x_pos = (screen_width / 2) - (character_width / 2) # 화면 가로의 절반 크기에 해당하는 곳에 위치 (가로)
character_y_pos = screen_height - character_height # 화면 세로 크기 가장 아래에 해당하는 곳에 위치 (세로)
# 이벤트 루프
running = True # 게임이 진행중인가?
while running: # 게임 계속 돌고 있음.
for event in pygame.event.get(): # 어떤 이벤트가 발생하였는가?
if event.type == pygame.QUIT: # 창이 닫히는 이벤트가 발생하였는가?
running = False # 게임이 진행중이 아님
screen.blit(background, (0, 0)) # 배경 그리기
screen.blit(character, (character_x_pos, character_y_pos))
pygame.display.update() # 게임화면을 다시 그리기!
# pygame 종료
pygame.quit()