메뉴 건너뛰기

OBG

Programming

Python
2013.11.21 23:15

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

MoA
조회 수 452 추천 수 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 Views1748
    read more
  2. [첫게임 만들기] 8. Win or Lose

    Date2013.11.21 CategoryPython ByMoA Views422
    Read More
  3. [첫게임 만들기] 9. 사운드

    Date2013.11.21 CategoryPython ByMoA Views452
    Read More
  4. [한빛미디어] 머신러닝·딥러닝 도서 선택 가이드

    Date2023.06.11 CategoryDeeplearning ByOBG Views71
    Read More
  5. "Node.js를 떠나며" - express를 만든 TJ의 글

    Date2022.06.23 CategoryTool/etc ByOBG Views127
    Read More
  6. #pragma

    Date2013.07.28 CategoryAPI/MFC ByMoA Views294
    Read More
  7. 10 Useful/Fun/Weird Github Repos You Have to Play Around With

    Date2023.12.28 CategorySite ByOBG Views99
    Read More
  8. 2016년에 자바스크립트를 배우는 기분

    Date2016.12.27 CategoryTool/etc ByMoA Views464
    Read More
  9. 2048 Game in Python

    Date2022.09.22 CategoryPython ByOBG Views119
    Read More
  10. 2048게임 높은 점수 얻기 위한 알고리즘

    Date2014.03.29 CategoryAlgorithm ByMoA Views552
    Read More
  11. A Beginner's Guide to Prompt Engineering with GitHub Copilot

    Date2024.04.04 CategoryLLM ByOBG Views33
    Read More
  12. Address Bar Install for Progressive Web Apps on the Desktop

    Date2021.12.15 CategoryWeb ByOBG Views84
    Read More
  13. Anthropic, LLM의 내부를 이해하는데 있어 상당한 진전을 보임

    Date2024.06.03 CategoryLLM ByOBG Views20
    Read More
  14. AS3 Code Library

    Date2013.10.11 CategoryLibrary ByMoA Views5043
    Read More
  15. ASCII 3D 렌더러 만들기

    Date2024.06.03 CategoryGraphic ByOBG Views29
    Read More
  16. AWS VPC 피어링

    Date2022.11.03 CategoryTool/etc ByOBG Views108
    Read More
  17. AWS 망 분리하기

    Date2022.09.06 CategoryTool/etc ByOBG Views117
    Read More
  18. Base64 decoder (binary file로 저장)

    Date2012.11.15 CategorySite ByNaya Views441
    Read More
  19. Binary 데이터 저장 by Google

    Date2013.07.28 CategoryC/C++ ByMoA Views328
    Read More
  20. Boost c++ Libraries (설명, 정리)

    Date2012.08.02 CategorySTL/Boost ByNaya Views294
    Read More
  21. boost::shared_ptr 소개

    Date2012.08.02 CategorySTL/Boost ByNaya Views364
    Read More
Board Pagination Prev 1 ... 2 3 4 5 6 7 8 9 10 ... 15 Next
/ 15
위로