로그인

검색

Python
2013.11.21 23:15

[첫게임 만들기] 9. 사운드

MoA
조회 수 3539 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄 첨부

이제 거의 다 왔다. 8강까지 제작한 게임으로도 충분히 재밌게 즐길 수 있다. 하지만 그래도 뭔가 아쉽다라는 느낌이 든다. 사운드가 없다.

사운드를 출력하기 위해 mixer를 초기화하고 사운드를 불러온다. 3번 코드 다음에 추가한다.

 

# 3.1 - mixer 초기화
pygame.mixer.init()

# 3.2 - 사운드를 불러온다
hit = pygame.mixer.Sound("resources/audio/explode.wav")
enemy = pygame.mixer.Sound("resources/audio/enemy.wav")
shoot = pygame.mixer.Sound("resources/audio/shoot.wav")
hit.set_volume(0.05)
enemy.set_volume(0.05)
shoot.set_volume(0.05)

# 배경 음악
pygame.mixer.music.load('resources/audio/moonlight.wav')
pygame.mixer.music.play(-1, 0.0)
pygame.mixer.music.set_volume(0.25)

이제 필요한 곳에 사운드를 삽입하면 된다.

 

# section 6.4.2.1의 if badrect.left<64: 구문 안 마지막에
hit.play()
# section 6.4.2.2의 if badrect.colliderect(bullrect): 구문 안 마지막에
enemy.play()
# section 8의 if event.type==pygame.MOUSEBUTTONDOWN: 구문 안 마지막에
shoot.play()

이제 모든 작업이 끝났다. 다음에는 코드를 정리하고 배포하는 것까지 시도해보자.

?

  1. Programming 게시판 관련

    Date2014.11.01 CategoryTool/etc ByMoA Views15452
    read more
  2. [첫게임 만들기] 2. 배경 그리기, Bunny 움직이게 하기

    Date2013.11.21 CategoryPython ByMoA Views2786
    Read More
  3. FastAPI 톺아보기 - 부제: python 백엔드 봄은 온다

    Date2023.01.25 CategoryPython ByOBG Views2843
    Read More
  4. 2048 Game in Python

    Date2022.09.22 CategoryPython ByOBG Views2935
    Read More
  5. SciPy and NumPy

    Date2013.12.23 CategoryPython ByMoA Views3061
    Read More
  6. Embedding Python in C/C++

    Date2013.12.23 CategoryPython ByMoA Views3064
    Read More
  7. [GUI] Tkinter, wxPython

    Date2013.11.27 CategoryPython ByMoA Views3070
    Read More
  8. [액션게임 만들기] 8. 캐릭터 액션 구현 1

    Date2014.05.07 CategoryPython ByMoA Views3115
    Read More
  9. [첫게임 만들기] 5. 적을 생성하자

    Date2013.11.21 CategoryPython ByMoA Views3120
    Read More
  10. [액션게임 만들기] 9. 캐릭터 액션 구현 2

    Date2014.05.07 CategoryPython ByMoA Views3200
    Read More
  11. [첫게임 만들기] 8. Win or Lose

    Date2013.11.21 CategoryPython ByMoA Views3205
    Read More
  12. [농장게임 만들기] 5. 플레이어를 추가하자

    Date2014.04.30 CategoryPython ByMoA Views3259
    Read More
  13. [액션게임 만들기] 4. 캐릭터 선택 화면

    Date2014.05.07 CategoryPython ByOBG Views3289
    Read More
  14. Numpy의 axis 변경

    Date2023.06.09 CategoryPython ByOBG Views3295
    Read More
  15. [농장게임 만들기] 4. 펜스를 그리자

    Date2014.04.30 CategoryPython ByMoA Views3304
    Read More
  16. [액션게임 만들기] 6. 게임 화면 출력

    Date2014.05.07 CategoryPython ByMoA Views3308
    Read More
  17. [액션게임 만들기] 5. 장면 전환

    Date2014.05.07 CategoryPython ByMoA Views3321
    Read More
  18. [액션게임 만들기] 10. 캐릭터 기술 구현

    Date2014.05.07 CategoryPython ByMoA Views3361
    Read More
  19. [농장게임 만들기] 2. Nubcake Farms 클래스 분석

    Date2014.04.26 CategoryPython ByOBG Views3415
    Read More
  20. 고양이 밖으로 못나가게 하기

    Date2013.11.10 CategoryPython ByMoA Views3416
    Read More
  21. [농장게임 만들기] 8. HUD에 텍스트를 표시하자

    Date2014.05.01 CategoryPython ByMoA Views3422
    Read More
Board Pagination Prev 1 2 3 Next
/ 3