무료
다른 수강생들이 자주 물어보는 질문이 궁금하신가요?
- 미해결파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
캐릭터의 가로방향 움직임
캐릭터가 좌우로는 키를 눌렀을 때만 움직이는데 상하로는 키를 눌렀다가 때도 움직입니다. 코딩 어느 부분이 다른건지 모르겠네요. (파이참을 써서 하고 있기는 한데 그게 이유는 아니겠죠?) import pygame pygame.init() # screen screen_width = 480 screen_height = 640 screen = pygame.display.set_mode((screen_width, screen_height)) # title pygame.display.set_caption("MyGame") # import background image background = pygame.image.load("C:/Users/eagle/Desktop/PythonWorkspace/background.png") # import sprite(character) character = pygame.image.load("C:/Users/eagle/Desktop/PythonWorkspace/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 # moving position to_x = 0 to_y = 0 # event loop running = True # is the game running? 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 elif event.key == pygame.K_UP or event.key == pygame.K_DOWN: tp_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, (int(character_x_pos), int(character_y_pos))) pygame.display.update() # exit pygame.quit()
- 미해결파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
맥에서 실행중 이런 메시지가 떠요.
창을 띄우고 싶은데 창이 뜨지 않고 Unable to obtain graphics context for NSWindow (Mojave behavior) 파이게임 까는 데만 해도 엄청난 시행착오를 겪었는데 다시 시련이 닥쳤네요... 어떻게 해결할 수 있을까요?
- 해결됨파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
y축 위로 가는데 왜 to_y -= 5 인가요
윈도우 창 기준 좌측 상단이 (0, 0)인 건 이해했는데 왜 y축 위로 갈 땐 -5 이고 아래로 갈 땐 +5인가요. 위로 올라갈 때가 +5 아닌가요? -5로 하니까 정상적으로 작동돼서 더 이해가 안 됩니다. 함수할 때 x축 y축이 아니라 (0, 0)에서 아래로 갈수록 수가 커지는 y축인 건가요?
- 해결됨파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
디버그로 할때는 잘 실행되는데
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) - 추억의 오락실 게임 만들기 (3시간)
이미지는 어디서?
이미지를 어디서 다운받을 수 있는지 찾지 못했어요ㅠㅠ 강의에선 링크?를 본문에 남겨주신댔는데 어디에 있나요?
- 미해결파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
질문있습니다 선생님
캐릭터랑 똥이랑 충돌했을 시 어떤 다른 이미지를 띄우고 싶을 때는 어떻게 하면 좋을까요? 1. ending image 를 image.load로 지정 2. screen.blit 을 통해 화면에 그리기 3. colliderect 시 pygame.image.load (경로) 를 넣었는데 생각한대로 응용이 되지 않습니다.ㅠ
- 미해결파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
게임 화면이 너무 늦게 열려요.
작동은 되는데 너무 늦게 켜져서 시작하자마자 게임오버가 되는데 이건 어떤 문제일까요?
- 미해결파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
캐릭터가 하나만 나오는데 여러개가 나오도록 할려면 어떻게 해야될까요?
적 캐릭터가 하나만 나오는데 여러개가 나오도록 할려면 어떻게 해야될까요?
- 해결됨파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
enumerate 부분에서 이해가 힘든 코드가 있습니다
안녕하세요. 공튀기기 강의 부분 코드입니다. 코드에서 for ball_idx, ball_val in enumerate(balls): ball_pos_x = ball_val["pos_x"] ball_pos_y = ball_val["pos_y"] ball_img_idx = ball_val["img_idx"]라고 하면 balls.append({ "pos_x" : 50, # 공의 x좌표 "pos_y" : 50, # 공의 y좌표 "img_idx" : 0, # 공의 이미지 인덱스 "to_x" : 3, # x축 이동방향 -3이면 왼쪽, +3 이면 오른쪽 "to_y" : -6, # y축 이동방향 "init_spd_y" : ball_speed_y[0]# y 최초 속도 }) 를 했으니깐 저 대괄호 {} 안에 있는 자체( 첫번째 공에 대한 정보)가 ball[0]이 되는 것이 맞나요? 그렇다면 ball_val["pos_x"] 가 무슨 값이 되는지 궁금합니다. 50 이 되는건가요..?? print로 찍어보니 점점 늘어나는 수던데 .. 0,1,2 등의 인덱스 숫자값이 아닌 "pos_x" 가 들어가있어서 헷갈리네요 ㅠㅠ
- 미해결파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
질문
이러게 했는데 안되여....
- 미해결파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
계속 올라가요
공이 y<0을때 아래로 떨여져야 하는데 계속 올라가요
- 미해결파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
만든 프로그램을 친구에게 보내는 법
이 게임을 추출해서 친구에게 보내는 방법은 무엇인가요?
- 미해결파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
exe파일 불가
잘 만들었는데 exe로 pyinstaller --onefile --noconsole 이름 이런식으로 변형 시켰을 때 안켜지네요 ㅠㅠ
- 미해결파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
비쥬얼 스튜디오 에서 나도코딩님 처럼 똑같이 코드를 쳤는데 에러가 뜹니다. 어떻게 해야하나요?
(사진)
- 미해결파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
비쥬얼 스튜디오에서 pip install pygame 를 첬는데 안됩니다.어떻게 해야할까요.
(사진)
- 해결됨파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
기본기 - 텍스트 부분에서 시간이 화면에 나오지 않아요
안녕하세요. 잘따라가고 있다 생각했는데 화면에 시간이 출력되지 않아 당황스럽네요 ㅠㅠ 10초뒤에 화면 꺼지는건 되는데 (= 시간은 가는데) 그 시간 가는게 나도코딩님처럼 게임화면에 나타나지 않네요 아래는 제 코드입니다..! import pygame pygame.init() # 초기화 (반드시 필요) # 화면 크기 설정 screen_width = 480 # 가로 크기 screen_height = 640 # 세로 크기 screen = pygame.display.set_mode((screen_width,screen_height)) # 화면 타이틀 설정 pygame.display.set_caption("Ureal Game") # 게임 이름 # FPS clock = pygame.time.Clock() # 배경 이미지 불러오기 background = pygame.image.load("C:/realc/PythonWorkSpace/pygame_basic/background.png") # 캐릭터(스프라이트) 불러오기 character = pygame.image.load("C:/realc/PythonWorkSpace/pygame_basic/ch.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 # 이동 속도 character_speed = 1 # 적 enemy 캐릭터 enemy = pygame.image.load("C:/realc/PythonWorkSpace/pygame_basic/enemy.png") enemy_size = enemy.get_rect().size # 이미지의 크기를 구해옴 enemy_width = enemy_size[0] # 캐릭터의 가로 크기 enemy_height = enemy_size[1] # 캐릭터의 세로 크기 enemy_x_pos = screen_width / 2 - enemy_width / 2 # 화면 가로의 절반 크기에 해당하는 곳에 위치 enemy_y_pos = screen_height / 2 - enemy_height / 2 # 화면 세로 크기 가장 아래에 해당하는 곳에 위치 # 폰트 정의 game_font = pygame.font.Font(None, 40) # 폰트 객체 생성 (폰트, 크기) # 총 시간 total_time = 10 # 시작 시간 정보 start_ticks = pygame.time.get_ticks() # 현재 tick 을 받아옴 # 이벤트 루프 running = True # 게임이 진행중인가? while running: dt = clock.tick(60) # 게임화면의 초당 프레임 수를 설정 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 -= character_speed elif event.key == pygame.K_RIGHT: to_x += character_speed elif event.key == pygame.K_UP: to_y -= character_speed elif event.key == pygame.K_DOWN: to_y += character_speed if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: to_x = 0 elif event.key == pygame.K_UP or event.key == pygame.K_DOWN: to_y = 0 character_x_pos += to_x * dt character_y_pos += to_y * dt 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 # 충돌 처리를 위한 rect 정보 업데이트 charcter_rect = character.get_rect() charcter_rect.left = character_x_pos charcter_rect.top = character_y_pos enemy_rect = enemy.get_rect() enemy_rect.left = enemy_x_pos enemy_rect.top = enemy_y_pos # 충돌 체크 if charcter_rect.colliderect(enemy_rect): print("충돌했어요") running=False # 타이머 집어 넣기 # 경과 시간 계산 elapsed_time = (pygame.time.get_ticks() - start_ticks) / 1000 # 경과 시간(ms)을 1000으로 나누어서 초(s) 단위로 표시 timer = game_font.render(str(int(total_time - elapsed_time)), True, (255,255,255)) # 출력할 글자, True, 글자 색상 screen.blit(timer, (10,10)) # 만약 시간이 0 이하이면 게임 종료 if total_time - elapsed_time <= 0 : print("타임아웃") running = False screen.blit(background, (0,0)) # 배경 그리기 screen.blit(character, (character_x_pos,character_y_pos)) screen.blit(enemy, (enemy_x_pos,enemy_y_pos)) pygame.display.update() # 게임 화면을 다시 그리기! # 잠시 대기 pygame.time.delay(2000) # 2초 정도 대기 # pygame 종료 pygame.quit()
- 파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
방향을 반대로 빠르게 전환할경우 케릭터가 조금 움직이다가 멈춤니다
삭제된 글입니다
- 미해결파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
공 쪼개질때 문제
안녕하세요, 실행을 시켜서 플레이를 할때 가장 큰 공이 벽 부딪히기 전에 쏘면 쪼개지지 않고 공이 우르르 한꺼번에 나옵니다. 예를 들면 "ㅁ"이 큰공이라 하고 이걸 벽 부딪히기 전에 쏘면 ㅁ는 안없어지고 ㅁ 안에 2,3,4번째 큰 공들이 갑자기 함께 나타납니다. 근데 벽 한번 바운스 되고 쏘면 정상적으로 쪼개지는데 그 다음 큰 공을 벽 부딪히기 전에 쏘면 3,4번째로 큰 공이 한번에 나오네요... 밑에가 제 코드입니다. 도와주실수 있나요? 아 그리고 코드중 ball은 ball_pos_x라 되어있고 무기는 weapon_x_pos되어있는데 이건 제가 처음 만들었을때 실수해서 그런거에요... ㅠㅠ 쭉 통일시키니까 달라도 문제는 없더라고요
- 미해결파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
mac에서 실행창
실행이 되는데 깨져서 나옵니다.
- 파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간)
실행창이 안보입니다
삭제된 글입니다