로그인

검색

Python
2013.11.21 23:15

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

MoA
조회 수 4716 추천 수 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 Views22023
    read more
  2. 다이얼로그 기반에서 메뉴 내용이 갱신 안되는 문제 해결

    Date2014.02.13 CategoryAPI/MFC ByMoA Views5067
    Read More
  3. 파이썬에서 C모듈 사용하기

    Date2014.02.10 CategoryPython ByMoA Views5383
    Read More
  4. CSpreadSheet

    Date2014.02.03 CategoryLibrary ByMoA Views3925
    Read More
  5. 워게임 사이트 정리

    Date2014.01.27 CategoryReversing ByMoA Views4585
    Read More
  6. RAND_MAX

    Date2014.01.19 CategoryC/C++ ByMoA Views4009
    Read More
  7. OpenCV 이용한 템플릿 매칭

    Date2014.01.16 CategoryPython ByMoA Views4945
    Read More
  8. Quake 3 source code and review

    Date2014.01.15 CategoryTool/etc ByMoA Views4455
    Read More
  9. 화면 캡쳐 소스

    Date2014.01.14 CategoryPython ByMoA Views4726
    Read More
  10. __FILE__ __LINE__ __FUNCTION__ 등 매크로

    Date2014.01.02 CategoryC/C++ ByMoA Views4785
    Read More
  11. 유용한 라이브러리 소개

    Date2013.12.27 CategoryTool/etc ByMoA Views4533
    Read More
  12. Embedding Python in C/C++

    Date2013.12.23 CategoryPython ByMoA Views3988
    Read More
  13. SciPy and NumPy

    Date2013.12.23 CategoryPython ByMoA Views4038
    Read More
  14. 다국어를 위한 StringTable, LoadString

    Date2013.12.22 CategoryAPI/MFC ByMoA Views6491
    Read More
  15. WTL 정리

    Date2013.12.22 CategoryAPI/MFC ByMoA Views5400
    Read More
  16. GetLastInputInfo 함수

    Date2013.12.06 CategoryAPI/MFC ByMoA Views4747
    Read More
  17. [GUI] wxPython에서 에러메시지 콘솔로 보는 법

    Date2013.12.03 CategoryPython ByMoA Views4874
    Read More
  18. [GUI] wxPython 기본 프로그램

    Date2013.11.30 CategoryPython ByMoA Views4450
    Read More
  19. [GUI] Tkinter, wxPython

    Date2013.11.27 CategoryPython ByMoA Views4463
    Read More
  20. [첫게임 만들기] 9. 사운드

    Date2013.11.21 CategoryPython ByMoA Views4716
    Read More
  21. [첫게임 만들기] 8. Win or Lose

    Date2013.11.21 CategoryPython ByMoA Views4243
    Read More
Board Pagination Prev 1 ... 3 4 5 6 7 8 9 10 11 12 ... 17 Next
/ 17