tjseodl1259
@tjseodl1259
Reviews Written
2
Average Rating
5.0
Posts
Q&A
to_x, to_y ์๋์ฐ์์๋ ์ค๋ฅ๋์ค๋๋ฐ ๋์ฒด ์ฝ๋๊ฐ ์๋์?
์์ ๊ฐ์ฌํฉ๋๋ค ์์์ง์ด๋ค์ !! ๊ฐ์ํญ์ ์๋ณด๊ณ ์์ด์ ๊ธฐ๋ณธํธ๋ถํฐ ์ญ๋ ต์ค์ ๋๋ค!
- Likes
- 0
- Comments
- 8
- Viewcount
- 499
Q&A
to_x, to_y ์๋์ฐ์์๋ ์ค๋ฅ๋์ค๋๋ฐ ๋์ฒด ์ฝ๋๊ฐ ์๋์?
import pygame pygame.init() # ์ด๊ธฐํ (๋ฐ๋์ ํ์) # ํ๋ฉด ํฌ๊ธฐ ์ค์ screen_width = 480 # ๊ฐ๋ก ํฌ๊ธฐ screen_height = 640 # ์ธ๋ก ํฌ๊ธฐ screen = pygame.display.set_mode((screen_width, screen_height)) # ํ๋ฉด ํ์ดํ ์ค์ pygame.display.set_caption("JD Game") # ๊ฒ์ ์ด๋ฆ # ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ๋ถ๋ฌ์ค๊ธฐ background = pygame.image.load("C:\\Users\\JunDragon\\Desktop\\PythonWorkspace\\pygame_basic\\background.png") # ์บ๋ฆญํฐ (์คํ๋ผ์ดํธ) ๋ถ๋ฌ์ค๊ธฐ character = pygame.image.load("C:\\Users\\JunDragon\\Desktop\\PythonWorkspace\\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 # ๊ฒ์์ด ์งํ์ค์ด ์๋ if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: to_x -= 5 elif event.key == pygame.K_RIGHT: to_x += 5 elif event.key == pygame.K_UP: to_y -= 5 elif event.key == pygame.K_DOWN: to_y += 5 if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: to_x = 0 if event.key == pygame.K_UP or event.key == pygame.K_DOWN: to_y = 0 character_x_pos += to_x character_y_pos += to_y if character_x_pos 0: character_x_pos = 0 elif character_x_pos > screen_width - character_width: character_x_pos = screen_width - character_width if character_y_pos 0: character_y_pos = 1 elif character_y_pos > screen_height - character_y_pos: character_y_pos = screen_height - character_y_pos # screen.fill((0, 0, 255)) screen.blit(background, (0, 0)) # ๋ฐฐ๊ฒฝ ๊ทธ๋ฆฌ๊ธฐ screen.blit(character, (character_x_pos, character_y_pos)) pygame.display.update() # ๊ฒ์ ํ๋ฉด์ ๋ค์ ๊ทธ๋ฆฌ๊ธฐ! # pygame ์ข ๋ฃ pygame.quit()
- Likes
- 0
- Comments
- 8
- Viewcount
- 499
Q&A
to_x, to_y ์๋์ฐ์์๋ ์ค๋ฅ๋์ค๋๋ฐ ๋์ฒด ์ฝ๋๊ฐ ์๋์?
์ด๋ ๊ฒ ๋จ๋ค์ ใ
- Likes
- 0
- Comments
- 8
- Viewcount
- 499
Q&A
to_x, to_y ์๋์ฐ์์๋ ์ค๋ฅ๋์ค๋๋ฐ ๋์ฒด ์ฝ๋๊ฐ ์๋์?
keyboard_event.py", line 48, in character_x_pos += to_x NameError: name 'to_x' is not defined
- Likes
- 0
- Comments
- 8
- Viewcount
- 499




