디버그로 할때는 잘 실행되는데
import pygame
pygame.init() # 초기화
screen_width = 480 # 가로
screen_height = 640 # 세로
screen = pygame.display.set_mode((screen_width, screen_height))
# 타이틀
pygame.display.set_caption("dudcks game") # 게임 이름
# 배경
background = pygame.image.load("C:/Users/dudcks/Desktop/workspace/Python/pygame_basic/background.png")
# 캐릭터
character = pygame.image.load("C:/Users/dudcks/Desktop/workspace/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
# 이동 좌표
to_x = 0
to_y = 0
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 -= 1
elif event.key == pygame.K_RIGHT:
to_x += 1
elif event.key == pygame.K_UP:
to_y -= 1
elif event.key == pygame.K_DOWN:
to_y += 1
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 = 0
elif character_y_pos > screen_height - character_height:
character_y_pos = screen_height - character_height
screen.blit(background, (0, 0))
screen.blit(character, (character_x_pos, character_y_pos))
pygame.display.update()
pygame.quit() # 게임 종료
비주얼 스튜디오 코드 오른쪽에 있는 실행버튼 눌렀을때는 에러가 떠요
File "<stdin>", line 1
& C:/Python3/Python38-32/python.exe c:/Users/dudcks/Desktop/workspace/Python/pygame_basic/4_keyboard_event.py
^
SyntaxError: invalid syntax
이렇게 떠요
이제부터 디버그로만 프로젝트를 실행해야 하나요?ㅠㅠ
답변 1
1
ㅎㅎ 실수로 한 줄 실행 모드가 되었네요. Shift + Enter 를 누르면 그렇게 된답니다. 터미널 우측 끝에 쓰레기통 모양 아이콘을 계속 클릭하셔서 터미널 창을 모두 닫은 후 다시 실행해보세요 !
pygame 설치오류
0
123
1
pip install pygame 이 실패합니다
0
205
1
pip install pygame 이 안되요
0
886
1
(4:00) linting enabled 항목이 보이지 않습니다
0
155
1
마지막 프로젝트 그림 파일들을 올려주실 수는 없을까요?
0
202
1
import pygame에서 계속 오류가 발생해요
0
3580
2
무기 Y포지션 speed 감소
0
294
1
pygame 공부
0
504
0
마지막 부분 스프라이트가 맨 왼쪽에 위치해있습니다
0
264
1
공 쪼개기 문제
0
305
0
실행시 글자가 깨집니다.
0
309
1
키보드 이벤트 오류
0
569
1
스크린의 높이를 680으로 설정했을 때 오류?
0
294
1
pygame.time.get_ticks() 질문있습니다.
0
534
0
캐릭터의 이동
0
328
0
적(똥)과 케릭터가 충돌했을 때 게임 오버가 뜨게 만들려고..
0
298
1
시작을 하기에 앞서...
0
388
0
이미지 배경을 투명하게 하려면?
0
374
0
파이게임이 실행은 되는데....
0
227
0
실행이 안됩니다.
0
320
0
똑같이 따라 쳤는데 오류가 생겨요
0
302
0
배경색이 안 나와요
0
328
0
import pygame 실행이 안 돼요
0
2697
1
Error
0
151
0





